Ticket #20057: 20057-beta.patch
| File 20057-beta.patch, 9.0 KB (added by , 6 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
241 241 minmiddledist = Config.getPref().getDouble(PREFIX + ".way_way_distance", 0.0); 242 242 ds = OsmDataManager.getInstance().getActiveDataSet(); 243 243 dsArea = ds == null ? null : ds.getDataSourceArea(); 244 maxLen = DETOUR_FACTOR * mindist; 244 245 } 245 246 246 247 protected Map<Node, MyWaySegment> getHighwayEndNodesNearOtherHighway() { … … 350 351 Node node = error.getKey(); 351 352 MyWaySegment ws = error.getValue(); 352 353 errors.add(TestError.builder(this, severity, code) 353 .message( message)354 .message(this.name, message) 354 355 .primitives(node, ws.w) 355 356 .highlight(node) 356 357 .build()); … … 371 372 } 372 373 fillSearchNodes(endnodes); 373 374 if (!searchNodes.isEmpty()) { 374 maxLen = DETOUR_FACTOR * mindist;375 375 if (isHighwayTest) { 376 addErrors(Severity.WARNING, getHighwayEndNodesNearOtherHighway(), tr("Way end node near other highway"));376 addErrors(Severity.WARNING, getHighwayEndNodesNearOtherHighway(), tr("Way end node near other way")); 377 377 } else { 378 378 addErrors(Severity.WARNING, getWayEndNodesNearOtherWay(), tr("Way end node near other way")); 379 379 } … … 382 382 /* the following two should use a shorter distance */ 383 383 boolean includeOther = isBeforeUpload ? ValidatorPrefHelper.PREF_OTHER_UPLOAD.get() : ValidatorPrefHelper.PREF_OTHER.get(); 384 384 if (minmiddledist > 0.0 && includeOther) { 385 maxLen = DETOUR_FACTOR * minmiddledist;386 385 fillSearchNodes(middlenodes); 387 386 addErrors(Severity.OTHER, getWayNodesNearOtherWay(), tr("Way node near other way")); 388 387 fillSearchNodes(othernodes); … … 415 414 private final Node n2; 416 415 private final boolean concernsArea; 417 416 418 MyWaySegment(Way w, Node n1, Node n2, boolean concer sArea) {417 MyWaySegment(Way w, Node n1, Node n2, boolean concernsArea) { 419 418 this.w = w; 420 419 this.n1 = n1; 421 420 this.n2 = n2; 422 this.concernsArea = concer sArea;421 this.concernsArea = concernsArea; 423 422 } 424 423 425 424 /** … … 444 443 return false; 445 444 } 446 445 if (n1 == node || n2 == node) { 447 Node uncon= visited.iterator().next();448 LatLon cl = ProjectionRegistry.getProjection().eastNorth2latlon(calcClosest( uncon));446 Node startNode = visited.iterator().next(); 447 LatLon cl = ProjectionRegistry.getProjection().eastNorth2latlon(calcClosest(startNode)); 449 448 // calculate real detour length, closest point might be somewhere between n1 and n2 450 449 double detourLen = len + node.getCoor().greatCircleDistance(cl); 451 450 if (detourLen > maxLen) 452 451 return false; 453 // see #17914: flag also nodes which are very close 454 double directDist = getDist(uncon); 455 if (directDist <= 0.1) 452 if (!endnodes.contains(startNode)) 453 return true; 454 // see #17914: flag also unconnected nodes which are very close 455 double directDist = getDist(startNode); 456 if (directDist <= 0.1) { 456 457 return false; 458 } 457 459 return directDist > 0.5 || (visited.size() == 2 && directDist * 1.5 > detourLen); 458 460 } 459 if (visited != null) {460 visited.add(node);461 List<Way> wantedParents = node.getParentWays().stream().filter(pw -> isWantedWay(pw))462 .collect(Collectors.toList());463 if ( wantedParents.size() > 1 && wantedParents.indexOf(parent)!= wantedParents.size() - 1) {461 List<Way> wantedParents = node.getParentWays().stream().filter(UnconnectedWays.this::isWantedWay) 462 .collect(Collectors.toList()); 463 if (wantedParents.size() > 1) { 464 int posWanted = wantedParents.indexOf(parent); 465 if (posWanted >= 0 && posWanted != wantedParents.size() - 1) { 464 466 // we want to find a different way. so move known way to the end of the list 465 467 wantedParents.remove(parent); 466 468 wantedParents.add(parent); 467 469 } 468 469 for (final Way way : wantedParents) { 470 List<Node> nextNodes = new ArrayList<>(); 471 int pos = way.getNodes().indexOf(node); 472 if (pos > 0) { 473 nextNodes.add(way.getNode(pos - 1)); 470 } 471 for (final Way way : wantedParents) { 472 if (len == 0) 473 visited.clear(); // first node might not be an end node 474 visited.add(node); 475 List<Node> nextNodes = new ArrayList<>(); 476 int pos = way.getNodes().indexOf(node); 477 if (pos > 0) { 478 nextNodes.add(way.getNode(pos - 1)); 479 } 480 if (pos + 1 < way.getNodesCount()) { 481 nextNodes.add(way.getNode(pos + 1)); 482 } 483 for (Node next : nextNodes) { 484 final boolean containsN = visited.contains(next); 485 visited.add(next); 486 if (!containsN && isConnectedTo(next, visited, 487 len + node.getCoor().greatCircleDistance(next.getCoor()), way)) { 488 return true; 474 489 } 475 if (pos + 1 < way.getNodesCount()) {476 nextNodes.add(way.getNode(pos + 1));477 }478 for (Node next : nextNodes) {479 final boolean containsN = visited.contains(next);480 visited.add(next);481 if (!containsN && isConnectedTo(next, visited,482 len + node.getCoor().greatCircleDistance(next.getCoor()), way)) {483 return true;484 }485 }486 490 } 487 491 } 488 492 return false; … … 585 589 return ret; 586 590 587 591 int size = w.getNodesCount(); 592 // TODO: concernsArea probably only useful with waterway=riverbank 588 593 boolean concersArea = w.concernsArea(); 589 594 for (int i = 1; i < size; ++i) { 590 595 if (i < size-1) { -
test/unit/org/openstreetmap/josm/data/validation/tests/UnconnectedWaysTest.java
21 21 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 22 22 import org.openstreetmap.josm.io.IllegalDataException; 23 23 import org.openstreetmap.josm.io.OsmReader; 24 import org.openstreetmap.josm.spi.preferences.Config; 24 25 25 26 /** 26 27 * Unit tests of {@code UnconnectedWays} class. … … 80 81 } 81 82 82 83 /** 83 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/181 36">Bug #18106</a>.84 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/18106">Bug #18106</a>. 84 85 * @throws IOException if any I/O error occurs 85 86 * @throws IllegalDataException if the OSM data cannot be parsed 86 87 * @throws FileNotFoundException if the data file cannot be found … … 138 139 assertThat(bib.getErrors(), isEmpty()); 139 140 } 140 141 } 142 143 /** 144 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20057">Bug #20057</a>. 145 * @throws IOException if any I/O error occurs 146 * @throws IllegalDataException if the OSM data cannot be parsed 147 * @throws FileNotFoundException if the data file cannot be found 148 */ 149 @Test 150 void testTicket20057() throws IOException, IllegalDataException, FileNotFoundException { 151 try (InputStream fis = TestUtils.getRegressionDataStream(20057, "data.osm")) { 152 final DataSet ds = OsmReader.parseDataSet(fis, NullProgressMonitor.INSTANCE); 153 MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, null, null)); 154 Config.getPref().putDouble(UnconnectedWays.PREFIX + ".way_way_distance", 1.0); 155 Config.getPref().putBoolean("validator.other", true); 156 bib.startTest(null); 157 bib.setBeforeUpload(false); 158 bib.visit(ds.allPrimitives()); 159 bib.endTest(); 160 assertThat(bib.getErrors(), isEmpty()); 161 } 162 } 141 163 }
