Fixed Vector.cross and optimized the Vector tests slightly.

This commit is contained in:
TomyLobo 2012-01-08 03:21:35 +01:00
parent e810113ea0
commit e1428602af
2 changed files with 11 additions and 11 deletions

View File

@ -503,9 +503,9 @@ public double dot(Vector other) {
*/ */
public Vector cross(Vector other) { public Vector cross(Vector other) {
return new Vector( return new Vector(
y * other.z + z * other.y, y * other.z - z * other.y,
z * other.x + x * other.z, z * other.x - x * other.z,
x * other.y + y * other.x x * other.y - y * other.x
); );
} }

View File

@ -100,16 +100,16 @@ private void assertCollinear(double ax, double ay, double az, double bx, double
final Vector b = new Vector(bx,by,bz); final Vector b = new Vector(bx,by,bz);
assertTrue(a.isCollinearWith(b)); assertTrue(a.isCollinearWith(b));
assertTrue(b.isCollinearWith(a)); assertTrue(b.isCollinearWith(a));
assertTrue(a.multiply(-1).isCollinearWith(b)); assertTrue(a.multiply(-1.0).isCollinearWith(b));
assertTrue(a.isCollinearWith(b.multiply(-1))); assertTrue(a.isCollinearWith(b.multiply(-1.0)));
} }
private void assertNotCollinear(double ax, double ay, double az, double bx, double by, double bz) { private void assertNotCollinear(double ax, double ay, double az, double bx, double by, double bz) {
final Vector a = new Vector(ax,ay,az); final Vector a = new Vector(ax,ay,az);
final Vector b = new Vector(bx,by,bz); final Vector b = new Vector(bx,by,bz);
assertFalse(a.isCollinearWith(b)); assertFalse(a.isCollinearWith(b));
assertFalse(b.isCollinearWith(a)); assertFalse(b.isCollinearWith(a));
assertFalse(a.multiply(-1).isCollinearWith(b)); assertFalse(a.multiply(-1.0).isCollinearWith(b));
assertFalse(a.isCollinearWith(b.multiply(-1))); assertFalse(a.isCollinearWith(b.multiply(-1.0)));
} }
private void assertCollinear(double ax, double az, double bx, double bz) { private void assertCollinear(double ax, double az, double bx, double bz) {
@ -117,15 +117,15 @@ private void assertCollinear(double ax, double az, double bx, double bz) {
final Vector2D b = new Vector2D(bx,bz); final Vector2D b = new Vector2D(bx,bz);
assertTrue(a.isCollinearWith(b)); assertTrue(a.isCollinearWith(b));
assertTrue(b.isCollinearWith(a)); assertTrue(b.isCollinearWith(a));
assertTrue(a.multiply(-1).isCollinearWith(b)); assertTrue(a.multiply(-1.0).isCollinearWith(b));
assertTrue(a.isCollinearWith(b.multiply(-1))); assertTrue(a.isCollinearWith(b.multiply(-1.0)));
} }
private void assertNotCollinear(double ax, double az, double bx, double bz) { private void assertNotCollinear(double ax, double az, double bx, double bz) {
final Vector2D a = new Vector2D(ax,az); final Vector2D a = new Vector2D(ax,az);
final Vector2D b = new Vector2D(bx,bz); final Vector2D b = new Vector2D(bx,bz);
assertFalse(a.isCollinearWith(b)); assertFalse(a.isCollinearWith(b));
assertFalse(b.isCollinearWith(a)); assertFalse(b.isCollinearWith(a));
assertFalse(a.multiply(-1).isCollinearWith(b)); assertFalse(a.multiply(-1.0).isCollinearWith(b));
assertFalse(a.isCollinearWith(b.multiply(-1))); assertFalse(a.isCollinearWith(b.multiply(-1.0)));
} }
} }