diff --git a/src/main/java/pythagoras/d/AbstractPoint.java b/src/main/java/pythagoras/d/AbstractPoint.java index 0a96f42..a955791 100644 --- a/src/main/java/pythagoras/d/AbstractPoint.java +++ b/src/main/java/pythagoras/d/AbstractPoint.java @@ -52,6 +52,21 @@ public abstract class AbstractPoint implements IPoint return result.set(x() + x, y() + y); } + @Override // from IPoint + public Vector subtract (double x, double y) { + return subtract(x, y, new Vector()); + } + + @Override + public Vector subtract (double x, double y, Vector result) { + return result.set(x() - x, y() - y); + } + + @Override + public Vector subtract (IPoint other, Vector result) { + return subtract(other.x(), other.y(), result); + } + @Override // from IPoint public Point rotate (double angle) { return rotate(angle, new Point()); diff --git a/src/main/java/pythagoras/d/IPoint.java b/src/main/java/pythagoras/d/IPoint.java index 7ab2cd6..349ae81 100644 --- a/src/main/java/pythagoras/d/IPoint.java +++ b/src/main/java/pythagoras/d/IPoint.java @@ -43,6 +43,18 @@ public interface IPoint extends Cloneable * @return a reference to the result, for chaining. */ Point add (double x, double y, Point result); + /** Subtracts the supplied point from {@code this}. + * @return a new vector containing the result. */ + Vector subtract (double x, double y); + + /** Subtracts the supplied point from {@code this} and stores the result in {@code result}. + * @return a reference to the result, for chaining. */ + Vector subtract (double x, double y, Vector result); + + /** Subtracts the supplied point from {@code this} and stores the result in {@code result}. + * @return a reference to the result, for chaining. */ + Vector subtract (IPoint other, Vector result); + /** Rotates this point around the origin by the specified angle. * @return a new point containing the result. */ Point rotate (double angle); diff --git a/src/main/java/pythagoras/f/AbstractPoint.java b/src/main/java/pythagoras/f/AbstractPoint.java index 2b914b7..6f5a8cb 100644 --- a/src/main/java/pythagoras/f/AbstractPoint.java +++ b/src/main/java/pythagoras/f/AbstractPoint.java @@ -52,6 +52,21 @@ public abstract class AbstractPoint implements IPoint return result.set(x() + x, y() + y); } + @Override // from IPoint + public Vector subtract (float x, float y) { + return subtract(x, y, new Vector()); + } + + @Override + public Vector subtract (float x, float y, Vector result) { + return result.set(x() - x, y() - y); + } + + @Override + public Vector subtract (IPoint other, Vector result) { + return subtract(other.x(), other.y(), result); + } + @Override // from IPoint public Point rotate (float angle) { return rotate(angle, new Point()); diff --git a/src/main/java/pythagoras/f/IPoint.java b/src/main/java/pythagoras/f/IPoint.java index 9f62af6..7cb81d7 100644 --- a/src/main/java/pythagoras/f/IPoint.java +++ b/src/main/java/pythagoras/f/IPoint.java @@ -43,6 +43,18 @@ public interface IPoint extends Cloneable * @return a reference to the result, for chaining. */ Point add (float x, float y, Point result); + /** Subtracts the supplied point from {@code this}. + * @return a new vector containing the result. */ + Vector subtract (float x, float y); + + /** Subtracts the supplied point from {@code this} and stores the result in {@code result}. + * @return a reference to the result, for chaining. */ + Vector subtract (float x, float y, Vector result); + + /** Subtracts the supplied point from {@code this} and stores the result in {@code result}. + * @return a reference to the result, for chaining. */ + Vector subtract (IPoint other, Vector result); + /** Rotates this point around the origin by the specified angle. * @return a new point containing the result. */ Point rotate (float angle);