Skip to content

Commit 5b3f5f4

Browse files
committed
Fix error highlight for self-intersecting ways
1 parent bf33e49 commit 5b3f5f4

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/org/openstreetmap/josm/data/osm/WaySegment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package org.openstreetmap.josm.data.osm;
33

44
/**
5-
* A segment consisting of 2 consecutive nodes out of a way.
5+
* A segment consisting of two consecutive nodes out of a way.
66
*/
77
public final class WaySegment extends IWaySegment<Node, Way> {
88

@@ -36,7 +36,7 @@ public static WaySegment forNodePair(Way way, Node first, Node second) {
3636
}
3737
endIndex--;
3838
}
39-
throw new IllegalArgumentException("Node pair is not part of way!");
39+
throw new IllegalArgumentException("The node pair is not consecutive part of the way!");
4040
}
4141

4242
/**

src/org/openstreetmap/josm/data/validation/tests/CycleDetector.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static Collection<WaySegment> createSegments(Map<Node, List<Node>> graph
155155
intersect.retainAll(mWays);
156156

157157
for (Way w : intersect) {
158-
if (w.getNeighbours(n).contains(m) && getNodeIndex(w, n) + 1 == getNodeIndex(w, m)) {
158+
if (isConsecutive(w, n, m)) {
159159
segments.add(WaySegment.forNodePair(w, n, m));
160160
}
161161
}
@@ -166,20 +166,21 @@ private static Collection<WaySegment> createSegments(Map<Node, List<Node>> graph
166166
}
167167

168168
/**
169-
* Returns the way index of a node. Only the first occurrence is considered in case it's a closed way.
169+
* Returns the way index of a node. Only the first occurrence is considered in case it's a closed or self-intersecting way.
170170
*
171171
* @param w parent way
172-
* @param n the node to look up
173-
* @return {@code >=0} if the node is found or<br>{@code -1} if node not part of the way
172+
* @param n the first node to look up
173+
* @param m the second, possibly consecutive node
174+
* @return {@code true} if the nodes are consecutive order in the way direction
174175
*/
175-
private static int getNodeIndex(Way w, Node n) {
176-
for (int i = 0; i < w.getNodesCount(); i++) {
177-
if (w.getNode(i).equals(n)) {
178-
return i;
176+
private static boolean isConsecutive(Way w, Node n, Node m) {
177+
for (int i = 0; i < w.getNodesCount() - 1; i++) {
178+
if (w.getNode(i).equals(n) && w.getNode(i + 1).equals(m)) {
179+
return true;
179180
}
180181
}
181182

182-
return -1;
183+
return false;
183184
}
184185

185186
/**
@@ -237,6 +238,12 @@ private Collection<Way> buildGraph(Way way) {
237238
}
238239
}
239240
}
241+
242+
// case for single, non-connected waterways
243+
if (graph.isEmpty()) {
244+
graph.add(way);
245+
}
246+
240247
return graph;
241248
}
242249
}

0 commit comments

Comments
 (0)