From d132e917ed73bcc979c492e584b25f375d533d5a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 11 May 2012 08:41:13 -0700 Subject: [PATCH] Some lingering f to d conversions. --- src/main/java/pythagoras/d/MathUtil.java | 4 +-- src/main/java/pythagoras/d/Matrix3.java | 12 +++++--- src/main/java/pythagoras/d/Matrix4.java | 9 ++++++ src/main/java/pythagoras/d/Transforms.java | 36 +++++++++------------- src/main/java/pythagoras/d/Vector.java | 6 ++++ 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/main/java/pythagoras/d/MathUtil.java b/src/main/java/pythagoras/d/MathUtil.java index a5b9308..e071828 100644 --- a/src/main/java/pythagoras/d/MathUtil.java +++ b/src/main/java/pythagoras/d/MathUtil.java @@ -34,7 +34,7 @@ public class MathUtil */ public static int ifloor (double v) { int iv = (int)v; - return (v < 0f) ? ((iv == v || iv == Integer.MIN_VALUE) ? iv : (iv - 1)) : iv; + return (v >= 0f || iv == v || iv == Integer.MIN_VALUE) ? iv : (iv - 1); } /** @@ -43,7 +43,7 @@ public class MathUtil */ public static int iceil (double v) { int iv = (int)v; - return (v > 0f) ? ((iv == v || iv == Integer.MAX_VALUE) ? iv : (iv + 1)) : iv; + return (v <= 0f || iv == v || iv == Integer.MAX_VALUE) ? iv : (iv + 1); } /** diff --git a/src/main/java/pythagoras/d/Matrix3.java b/src/main/java/pythagoras/d/Matrix3.java index 7007626..153be0d 100644 --- a/src/main/java/pythagoras/d/Matrix3.java +++ b/src/main/java/pythagoras/d/Matrix3.java @@ -471,11 +471,8 @@ public class Matrix3 implements IMatrix3, Serializable } /** - * Inverts this matrix and places the result in the given object. This code is based on the - * examples in the Matrix and - * Quaternion FAQ. - * - * @return a reference to the result matrix, for chaining. + * @{@inheritDoc} This code is based on the examples in the + * Matrix and Quaternion FAQ. */ @Override // from IMatrix3 public Matrix3 invert (Matrix3 result) throws SingularMatrixException { @@ -641,6 +638,11 @@ public class Matrix3 implements IMatrix3, Serializable return result.set(m00*vx + m10*vy, m01*vx + m11*vy); } + /** + * {@inheritDoc} This uses the iterative polar decomposition algorithm described by + * Ken + * Shoemake. + */ @Override // from IMatrix3 public double extractRotation () { // start with the contents of the upper 2x2 portion of the matrix diff --git a/src/main/java/pythagoras/d/Matrix4.java b/src/main/java/pythagoras/d/Matrix4.java index abf8f1a..8d53d0d 100644 --- a/src/main/java/pythagoras/d/Matrix4.java +++ b/src/main/java/pythagoras/d/Matrix4.java @@ -705,6 +705,10 @@ public final class Matrix4 implements IMatrix4, Serializable return invert(new Matrix4()); } + /** + * {@inheritDoc} This code is based on the examples in the + * Matrix and Quaternion FAQ. + */ @Override // from IMatrix4 public Matrix4 invert (Matrix4 result) throws SingularMatrixException { double m00 = this.m00, m10 = this.m10, m20 = this.m20, m30 = this.m30; @@ -917,6 +921,11 @@ public final class Matrix4 implements IMatrix4, Serializable return extractRotation(new Quaternion()); } + /** + * {@inheritDoc} This uses the iterative polar decomposition algorithm described by + * Ken + * Shoemake. + */ @Override // from IMatrix4 public Quaternion extractRotation (Quaternion result) throws SingularMatrixException { // start with the contents of the upper 3x3 portion of the matrix diff --git a/src/main/java/pythagoras/d/Transforms.java b/src/main/java/pythagoras/d/Transforms.java index 82649a9..a010797 100644 --- a/src/main/java/pythagoras/d/Transforms.java +++ b/src/main/java/pythagoras/d/Transforms.java @@ -31,8 +31,7 @@ public class Transforms * into} may refer to the same instance as {@code a} or {@code b}. * @return {@code into} for chaining. */ - public static AffineTransform multiply ( - AffineTransform a, AffineTransform b, AffineTransform into) { + public static T multiply (AffineTransform a, AffineTransform b, T into) { return multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, b.m00, b.m01, b.m10, b.m11, b.tx, b.ty, into); } @@ -42,11 +41,9 @@ public class Transforms * into} may refer to the same instance as {@code a}. * @return {@code into} for chaining. */ - public static AffineTransform multiply ( - AffineTransform a, double m00, double m01, double m10, double m11, double tx, double ty, - AffineTransform into) { - return multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, - m00, m01, m10, m11, tx, ty, into); + public static T multiply ( + AffineTransform a, double m00, double m01, double m10, double m11, double tx, double ty, T into) { + return multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, m00, m01, m10, m11, tx, ty, into); } /** @@ -54,27 +51,24 @@ public class Transforms * into} may refer to the same instance as {@code b}. * @return {@code into} for chaining. */ - public static AffineTransform multiply ( - double m00, double m01, double m10, double m11, double tx, double ty, - AffineTransform b, AffineTransform into) { - return multiply(m00, m01, m10, m11, tx, ty, - b.m00, b.m01, b.m10, b.m11, b.tx, b.ty, into); + public static T multiply ( + double m00, double m01, double m10, double m11, double tx, double ty, AffineTransform b, T into) { + return multiply(m00, m01, m10, m11, tx, ty, b.m00, b.m01, b.m10, b.m11, b.tx, b.ty, into); } /** * Multiplies the supplied two affine transforms, storing the result in {@code into}. * @return {@code into} for chaining. */ - public static AffineTransform multiply ( + public static T multiply ( double am00, double am01, double am10, double am11, double atx, double aty, - double bm00, double bm01, double bm10, double bm11, double btx, double bty, - AffineTransform into) { - into.m00 = am00 * bm00 + am10 * bm01; - into.m01 = am01 * bm00 + am11 * bm01; - into.m10 = am00 * bm10 + am10 * bm11; - into.m11 = am01 * bm10 + am11 * bm11; - into.tx = am00 * btx + am10 * bty + atx; - into.ty = am01 * btx + am11 * bty + aty; + double bm00, double bm01, double bm10, double bm11, double btx, double bty, T into) { + into.setTransform(am00 * bm00 + am10 * bm01, + am01 * bm00 + am11 * bm01, + am00 * bm10 + am10 * bm11, + am01 * bm10 + am11 * bm11, + am00 * btx + am10 * bty + atx, + am01 * btx + am11 * bty + aty); return into; } } diff --git a/src/main/java/pythagoras/d/Vector.java b/src/main/java/pythagoras/d/Vector.java index faf38a2..60b918f 100644 --- a/src/main/java/pythagoras/d/Vector.java +++ b/src/main/java/pythagoras/d/Vector.java @@ -79,6 +79,12 @@ public class Vector extends AbstractVector return add(x, y, this); } + /** Subtracts a vector in-place from this one. + * @return a reference to this vector, for chaining. */ + public Vector subtractLocal (double x, double y) { + return subtract(x, y, this); + } + /** Adds a scaled vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addScaledLocal (IVector other, double v) {