Vec2 { public float[] toArray(float[] result, int offset) { if (result == null || result.length - offset < 2) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Vec2", "toArray", "missingResult")); } result[offset++] = (float) this.x; result[offset] = (float) this.y; return result; } 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 testToArray() throws Exception { Vec2 u = new Vec2(X, Y); float[] a = u.toArray(new float[2], 0); assertEquals("u.x", (float) u.x, a[0], 0f); assertEquals("u.y", (float) u.y, a[1], 0f); }
@Test public void testToArray_Offset() throws Exception { Vec2 u = new Vec2(X, Y); int offset = 2; float[] array = new float[6]; u.toArray(array, offset); for (int i = 0; i < offset; i++) { assertEquals("element = 0", 0, array[i], 0f); } assertEquals("u.x", (float) u.x, array[offset], 0f); assertEquals("u.y", (float) u.y, array[offset + 1], 0f); for (int i = offset + 2; i < array.length; i++) { assertEquals("element = 0", 0, array[i], 0f); } }
@Test(expected = IllegalArgumentException.class) public void testToArray_ArrayTooSmall() throws Exception { Vec2 u = new Vec2(X, Y); u.toArray(new float[2], 1); fail("expected IllegalArgumentException"); }