Some lingering f to d conversions.

This commit is contained in:
Michael Bayne
2012-05-11 08:41:13 -07:00
parent 993b37ed19
commit d132e917ed
5 changed files with 39 additions and 28 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ public class MathUtil
*/ */
public static int ifloor (double v) { public static int ifloor (double v) {
int iv = (int)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) { public static int iceil (double v) {
int iv = (int)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);
} }
/** /**
+7 -5
View File
@@ -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 * @{@inheritDoc} This code is based on the examples in the
* examples in the <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and * <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
* Quaternion FAQ</a>.
*
* @return a reference to the result matrix, for chaining.
*/ */
@Override // from IMatrix3 @Override // from IMatrix3
public Matrix3 invert (Matrix3 result) throws SingularMatrixException { 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); return result.set(m00*vx + m10*vy, m01*vx + m11*vy);
} }
/**
* {@inheritDoc} This uses the iterative polar decomposition algorithm described by
* <a href="http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf">Ken
* Shoemake</a>.
*/
@Override // from IMatrix3 @Override // from IMatrix3
public double extractRotation () { public double extractRotation () {
// start with the contents of the upper 2x2 portion of the matrix // start with the contents of the upper 2x2 portion of the matrix
+9
View File
@@ -705,6 +705,10 @@ public final class Matrix4 implements IMatrix4, Serializable
return invert(new Matrix4()); return invert(new Matrix4());
} }
/**
* {@inheritDoc} This code is based on the examples in the
* <a href="http://www.j3d.org/matrix_faq/matrfaq_latest.html">Matrix and Quaternion FAQ</a>.
*/
@Override // from IMatrix4 @Override // from IMatrix4
public Matrix4 invert (Matrix4 result) throws SingularMatrixException { public Matrix4 invert (Matrix4 result) throws SingularMatrixException {
double m00 = this.m00, m10 = this.m10, m20 = this.m20, m30 = this.m30; 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()); return extractRotation(new Quaternion());
} }
/**
* {@inheritDoc} This uses the iterative polar decomposition algorithm described by
* <a href="http://www.cs.wisc.edu/graphics/Courses/838-s2002/Papers/polar-decomp.pdf">Ken
* Shoemake</a>.
*/
@Override // from IMatrix4 @Override // from IMatrix4
public Quaternion extractRotation (Quaternion result) throws SingularMatrixException { public Quaternion extractRotation (Quaternion result) throws SingularMatrixException {
// start with the contents of the upper 3x3 portion of the matrix // start with the contents of the upper 3x3 portion of the matrix
+15 -21
View File
@@ -31,8 +31,7 @@ public class Transforms
* into} may refer to the same instance as {@code a} or {@code b}. * into} may refer to the same instance as {@code a} or {@code b}.
* @return {@code into} for chaining. * @return {@code into} for chaining.
*/ */
public static AffineTransform multiply ( public static <T extends Transform> T multiply (AffineTransform a, AffineTransform b, T into) {
AffineTransform a, AffineTransform b, AffineTransform into) {
return multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, 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); 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}. * into} may refer to the same instance as {@code a}.
* @return {@code into} for chaining. * @return {@code into} for chaining.
*/ */
public static AffineTransform multiply ( public static <T extends Transform> T multiply (
AffineTransform a, double m00, double m01, double m10, double m11, double tx, double ty, AffineTransform a, double m00, double m01, double m10, double m11, double tx, double ty, T into) {
AffineTransform into) { return multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, m00, m01, m10, m11, tx, ty, 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}. * into} may refer to the same instance as {@code b}.
* @return {@code into} for chaining. * @return {@code into} for chaining.
*/ */
public static AffineTransform multiply ( public static <T extends Transform> T multiply (
double m00, double m01, double m10, double m11, double tx, double ty, double m00, double m01, double m10, double m11, double tx, double ty, AffineTransform b, T into) {
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);
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}. * Multiplies the supplied two affine transforms, storing the result in {@code into}.
* @return {@code into} for chaining. * @return {@code into} for chaining.
*/ */
public static AffineTransform multiply ( public static <T extends Transform> T multiply (
double am00, double am01, double am10, double am11, double atx, double aty, double am00, double am01, double am10, double am11, double atx, double aty,
double bm00, double bm01, double bm10, double bm11, double btx, double bty, double bm00, double bm01, double bm10, double bm11, double btx, double bty, T into) {
AffineTransform into) { into.setTransform(am00 * bm00 + am10 * bm01,
into.m00 = am00 * bm00 + am10 * bm01; am01 * bm00 + am11 * bm01,
into.m01 = am01 * bm00 + am11 * bm01; am00 * bm10 + am10 * bm11,
into.m10 = am00 * bm10 + am10 * bm11; am01 * bm10 + am11 * bm11,
into.m11 = am01 * bm10 + am11 * bm11; am00 * btx + am10 * bty + atx,
into.tx = am00 * btx + am10 * bty + atx; am01 * btx + am11 * bty + aty);
into.ty = am01 * btx + am11 * bty + aty;
return into; return into;
} }
} }
+6
View File
@@ -79,6 +79,12 @@ public class Vector extends AbstractVector
return add(x, y, this); 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. /** Adds a scaled vector in-place to this one.
* @return a reference to this vector, for chaining. */ * @return a reference to this vector, for chaining. */
public Vector addScaledLocal (IVector other, double v) { public Vector addScaledLocal (IVector other, double v) {