GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Give PMatrix a print() method · Issue #811 · processing/processing4

Give PMatrix a print() method #811

New issue
Copy link
New issue
Copy link
Closed
Closed
Give PMatrix a print() method#811
Copy link
Assignees
Sumamasonia
Labels
coreenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed

Description

@processing-bot
processing-bot
opened on Dec 16, 2023
Issue body actions

Created by: PianoMastR64

Since PMatrix2D and PMatrix3D both have a print() method with matching signatures, it would make sense for their common interface PMatrix to have this method. Right now I have to do this:

public void printMatrix(PMatrix matrix) {
    if(matrix instanceof PMatrix2D matrix2D) {
        matrix2D.print();
    } else if(matrix instanceof PMatrix3D matrix3D) {
        matrix3D.print();
    }
}

Activity

  1. processing-bot commented on Dec 16, 2023

    @processing-bot
    processing-bot
    on Dec 16, 2023
    CollaboratorAuthor
    More actions

    Created by: PianoMastR64

    And since I'm here, usually you would override the toString() method for this so the client can decide what to do with it, such as printing to the console. I'm sure you have your reasons for doing it this way though.

  2. processing-bot commented on Feb 3, 2024

    @processing-bot
    processing-bot
    on Feb 3, 2024
    CollaboratorAuthor
    More actions

    Created by: vaishnavi192

    Hey @benfry @PianoMastR64 do you mean something like this?
    public void printMatrix(PMatrix matrix) {
    System.out.println(matrix.toString());
    }
    can you describe a bit further....I want to work on it

  3. processing-bot commented on Feb 8, 2024

    @processing-bot
    processing-bot
    on Feb 8, 2024
    CollaboratorAuthor
    More actions

    Created by: PianoMastR64

    @vaishnavi192 I was thinking something maybe like this:

    public interface PMatrix {
        default void print(){
            System.out.println(this);
        }
    }
    
    public class PMatrix2D implements PMatrix {
        @Override
        public String toString() {
            int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
                PApplet.max(abs(m10), abs(m11), abs(m12))));
            
            int digits = 1;
            if(Float.isNaN(big) || Float.isInfinite(big)) {  // avoid infinite loop
                digits = 5;
            } else {
                while((big /= 10) != 0) digits++;  // cheap log()
            }
            
            StringBuilder sb = new StringBuilder();
            sb
                .append(PApplet.nfs(m00, digits, 4)).append(" ")
                .append(PApplet.nfs(m01, digits, 4)).append(" ")
                .append(PApplet.nfs(m02, digits, 4)).append("\n")
                
                .append(PApplet.nfs(m10, digits, 4)).append(" ")
                .append(PApplet.nfs(m11, digits, 4)).append(" ")
                .append(PApplet.nfs(m12, digits, 4)).append("\n");
            
            return sb.toString();
        }
    }
    
    public class PMatrix3D implements PMatrix {
        @Override
        public String toString() {
            int big = (int) Math.abs(max(max(max(max(Math.abs(m00), Math.abs(m01)),
                        max(Math.abs(m02), Math.abs(m03))),
                    max(max(Math.abs(m10), Math.abs(m11)),
                        max(Math.abs(m12), Math.abs(m13)))),
                max(max(max(Math.abs(m20), Math.abs(m21)),
                        max(Math.abs(m22), Math.abs(m23))),
                    max(max(Math.abs(m30), Math.abs(m31)),
                        max(Math.abs(m32), Math.abs(m33))))));
            
            int digits = 1;
            if(Float.isNaN(big) || Float.isInfinite(big)) {  // avoid infinite loop
                digits = 5;
            } else {
                while((big /= 10) != 0) digits++;  // cheap log()
            }
            
            StringBuilder sb = new StringBuilder();
            sb
                .append(PApplet.nfs(m00, digits, 4)).append(" ")
                .append(PApplet.nfs(m01, digits, 4)).append(" ")
                .append(PApplet.nfs(m02, digits, 4)).append(" ")
                .append(PApplet.nfs(m03, digits, 4)).append("\n")
                
                .append(PApplet.nfs(m10, digits, 4)).append(" ")
                .append(PApplet.nfs(m11, digits, 4)).append(" ")
                .append(PApplet.nfs(m12, digits, 4)).append(" ")
                .append(PApplet.nfs(m13, digits, 4)).append("\n")
                
                .append(PApplet.nfs(m20, digits, 4)).append(" ")
                .append(PApplet.nfs(m21, digits, 4)).append(" ")
                .append(PApplet.nfs(m22, digits, 4)).append(" ")
                .append(PApplet.nfs(m23, digits, 4)).append("\n")
                
                .append(PApplet.nfs(m30, digits, 4)).append(" ")
                .append(PApplet.nfs(m31, digits, 4)).append(" ")
                .append(PApplet.nfs(m32, digits, 4)).append(" ")
                .append(PApplet.nfs(m33, digits, 4)).append("\n");
            
            return sb.toString();
        }
    }
  4. processing-bot commented on Feb 8, 2024

    @processing-bot
    processing-bot
    on Feb 8, 2024
    CollaboratorAuthor
    More actions

    Created by: PianoMastR64

    And since I'm here, I have a suggestion that doesn't have to be taken seriously. I'm just having fun learning about streams and functional programming in Java recently.

    This:

    int big = (int) Math.abs(max(max(max(max(Math.abs(m00), Math.abs(m01)),
                max(Math.abs(m02), Math.abs(m03))),
            max(max(Math.abs(m10), Math.abs(m11)),
                max(Math.abs(m12), Math.abs(m13)))),
        max(max(max(Math.abs(m20), Math.abs(m21)),
                max(Math.abs(m22), Math.abs(m23))),
            max(max(Math.abs(m30), Math.abs(m31)),
                max(Math.abs(m32), Math.abs(m33))))));

    Could be turned into this:

    int big = (int) (float) Stream.of(
            m00, m01, m02, m03,
            m10, m11, m12, m13,
            m20, m21, m22, m23,
            m30, m31, m32, m33)
        .map(Math::abs)
        .max(Float::compare)
        .orElse(Float.NaN);

    It's a little more readable. Also, I didn't test it.

  5. processing-bot commented on Feb 8, 2024

    @processing-bot
    processing-bot
    on Feb 8, 2024
    CollaboratorAuthor
    More actions

    Created by: PianoMastR64

    Oh, also Float.isNaN() and Float.isInfinite() are being checked on int big which is not a float. Not sure why that is. I'm guessing big was a float in the past

  6. processing-bot commented on Feb 12, 2024

    @processing-bot
    processing-bot
    on Feb 12, 2024
    CollaboratorAuthor
    More actions

    Created by: rndmbluescreen

    And since I'm here, I have a suggestion that doesn't have to be taken seriously. I'm just having fun learning about streams and functional programming in Java recently.

    This:

    int big = (int) Math.abs(max(max(max(max(Math.abs(m00), Math.abs(m01)),
                max(Math.abs(m02), Math.abs(m03))),
            max(max(Math.abs(m10), Math.abs(m11)),
                max(Math.abs(m12), Math.abs(m13)))),
        max(max(max(Math.abs(m20), Math.abs(m21)),
                max(Math.abs(m22), Math.abs(m23))),
            max(max(Math.abs(m30), Math.abs(m31)),
                max(Math.abs(m32), Math.abs(m33))))));

    Could be turned into this:

    int big = (int) (float) Stream.of(
            m00, m01, m02, m03,
            m10, m11, m12, m13,
            m20, m21, m22, m23,
            m30, m31, m32, m33)
        .map(Math::abs)
        .max(Float::compare)
        .orElse(Float.NaN);

    It's a little more readable. Also, I didn't test it.

    the contribution guidelines say no ;)

    also this is my first pull request so let's see how this goes

  7. Stefterv
    added
    enhancementNew feature or requestNew feature or request
    core
    on Nov 16, 2024
  8. Stefterv
    assigned
    Stefterv
    and
    SableRaf
    on Nov 16, 2024
  9. SableRaf commented on Jan 17, 2025

    @SableRaf
    SableRaf
    on Jan 17, 2025
    Collaborator
    More actions

    Hey @rndmbluescreen are you still interested in this issue? If so would you mind re-submitting your PR (link)?

    cc @PianoMastR64 @Stefterv

  10. Stefterv
    unassigned
    SableRaf
    and
    Stefterv
    on Aug 11, 2025
  11. Stefterv
    added
    help wantedExtra attention is neededExtra attention is needed
    good first issueGood for newcomersGood for newcomers
    on Aug 11, 2025
  12. junavw commented on Oct 7, 2025

    @junavw
    junavw
    on Oct 7, 2025
    More actions

    @Stefterv
    Hello,
    We are college students and our goal is to practice and learn by contributing to open source projects. We found this project and would like to contribute. Could you please assign this issue to us as a starting point? Thank you!

  13. junavw commented on Oct 8, 2025

    @junavw
    junavw
    on Oct 8, 2025
    More actions

    @SableRaf ?

  14. junavw commented on Oct 9, 2025

    @junavw
    junavw
    on Oct 9, 2025
    More actions

    Hello, sorry for the short notice, but we’re very interested in this project and would really like to contribute. Would it be possible to assign this issue to us? Thank you.

  15. junavw commented on Oct 13, 2025

    @junavw
    junavw
    on Oct 13, 2025
    More actions

    @Stefterv ?

  16. Sumamasonia commented on Dec 6, 2025

    @Sumamasonia
    Sumamasonia
    on Dec 6, 2025
    Contributor
    More actions

    Hi, I noticed there hasn't been activity on this since February. I am a beginner and would like to work on this. Can this be assigned to me so that I can submit a PR?

  17. Sumamasonia commented on Dec 19, 2025

    @Sumamasonia
    Sumamasonia
    on Dec 19, 2025
    Contributor
    More actions

    @Stefterv , I want to work on this so can you assign this issue to me?

  18. SableRaf commented on Dec 19, 2025

    @SableRaf
    SableRaf
    on Dec 19, 2025
    Collaborator
    More actions

    Hi @junavw. Hello @Sumamasonia. Thanks for your interest in contributing to Processing.

    Please take a look at the Contributor Guidelines and in particular the Making your First Contribution section. If you have any questions, feel free to join our Discord and ask in the contribute-to-processing channel.

    Please note that we may be slow to answer due to the holidays.

  19. satindra-r commented on Jan 23, 2026

    @satindra-r
    satindra-r
    on Jan 23, 2026
    More actions

    Hello, I am interested in working on this issue. I would like to add print() to the PMatrix interface and override them in the PMatrix2D and PMatrix3D classes.

  20. catilac
    assigned
    Sumamasonia
    on Jan 29, 2026
  21. catilac commented on Jan 29, 2026

    @catilac
    catilac
    on Jan 29, 2026
    Collaborator
    More actions

    @satindra-r hi! we do have a solution out there with some requested changes. please reach out to us in the discord because there are many other tasks i can get you started on

  22. catilac
    closed this as completedin e03e31bon Jan 30, 2026
  23. pull
    added a commit that references this issue on Jan 30, 2026

    Added print() method to PMatrix (Fixes processing#811) (processing#1355)

    This issue will close once commit e03e31b is merged into the 'main' branch.
    e03e31b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Sumamasonia
    Sumamasonia

Labels

coreenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.