Changeset 6556 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r6491 r6556 8 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 9 9 import org.openstreetmap.josm.data.projection.Projections; 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 11 import org.openstreetmap.josm.tools.Predicate; 12 import org.openstreetmap.josm.tools.Utils; 13 14 import java.util.Collection; 15 import java.util.Set; 16 import java.util.TreeSet; 10 17 11 18 /** … … 337 344 return false; 338 345 } 346 347 /** 348 * Tests whether {@code this} node is connected to {@code otherNode} via at most {@code hops} nodes 349 * matching the {@code predicate} (which may be {@code null} to consider all nodes). 350 */ 351 public boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate) { 352 CheckParameterUtil.ensureParameterNotNull(otherNodes); 353 CheckParameterUtil.ensureThat(!otherNodes.isEmpty(), "otherNodes must not be empty!"); 354 CheckParameterUtil.ensureThat(hops >= 0, "hops must be non-negative!"); 355 return hops == 0 356 ? isConnectedTo(otherNodes, hops, predicate, null) 357 : isConnectedTo(otherNodes, hops, predicate, new TreeSet<Node>()); 358 } 359 360 private boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate, Set<Node> visited) { 361 if (otherNodes.contains(this)) { 362 return true; 363 } 364 if (hops > 0) { 365 visited.add(this); 366 for (final Way w : Utils.filteredCollection(this.getReferrers(), Way.class)) { 367 for (final Node n : w.getNodes()) { 368 final boolean containsN = visited.contains(n); 369 visited.add(n); 370 if (!containsN && (predicate == null || predicate.evaluate(n)) && n.isConnectedTo(otherNodes, hops - 1, predicate, visited)) { 371 return true; 372 } 373 } 374 } 375 } 376 return false; 377 } 339 378 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r6552 r6556 114 114 mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0); 115 115 minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0); 116 dsArea = Main.main .getCurrentDataSet().getDataSourceArea();116 dsArea = Main.main == null || !Main.main.hasEditLayer() ? null : Main.main.getCurrentDataSet().getDataSourceArea(); 117 117 } 118 118 … … 135 135 continue; 136 136 } 137 // There's a small false-positive here. Imagine an intersection 138 // like a 't'. If the top part of the 't' is short enough, it 139 // will trigger the node at the very top of the 't' to be unconnected 140 // to the way that "crosses" the 't'. We should probably check that 141 // the ways to which 'en' belongs are not connected to 's.w'. 137 // to handle intersections of 't' shapes and similar 138 if (en.isConnectedTo(s.w.getNodes(), 3 /* hops */, null)) { 139 continue; 140 } 142 141 map.put(en, s.w); 143 142 }
Note:
See TracChangeset
for help on using the changeset viewer.