Ticket #16942: 16942-v2.patch
| File 16942-v2.patch, 3.9 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
265 265 if (wayMap.isEmpty()) 266 266 return; 267 267 268 Set<Node> sharedNodes = findIntersectionNodes(r); 268 Set<Node> sharedNodes = new HashSet<>(); 269 Set<Way> intersectionWays = new HashSet<>(); 270 findIntersectionNodes(r, sharedNodes, intersectionWays); 271 269 272 List<PolyData> innerPolygons = polygon.getInnerPolygons(); 270 273 List<PolyData> outerPolygons = polygon.getOuterPolygons(); 271 274 List<PolyData> allPolygons = new ArrayList<>(); 272 275 allPolygons.addAll(outerPolygons); 273 276 allPolygons.addAll(innerPolygons); 277 274 278 Map<PolyData, List<PolyData>> crossingPolyMap = findIntersectingWays(r, innerPolygons, outerPolygons); 275 279 276 280 if (!sharedNodes.isEmpty()) { … … 277 281 for (int i = 0; i < allPolygons.size(); i++) { 278 282 PolyData pd1 = allPolygons.get(i); 279 283 checkPolygonForSelfIntersection(r, pd1); 284 // check if this ring has a way that is known to intersect with another way 285 286 if (!hasIntersectionWay(pd1, intersectionWays)) 287 continue; 288 280 289 for (int j = i + 1; j < allPolygons.size(); j++) { 281 290 PolyData pd2 = allPolygons.get(j); 282 291 if (!checkProblemMap(crossingPolyMap, pd1, pd2)) { 283 checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes); 292 if (hasIntersectionWay(pd2, intersectionWays)) 293 checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes); 284 294 } 285 295 } 286 296 } … … 300 310 } 301 311 302 312 /** 313 * Simple check if given ring contains way that is known to intersect. 314 * @param pd the ring 315 * @param intersectionWays the known intersection ways 316 * @return true if one or more ways are in the set of known ways 317 */ 318 private boolean hasIntersectionWay(PolyData pd, Set<Way> intersectionWays) { 319 for (Way w : intersectionWays) { 320 if (pd.getWayIds().contains(w.getUniqueId())){ 321 return true; 322 } 323 } 324 return false; 325 } 326 327 /** 303 328 * Check if a polygon ring is self-intersecting when the ring was build from multiple ways. 304 329 * An self intersection in a single way is checked in {@link SelfIntersectingWay}. 305 330 * @param r the relation … … 339 364 * Detect intersections of multipolygon ways at nodes. If any way node is used by more than two ways 340 365 * or two times in one way and at least once in another way we found an intersection. 341 366 * @param r the relation 342 * @return List of nodes were ways intersect 367 * @param sharedNodes We be filled with shared nodes 368 * @param intersectionWays We be filled with ways that have a shared node 343 369 */ 344 private static Set<Node> findIntersectionNodes(Relation r) { 345 Set<Node> intersectionNodes = new HashSet<>(); 370 private static void findIntersectionNodes(Relation r, Set<Node> sharedNodes, Set<Way> intersectionWays) { 346 371 Map<Node, List<Way>> nodeMap = new HashMap<>(); 347 372 for (RelationMember rm : r.getMembers()) { 348 373 if (!rm.isWay()) … … 360 385 } 361 386 ways.add(rm.getWay()); 362 387 if (ways.size() > 2 || (ways.size() == 2 && i != 0 && i + 1 != numNodes)) { 363 intersectionNodes.add(n); 388 sharedNodes.add(n); 389 intersectionWays.addAll(ways); 364 390 } 365 391 } 366 392 } 367 return intersectionNodes;368 393 } 369 394 370 395 private enum ExtPolygonIntersection {
