@@ -155,7 +155,7 @@ private static Collection<WaySegment> createSegments(Map<Node, List<Node>> graph
155
155
intersect .retainAll (mWays );
156
156
157
157
for (Way w : intersect ) {
158
- if (w . getNeighbours ( n ). contains ( m ) && getNodeIndex ( w , n ) + 1 == getNodeIndex ( w , m )) {
158
+ if (isConsecutive ( w , n , m )) {
159
159
segments .add (WaySegment .forNodePair (w , n , m ));
160
160
}
161
161
}
@@ -166,20 +166,21 @@ private static Collection<WaySegment> createSegments(Map<Node, List<Node>> graph
166
166
}
167
167
168
168
/**
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.
170
170
*
171
171
* @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
174
175
*/
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 ;
179
180
}
180
181
}
181
182
182
- return - 1 ;
183
+ return false ;
183
184
}
184
185
185
186
/**
@@ -237,6 +238,12 @@ private Collection<Way> buildGraph(Way way) {
237
238
}
238
239
}
239
240
}
241
+
242
+ // case for single, non-connected waterways
243
+ if (graph .isEmpty ()) {
244
+ graph .add (way );
245
+ }
246
+
240
247
return graph ;
241
248
}
242
249
}
0 commit comments