mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
* Add print method to PMatrix interface Added a default method to print matrix data. * docs: add print() method declaration to PMatrix interface * refactor: implement toString and override print in PMatrix2D * refactor: implement toString and override print in PMatrix3D
This commit is contained in:
@@ -205,4 +205,8 @@ public interface PMatrix {
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public float determinant();
|
||||
/**
|
||||
* Print the matrix data to the console.
|
||||
*/
|
||||
public void print();
|
||||
}
|
||||
|
||||
@@ -466,26 +466,15 @@ public class PMatrix2D implements PMatrix {
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@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))));
|
||||
System.out.print(toString());
|
||||
}
|
||||
|
||||
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.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";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -809,52 +809,18 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@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";
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user