Skip to content

Commit

Permalink
Store coordinate in Node
Browse files Browse the repository at this point in the history
  • Loading branch information
wipfli committed Nov 22, 2024
1 parent 60a3c1c commit b7cb952
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ private void buildNodes(List<List<Coordinate>> 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);
}

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);
}
Expand Down Expand Up @@ -456,6 +456,11 @@ private List<List<Coordinate>> nodeLines(List<LineString> input) {
private class Node {
final int id = nodes++;
final List<Edge> edge = new ArrayList<>();
Coordinate coordinate;

public Node(Coordinate coordinate) {
this.coordinate = coordinate;
}

void addEdge(Edge edge) {
for (Edge other : this.edge) {
Expand All @@ -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);
}
}

Expand Down

0 comments on commit b7cb952

Please sign in to comment.