diff --git a/src/main/java/pythagoras/f/AbstractVector.java b/src/main/java/pythagoras/f/AbstractVector.java index 7b7b76e..cc14c73 100644 --- a/src/main/java/pythagoras/f/AbstractVector.java +++ b/src/main/java/pythagoras/f/AbstractVector.java @@ -136,6 +136,16 @@ public abstract class AbstractVector implements IVector return result.set(x() + x, y() + y); } + @Override // from interface IVector + public Vector subtract (float x, float y) { + return subtract(x, y, new Vector()); + } + + @Override // from interface IVector + public Vector subtract (float x, float y, Vector result) { + return result.set(x() - x, y() - y); + } + @Override // from interface IVector public Vector addScaled (IVector other, float v) { return addScaled(other, v, new Vector()); diff --git a/src/main/java/pythagoras/f/IVector.java b/src/main/java/pythagoras/f/IVector.java index a7147b8..5f36dc9 100644 --- a/src/main/java/pythagoras/f/IVector.java +++ b/src/main/java/pythagoras/f/IVector.java @@ -115,6 +115,14 @@ public interface IVector * @return a reference to the result, for chaining. */ Vector subtract (IVector other, Vector result); + /** Subtracts a vector from this one. + * @return a new vector containing the result. */ + Vector subtract (float x, float y); + + /** Subtracts a vector from this one and places the result in the supplied object. + * @return a reference to the result, for chaining. */ + Vector subtract (float x, float y, Vector result); + /** Rotates this vector by the specified angle. * @return a new vector containing the result. */ Vector rotate (float angle);