in graphLayout/jetbrains.mps.graphLayout.graph/source_gen/jetbrains/mps/graphLayout/outputUtil/GraphLayoutOutputUtil.java [39:86]
public static Point2D getRectPosAlongPolyline(List<Point> route, Rectangle rect) {
Point prev = null;
int x = rect.x;
int y = rect.y;
Point res = null;
int len = 0;
int num = 0;
for (Point next : ListSequence.fromList(route)) {
if (prev == null || prev.equals(next)) {
prev = next;
continue;
}
num++;
if (prev.x == next.x && prev.x == x) {
if ((prev.y - y) * (next.y - y) < 0) {
int yCenter = y + rect.height / 2;
int dist = rect.width / 2;
if (prev.y > next.y) {
dist = -dist;
}
res = new Point(len + Math.abs(yCenter - prev.y), dist);
}
}
if (prev.y == next.y && prev.y == y) {
if ((prev.x - x) * (next.x - x) < 0) {
int xCenter = x + rect.width / 2;
int dist = rect.height / 2;
if (prev.x < next.x) {
dist = -dist;
}
res = new Point(len + Math.abs(xCenter - prev.x), dist);
}
}
len += prev.manhattanDist(next);
prev = next;
}
if (res == null) {
return null;
}
int l = len / 2;
double relX = 1.0 * Math.abs(res.x - l) / l;
if (res.x < l) {
relX = -relX;
}
Point2D.Double point = new Point2D.Double(relX, res.y);
return point;
}