A bunch of add/substract to syncmake i.Point with f/d.Point.
Closes #24.
This commit is contained in:
@@ -10,26 +10,51 @@ package pythagoras.i;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractPoint implements IPoint
|
public abstract class AbstractPoint implements IPoint
|
||||||
{
|
{
|
||||||
@Override // from interface IPoint
|
@Override // from IPoint
|
||||||
public int distanceSq (int px, int py) {
|
public int distanceSq (int px, int py) {
|
||||||
return Points.distanceSq(x(), y(), px, py);
|
return Points.distanceSq(x(), y(), px, py);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IPoint
|
@Override // from IPoint
|
||||||
public int distanceSq (IPoint p) {
|
public int distanceSq (IPoint p) {
|
||||||
return Points.distanceSq(x(), y(), p.x(), p.y());
|
return Points.distanceSq(x(), y(), p.x(), p.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IPoint
|
@Override // from IPoint
|
||||||
public int distance (int px, int py) {
|
public int distance (int px, int py) {
|
||||||
return Points.distance(x(), y(), px, py);
|
return Points.distance(x(), y(), px, py);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IPoint
|
@Override // from IPoint
|
||||||
public int distance (IPoint p) {
|
public int distance (IPoint p) {
|
||||||
return Points.distance(x(), y(), p.x(), p.y());
|
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
|
@Override // from interface IPoint
|
||||||
public Point clone () {
|
public Point clone () {
|
||||||
return new Point(this);
|
return new Point(this);
|
||||||
|
|||||||
@@ -27,6 +27,26 @@ public interface IPoint extends Cloneable
|
|||||||
/** Returns the Euclidian distance between this point and the supplied point. */
|
/** Returns the Euclidian distance between this point and the supplied point. */
|
||||||
int distance (IPoint p);
|
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. */
|
/** Returns a mutable copy of this point. */
|
||||||
Point clone ();
|
Point clone ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,32 @@ public class Point extends AbstractPoint implements Serializable
|
|||||||
y += dy;
|
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
|
@Override // from interface IPoint
|
||||||
public int x () {
|
public int x () {
|
||||||
return x;
|
return x;
|
||||||
|
|||||||
Reference in New Issue
Block a user