diff --git a/core/src/processing/core/PMatrix.java b/core/src/processing/core/PMatrix.java index edb1d260e..df15dc4a4 100644 --- a/core/src/processing/core/PMatrix.java +++ b/core/src/processing/core/PMatrix.java @@ -205,4 +205,8 @@ public void preApply(float n00, float n01, float n02, float n03, * @return the determinant of the matrix */ public float determinant(); + /** + * Print the matrix data to the console. + */ + public void print(); } diff --git a/core/src/processing/core/PMatrix2D.java b/core/src/processing/core/PMatrix2D.java index c30a3504e..bc6538f91 100644 --- a/core/src/processing/core/PMatrix2D.java +++ b/core/src/processing/core/PMatrix2D.java @@ -466,26 +466,15 @@ public float determinant() { ////////////////////////////////////////////////////////////// + @Override public void print() { - 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() - } - - System.out.println(PApplet.nfs(m00, digits, 4) + " " + - PApplet.nfs(m01, digits, 4) + " " + - PApplet.nfs(m02, digits, 4)); - - System.out.println(PApplet.nfs(m10, digits, 4) + " " + - PApplet.nfs(m11, digits, 4) + " " + - PApplet.nfs(m12, digits, 4)); + System.out.print(toString()); + } - System.out.println(); + @Override + public String toString() { + return PApplet.nfs(m00, 1, 4) + " " + PApplet.nfs(m01, 1, 4) + " " + PApplet.nfs(m02, 1, 4) + "\n" + + PApplet.nfs(m10, 1, 4) + " " + PApplet.nfs(m11, 1, 4) + " " + PApplet.nfs(m12, 1, 4) + "\n"; } diff --git a/core/src/processing/core/PMatrix3D.java b/core/src/processing/core/PMatrix3D.java index 831d9ad63..082d7fa8c 100644 --- a/core/src/processing/core/PMatrix3D.java +++ b/core/src/processing/core/PMatrix3D.java @@ -809,52 +809,18 @@ protected boolean invApply(float n00, float n01, float n02, float n03, ////////////////////////////////////////////////////////////// + @Override public void print() { - /* - System.out.println(m00 + " " + m01 + " " + m02 + " " + m03 + "\n" + - m10 + " " + m11 + " " + m12 + " " + m13 + "\n" + - m20 + " " + m21 + " " + m22 + " " + m23 + "\n" + - m30 + " " + m31 + " " + m32 + " " + m33 + "\n"); - */ - int big = (int) Math.abs(max(max(max(max(abs(m00), abs(m01)), - max(abs(m02), abs(m03))), - max(max(abs(m10), abs(m11)), - max(abs(m12), abs(m13)))), - max(max(max(abs(m20), abs(m21)), - max(abs(m22), abs(m23))), - max(max(abs(m30), abs(m31)), - max(abs(m32), 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() - } - - System.out.println(PApplet.nfs(m00, digits, 4) + " " + - PApplet.nfs(m01, digits, 4) + " " + - PApplet.nfs(m02, digits, 4) + " " + - PApplet.nfs(m03, digits, 4)); - - System.out.println(PApplet.nfs(m10, digits, 4) + " " + - PApplet.nfs(m11, digits, 4) + " " + - PApplet.nfs(m12, digits, 4) + " " + - PApplet.nfs(m13, digits, 4)); - - System.out.println(PApplet.nfs(m20, digits, 4) + " " + - PApplet.nfs(m21, digits, 4) + " " + - PApplet.nfs(m22, digits, 4) + " " + - PApplet.nfs(m23, digits, 4)); - - System.out.println(PApplet.nfs(m30, digits, 4) + " " + - PApplet.nfs(m31, digits, 4) + " " + - PApplet.nfs(m32, digits, 4) + " " + - PApplet.nfs(m33, digits, 4)); - - System.out.println(); + System.out.print(toString()); } + @Override + public String toString() { + return PApplet.nfs(m00, 1, 4) + " " + PApplet.nfs(m01, 1, 4) + " " + PApplet.nfs(m02, 1, 4) + " " + PApplet.nfs(m03, 1, 4) + "\n" + + PApplet.nfs(m10, 1, 4) + " " + PApplet.nfs(m11, 1, 4) + " " + PApplet.nfs(m12, 1, 4) + " " + PApplet.nfs(m13, 1, 4) + "\n" + + PApplet.nfs(m20, 1, 4) + " " + PApplet.nfs(m21, 1, 4) + " " + PApplet.nfs(m22, 1, 4) + " " + PApplet.nfs(m23, 1, 4) + "\n" + + PApplet.nfs(m30, 1, 4) + " " + PApplet.nfs(m31, 1, 4) + " " + PApplet.nfs(m32, 1, 4) + " " + PApplet.nfs(m33, 1, 4) + "\n"; + } //////////////////////////////////////////////////////////////