/** * Adds the values of the given source vector to 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) * @throws NullPointerException * if source is null. */ @Override public Vector2 add(final ReadOnlyVector2 source, final Vector2 store) { return add(source.getX(), source.getY(), store); }
@Test public void testAdd() { final Vector2 vec1 = new Vector2(); final Vector2 vec2 = new Vector2(Vector2.ONE); vec1.addLocal(1, 2); assertEquals(new Vector2(1, 2), vec1); vec1.addLocal(-1, -2); assertEquals(Vector2.ZERO, vec1); vec1.zero(); vec1.addLocal(vec2); assertEquals(Vector2.ONE, vec1); vec1.zero(); final Vector2 vec3 = vec1.add(vec2, new Vector2()); assertEquals(Vector2.ZERO, vec1); assertEquals(Vector2.ONE, vec3); final Vector2 vec4 = vec1.add(1, 0, null); assertEquals(Vector2.ZERO, vec1); assertEquals(Vector2.UNIT_X, vec4); }
/** * Adds the values of the given source vector to 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) * @throws NullPointerException * if source is null. */ @Override public Vector2 add(final ReadOnlyVector2 source, final Vector2 store) { return add(source.getX(), source.getY(), store); }