diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java index 8f5e94c1a7..628c48deaf 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java @@ -392,7 +392,7 @@ private void buildNodes(List> edges) { Coordinate first = coordinateSequence.getFirst(); Node firstNode = nodes.get(first); if (firstNode == null) { - firstNode = new Node(); + firstNode = new Node(first); nodes.put(first, firstNode); output.add(firstNode); } @@ -400,7 +400,7 @@ private void buildNodes(List> edges) { Coordinate last = coordinateSequence.getLast(); Node lastNode = nodes.get(last); if (lastNode == null) { - lastNode = new Node(); + lastNode = new Node(last); nodes.put(last, lastNode); output.add(lastNode); } @@ -456,6 +456,11 @@ private List> nodeLines(List input) { private class Node { final int id = nodes++; final List edge = new ArrayList<>(); + Coordinate coordinate; + + public Node(Coordinate coordinate) { + this.coordinate = coordinate; + } void addEdge(Edge edge) { for (Edge other : this.edge) { @@ -480,12 +485,7 @@ public String toString() { } public double distance(Node end) { - if (!getEdges().isEmpty() && !end.getEdges().isEmpty()) { - Coordinate a = getEdges().getFirst().coordinates.getFirst(); - Coordinate b = end.getEdges().getFirst().coordinates.getFirst(); - return a.distance(b); - } - return Double.POSITIVE_INFINITY; + return coordinate.distance(end.coordinate); } }