This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
BWMirror-Generator/manual-bwapi/AbstractPoint.java
2017-04-11 10:48:21 -04:00

30 lines
764 B
Java

package bwapi;
/**
* Common ancestor for location based objects to simplify distance computation.
* This will be refactored into interface with default methods when java 8 becomes widely used.
*
* Idea by Rafa³ Poniatowski
*/
public abstract class AbstractPoint<T extends AbstractPoint> {
public abstract T getPoint();
public int getX(){
return getPoint().getX();
}
public int getY(){
return getPoint().getY();
}
public double getDistance(AbstractPoint<T> otherPosition) {
return getDistance(otherPosition.getX(), otherPosition.getY());
}
public double getDistance(int x, int y) {
double dx = x - getX();
double dy = y - getY();
return Math.sqrt(dx * dx + dy * dy);
}
}