public class Tuple3f { public float x; public float y; public float z; public Tuple3f(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } public Tuple3f(float t[]) { // ArrayIndexOutOfBounds is thrown if t.length < 3 this.x = t[0]; this.y = t[1]; this.z = t[2]; } public Tuple3f(Tuple3f t1) { x = t1.x; y = t1.y; z = t1.z; } public Tuple3f() { x = 0.0f; y = 0.0f; z = 0.0f; } public final void set(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } public final void set(float t[]) { // ArrayIndexOutOfBounds is thrown if t.length < 3 x = t[0]; y = t[1]; z = t[2]; } public final void set(Tuple3f t1) { x = t1.x; y = t1.y; z = t1.z; } public final void get(float t[]) { // ArrayIndexOutOfBounds is thrown if t.length < 3 t[0] = x; t[1] = y; t[2] = z; } public final void get(Tuple3f t) { t.x = x; t.y = y; t.z = z; } public void add(Tuple3f t1) { x += t1.x; y += t1.y; z += t1.z; } public static Tuple3f add(Tuple3f t1, Tuple3f t2) { Tuple3f t = new Tuple3f(t1); t.add(t2); return t; } public static Tuple3f sub(Tuple3f t1, Tuple3f t2) { Tuple3f t = new Tuple3f(t1); t.sub(t2); return t; } public void sub(Tuple3f t1) { x -= t1.x; y -= t1.y; z -= t1.z; } public final void negate(Tuple3f t1) { x = -t1.x; y = -t1.y; z = -t1.z; } public final void negate() { x = -x; y = -y; z = -z; } public final void scale(float s) { x *= s; y *= s; z *= s; } public boolean equals(Tuple3f t1) { return t1 != null && x == t1.x && y == t1.y && z == t1.z; } public String toString() { return "(" + x + ", " + y + ", " + z +")"; } public final void absolute(Tuple3f t) { set(t); absolute(); } public final void absolute() { if (x < 0.0) x = -x; if (y < 0.0) y = -y; if (z < 0.0) z = -z; } public void println(String leader) { System.out.println(leader + toString()); } }