// Fix #8631 - Remove duplicated nodes from graph to be robust with self-intersecting ways
Set<Node> removedNodes = new HashSet<>();
sortedNodes = new ArrayList<>();
for (int i = 0; i < sortedNodesPath.size(); i++) {
Node n = sortedNodesPath.get(i);
if (i < sortedNodesPath.size()-1) {
if (sortedNodesPath.get(i+1).getCoor().equals(n.getCoor())) {
removedNodes.add(n);
for (Way w : ways)
w.removeNode(n);
continue;
}
}
if (!removedNodes.contains(n)) {
sortedNodes.add(n);
}
}
// Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way, but I'm starting to get sleepy, so I do this for now.
Way refWay = ways.get(refWayIndex);
boolean refWayReversed = true;
for (int i = 0; i < sortedNodes.size() - 1; i++) {
if (sortedNodes.get(i) == refWay.firstNode() && sortedNodes.get(i + 1) == refWay.getNode(1)) {
refWayReversed = false;
break;
}
}
if (refWayReversed) {
Collections.reverse(sortedNodes); // need to keep the orientation of the reference way.
}
// Initialize the required parameters. (segment normals, etc.)
nodeCount = sortedNodes.size();
pts = new EastNorth[nodeCount];
normals = new EastNorth[nodeCount - 1];
int i = 0;
for (Node n : sortedNodes) {
EastNorth t = n.getEastNorth();
pts[i] = t;
i++;
}
for (i = 0; i < nodeCount - 1; i++) {
double dx = pts[i + 1].getX() - pts[i].getX();