/** * Subtracts the values of the given source vector from those of this vector and returns them in store. * * @param source * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return (this.x - source.x, this.y - source.y, this.z - source.z, this.w - source.w) * @throws NullPointerException * if source is null. */ @Override public Vector4 subtract(final ReadOnlyVector4 source, final Vector4 store) { return subtract(source.getX(), source.getY(), source.getZ(), source.getW(), store); }
@Test public void testSubtract() { final Vector4 vec1 = new Vector4(); final Vector4 vec2 = new Vector4(Vector4.ONE); vec1.subtractLocal(1, 2, 3, 4); assertEquals(new Vector4(-1, -2, -3, -4), vec1); vec1.subtractLocal(-1, -2, -3, -4); assertEquals(Vector4.ZERO, vec1); vec1.zero(); vec1.subtractLocal(vec2); assertEquals(Vector4.NEG_ONE, vec1); vec1.zero(); final Vector4 vec3 = vec1.subtract(vec2, new Vector4()); assertEquals(Vector4.ZERO, vec1); assertEquals(Vector4.NEG_ONE, vec3); final Vector4 vec4 = vec1.subtract(0, 0, 0, 1, null); assertEquals(Vector4.ZERO, vec1); assertEquals(Vector4.NEG_UNIT_W, vec4); }
/** * Subtracts the values of the given source vector from those of this vector and returns them in store. * * @param source * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return (this.x - source.x, this.y - source.y, this.z - source.z, this.w - source.w) * @throws NullPointerException * if source is null. */ @Override public Vector4 subtract(final ReadOnlyVector4 source, final Vector4 store) { return subtract(source.getX(), source.getY(), source.getZ(), source.getW(), store); }