Changeset 15336 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-09-05T07:43:50+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r15335 r15336 15 15 import java.util.List; 16 16 import java.util.Map; 17 import java.util.Map.Entry; 17 18 import java.util.Set; 18 19 … … 33 34 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 35 import org.openstreetmap.josm.spi.preferences.Config; 35 import org.openstreetmap.josm.tools.Logging;36 36 37 37 /** … … 200 200 } 201 201 202 protected Map<Node, Way> getWayEndNodesNearOtherHighway() {203 Map<Node, Way> map = new HashMap<>();202 protected Map<Node, MyWaySegment> getWayEndNodesNearOtherHighway() { 203 Map<Node, MyWaySegment> map = new HashMap<>(); 204 204 for (MyWaySegment s : waySegments) { 205 205 if (isCanceled()) { … … 217 217 // to handle intersections of 't' shapes and similar 218 218 if (!en.isConnectedTo(s.w.getNodes(), 3 /* hops */, null)) { 219 map.put(en, s.w);219 addIfNewOrCloser(map, en, s); 220 220 } 221 221 } … … 224 224 } 225 225 226 protected Map<Node, Way> getWayEndNodesNearOtherWay() {227 Map<Node, Way> map = new HashMap<>();226 protected Map<Node, MyWaySegment> getWayEndNodesNearOtherWay() { 227 Map<Node, MyWaySegment> map = new HashMap<>(); 228 228 for (MyWaySegment s : waySegments) { 229 229 if (isCanceled()) { … … 234 234 for (Node en : s.nearbyNodes(mindist)) { 235 235 if (!en.isConnectedTo(s.w.getNodes(), 3 /* hops */, null)) { 236 map.put(en, s.w);236 addIfNewOrCloser(map, en, s); 237 237 } 238 238 } … … 242 242 } 243 243 244 protected Map<Node, Way> getWayNodesNearOtherWay() {245 Map<Node, Way> map = new HashMap<>();244 protected Map<Node, MyWaySegment> getWayNodesNearOtherWay() { 245 Map<Node, MyWaySegment> map = new HashMap<>(); 246 246 for (MyWaySegment s : waySegments) { 247 247 if (isCanceled()) { … … 251 251 for (Node en : s.nearbyNodes(minmiddledist)) { 252 252 if (!en.isConnectedTo(s.w.getNodes(), 3 /* hops */, null)) { 253 map.put(en, s.w);253 addIfNewOrCloser(map, en, s); 254 254 } 255 255 } … … 258 258 } 259 259 260 protected final void addErrors(Severity severity, Map<Node, Way> errorMap, String message) { 261 for (Map.Entry<Node, Way> error : errorMap.entrySet()) { 260 private void addIfNewOrCloser(Map<Node, MyWaySegment> map, Node node, MyWaySegment ws) { 261 MyWaySegment old = map.get(node); 262 if (old != null) { 263 double d1 = ws.getDist(node); 264 double d2 = old.getDist(node); 265 if (d1 > d2) { 266 // keep old value 267 return; 268 } 269 } 270 map.put(node, ws); 271 } 272 273 protected final void addErrors(Severity severity, Map<Node, MyWaySegment> errorMap, String message) { 274 for (Entry<Node, MyWaySegment> error : errorMap.entrySet()) { 262 275 Node node = error.getKey(); 263 Way way= error.getValue();264 if (partialSelection && !nodesToTest.contains(node) && !waysToTest.contains(w ay))276 MyWaySegment ws = error.getValue(); 277 if (partialSelection && !nodesToTest.contains(node) && !waysToTest.contains(ws.w)) 265 278 continue; 266 279 errors.add(TestError.builder(this, severity, code) 267 280 .message(message) 268 .primitives(node, w ay)281 .primitives(node, ws.w) 269 282 .highlight(node) 270 283 .build()); … … 328 341 } 329 342 330 public boolean nearby(Node n, double dist) { 331 if (w == null) { 332 Logging.debug("way null"); 333 return false; 334 } 343 double getDist(Node n) { 344 EastNorth coord = n.getEastNorth(); 345 if (coord == null) 346 return Double.NaN; 347 EastNorth en1 = n1.getEastNorth(); 348 EastNorth en2 = n2.getEastNorth(); 349 return Line2D.ptSegDist(en1.getX(), en1.getY(), en2.getX(), en2.getY(), coord.getX(), coord.getY()); 350 351 } 352 353 boolean nearby(Node n, double dist) { 335 354 if (w.containsNode(n)) 336 355 return false; 337 356 if (n.isKeyTrue("noexit")) 338 357 return false; 339 EastNorth coord = n.getEastNorth(); 340 if (coord == null) 341 return false; 342 EastNorth en1 = n1.getEastNorth(); 343 EastNorth en2 = n2.getEastNorth(); 344 return Line2D.ptSegDist(en1.getX(), en1.getY(), en2.getX(), en2.getY(), coord.getX(), coord.getY()) < dist; 345 } 346 347 public BBox getBounds(double fudge) { 358 double d = getDist(n); 359 return !Double.isNaN(d) && d < dist; 360 } 361 362 BBox getBounds(double fudge) { 348 363 double x1 = n1.getCoor().lon(); 349 364 double x2 = n2.getCoor().lon(); … … 365 380 } 366 381 367 publicCollection<Node> nearbyNodes(double dist) {382 Collection<Node> nearbyNodes(double dist) { 368 383 /* 369 384 * We know that any point near the line segment must be at
Note:
See TracChangeset
for help on using the changeset viewer.