Vec3 { public Vec3 mix(Vec3 vector, double weight) { if (vector == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Vec3", "mix", "missingVector")); } double w0 = 1 - weight; double w1 = weight; this.x = this.x * w0 + vector.x * w1; this.y = this.y * w0 + vector.y * w1; this.z = this.z * w0 + vector.z * w1; return this; } Vec3();  Vec3(double x, double y, double z);  Vec3(Vec3 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec3 vector); double distanceToSquared(Vec3 vector); Vec3 set(double x, double y, double z); Vec3 set(Vec3 vector); Vec3 swap(Vec3 vector); Vec3 add(Vec3 vector); Vec3 subtract(Vec3 vector); Vec3 multiply(double scalar); Vec3 multiplyByMatrix(Matrix4 matrix); Vec3 divide(double divisor); Vec3 negate(); Vec3 normalize(); double dot(Vec3 vector); Vec3 cross(Vec3 vector); Vec3 cross(Vec3 a, Vec3 b); Vec3 mix(Vec3 vector, double weight); public double x; public double y; public double z; }
@Test public void testMix() throws Exception { final double weight = 0.75; final double x1 = 3.1d; final double y1 = 4.3d; final double z1 = 5.5d; final double x2 = 6.2d; final double y2 = 7.4d; final double z2 = 8.6d; Vec3 u = new Vec3(x1, y1, z1); Vec3 v = new Vec3(x2, y2, z2); Vec3 w = u.mix(v, weight); assertEquals("u.x", x1 + ((x2 - x1) * weight), u.x, TOLERANCE); assertEquals("u.y", y1 + ((y2 - y1) * weight), u.y, TOLERANCE); assertEquals("u.z", z1 + ((z2 - z1) * weight), u.z, TOLERANCE); assertEquals("v.x", x2, v.x, 0d); assertEquals("v.y", y2, v.y, 0d); assertEquals("v.z", z2, v.z, 0d); assertSame("w == u", u, w); }
@Test(expected = IllegalArgumentException.class) public void testMix_WithNull() throws Exception { PowerMockito.mockStatic(Logger.class); final double weight = 5d; Vec3 u = new Vec3(3, 4, 5); u.mix(null, weight); fail("Expected an IllegalArgumentException to be thrown."); }