Vec2 { public Vec2 multiplyByMatrix(Matrix3 matrix) { if (matrix == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Vec2", "multiplyByMatrix", "missingMatrix")); } double[] m = matrix.m; double x = (m[0] * this.x) + (m[1] * this.y) + m[2]; double y = (m[3] * this.x) + (m[4] * this.y) + m[5]; double z = (m[6] * this.x) + (m[7] * this.y) + m[8]; this.x = x / z; this.y = y / z; return this; } Vec2();  Vec2(double x, double y);  Vec2(Vec2 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec2 vector); double distanceToSquared(Vec2 vector); Vec2 set(double x, double y); Vec2 set(Vec2 vector); Vec2 swap(Vec2 vector); Vec2 add(Vec2 vector); Vec2 subtract(Vec2 vector); Vec2 multiply(double scalar); Vec2 multiplyByMatrix(Matrix3 matrix); Vec2 divide(double divisor); Vec2 negate(); Vec2 normalize(); double dot(Vec2 vector); Vec2 mix(Vec2 vector, double weight); public double x; public double y; }
@Test public void testMultiplyByMatrix() throws Exception { double theta = 30d; double x = 2; double y = 3; Matrix3 m = new Matrix3().multiplyByRotation(theta).setTranslation(x, y); Vec2 u = new Vec2(1, 0).multiplyByMatrix(m); assertEquals("acos u.x", theta, Math.toDegrees(Math.acos(u.x - x)), 1e-10); assertEquals("asin u.y", theta, Math.toDegrees(Math.asin(u.y - y)), 1e-10); }
@Test public void testMultiplyByMatrix_NaN() throws Exception { Matrix3 m = new Matrix3().multiplyByRotation(Double.NaN); assertTrue("Rotation NaN", hasNaN(new Vec2(1, 0).multiplyByMatrix(m))); }
@Test(expected = IllegalArgumentException.class) public void testMultiplyByMatrix_WithNull() throws Exception { Vec2 u = new Vec2(); u.multiplyByMatrix(null); fail("Expected an IllegalArgumentException to be thrown."); }