* The reference point
* @return The anchor location
*/
@Override
public Point getLocation(Point reference) {
Polygon owner;
if (getOwner() instanceof VertexFigure) {
owner = (Polygon) getOwner().getChildren().get(0);
} else {
throw new NullPointerException();
}
Point center = getReferencePoint();
if (reference.x == center.x && reference.y == center.y) {
return center;
}
// The line run
float run = (reference.x - center.x);
PointList pointList = owner.getPoints();
for (int i = 0; i < pointList.size() - 1; i++) {
Point start = pointList.getPoint(i);
Point end = pointList.getPoint(i + 1);
// Translate from relative to absolute coordinates
owner.translateToAbsolute(start);
owner.translateToAbsolute(end);
// Check intersection
if (Geometry.linesIntersect(center.x, center.y, reference.x,
reference.y, start.x, start.y, end.x, end.y)) {
float p = ((float) (start.y - end.y))