GeezerVison is showing github.com — Give PMatrix a print() method · Issue #811 · processing/processing4
Give PMatrix a print() method #811DescriptionCreated 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();
}
}Activityprocessing-bot commented 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. processing-bot commented 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 processing-bot commented 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();
}
}processing-bot commented 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. processing-bot commented 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 processing-bot commented 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 SableRaf commented on Jan 17, 2025 junavw commented on Oct 7, 2025 @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! junavw commented on Oct 8, 2025 junavw commented on Oct 9, 2025 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. junavw commented on Oct 13, 2025 Sumamasonia commented on Dec 6, 2025 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? Sumamasonia commented on Dec 19, 2025 @Stefterv , I want to work on this so can you assign this issue to me? SableRaf commented on Dec 19, 2025 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. satindra-r commented on Jan 23, 2026 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. catilac commented on Jan 29, 2026 @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 added a commit that references this issue on Jan 30, 2026This issue will close once commit e03e31b is merged into the 'main' branch.e03e31b
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|