A bunch of add/substract to syncmake i.Point with f/d.Point.

Closes #24.
This commit is contained in:
Michael Bayne
2013-05-24 06:10:03 -07:00
parent d97a7a20b1
commit 0ff90d641e
3 changed files with 75 additions and 4 deletions
+29 -4
View File
@@ -10,26 +10,51 @@ package pythagoras.i;
*/
public abstract class AbstractPoint implements IPoint
{
@Override // from interface IPoint
@Override // from IPoint
public int distanceSq (int px, int py) {
return Points.distanceSq(x(), y(), px, py);
}
@Override // from interface IPoint
@Override // from IPoint
public int distanceSq (IPoint p) {
return Points.distanceSq(x(), y(), p.x(), p.y());
}
@Override // from interface IPoint
@Override // from IPoint
public int distance (int px, int py) {
return Points.distance(x(), y(), px, py);
}
@Override // from interface IPoint
@Override // from IPoint
public int distance (IPoint p) {
return Points.distance(x(), y(), p.x(), p.y());
}
@Override // from IPoint
public Point add (int x, int y) {
return new Point(x() + x, y() + y);
}
@Override // from IPoint
public Point add (int x, int y, Point result) {
return result.set(x() + x, y() + y);
}
@Override // from IPoint
public Point subtract (int x, int y) {
return subtract(x, y, new Point());
}
@Override
public Point subtract (int x, int y, Point result) {
return result.set(x() - x, y() - y);
}
@Override
public Point subtract (IPoint other, Point result) {
return subtract(other.x(), other.y(), result);
}
@Override // from interface IPoint
public Point clone () {
return new Point(this);
+20
View File
@@ -27,6 +27,26 @@ public interface IPoint extends Cloneable
/** Returns the Euclidian distance between this point and the supplied point. */
int distance (IPoint p);
/** Translates this point by the specified offset.
* @return a new point containing the result. */
Point add (int x, int y);
/** Translates this point by the specified offset and stores the result in the object provided.
* @return a reference to the result, for chaining. */
Point add (int x, int y, Point result);
/** Subtracts the supplied point from {@code this}.
* @return a new point containing the result. */
Point subtract (int x, int y);
/** Subtracts the supplied point from {@code this} and stores the result in {@code result}.
* @return a reference to the result, for chaining. */
Point subtract (int x, int y, Point result);
/** Subtracts the supplied point from {@code this} and stores the result in {@code result}.
* @return a reference to the result, for chaining. */
Point subtract (IPoint other, Point result);
/** Returns a mutable copy of this point. */
Point clone ();
}
+26
View File
@@ -67,6 +67,32 @@ public class Point extends AbstractPoint implements Serializable
y += dy;
}
/** Sets the coordinates of this point to be equal to those of the supplied point.
* @return a reference to this this, for chaining. */
public Point set (IPoint p) {
return set(p.x(), p.y());
}
/** Sets the coordinates of this point to the supplied values.
* @return a reference to this this, for chaining. */
public Point set (int x, int y) {
this.x = x;
this.y = y;
return this;
}
/** Translates this point by the specified offset.
* @return a reference to this point, for chaining. */
public Point addLocal (int dx, int dy) {
return add(dx, dy, this);
}
/** Subtracts the supplied x/y from this point.
* @return a reference to this point, for chaining. */
public Point subtractLocal (int x, int y) {
return subtract(x, y, this);
}
@Override // from interface IPoint
public int x () {
return x;