Ticket #16942: 16942-v2.patch

File 16942-v2.patch, 3.9 KB (added by GerdP, 4 months ago)
• src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

 if (wayMap.isEmpty()) return; Set sharedNodes = findIntersectionNodes(r); Set sharedNodes = new HashSet<>(); Set intersectionWays = new HashSet<>(); findIntersectionNodes(r, sharedNodes, intersectionWays); List innerPolygons = polygon.getInnerPolygons(); List outerPolygons = polygon.getOuterPolygons(); List allPolygons = new ArrayList<>(); allPolygons.addAll(outerPolygons); allPolygons.addAll(innerPolygons); Map> crossingPolyMap = findIntersectingWays(r, innerPolygons, outerPolygons); if (!sharedNodes.isEmpty()) { for (int i = 0; i < allPolygons.size(); i++) { PolyData pd1 = allPolygons.get(i); checkPolygonForSelfIntersection(r, pd1); // check if this ring has a way that is known to intersect with another way if (!hasIntersectionWay(pd1, intersectionWays)) continue; for (int j = i + 1; j < allPolygons.size(); j++) { PolyData pd2 = allPolygons.get(j); if (!checkProblemMap(crossingPolyMap, pd1, pd2)) { checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes); if (hasIntersectionWay(pd2, intersectionWays)) checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes); } } } } /** * Simple check if given ring contains way that is known to intersect. * @param pd the ring * @param intersectionWays the known intersection ways * @return true if one or more ways are in the set of known ways */ private boolean hasIntersectionWay(PolyData pd, Set intersectionWays) { for (Way w : intersectionWays) { if (pd.getWayIds().contains(w.getUniqueId())){ return true; } } return false; } /** * Check if a polygon ring is self-intersecting when the ring was build from multiple ways. * An self intersection in a single way is checked in {@link SelfIntersectingWay}. * @param r the relation * Detect intersections of multipolygon ways at nodes. If any way node is used by more than two ways * or two times in one way and at least once in another way we found an intersection. * @param r the relation * @return List of nodes were ways intersect * @param sharedNodes We be filled with shared nodes * @param intersectionWays We be filled with ways that have a shared node */ private static Set findIntersectionNodes(Relation r) { Set intersectionNodes = new HashSet<>(); private static void findIntersectionNodes(Relation r, Set sharedNodes, Set intersectionWays) { Map> nodeMap = new HashMap<>(); for (RelationMember rm : r.getMembers()) { if (!rm.isWay()) } ways.add(rm.getWay()); if (ways.size() > 2 || (ways.size() == 2 && i != 0 && i + 1 != numNodes)) { intersectionNodes.add(n); sharedNodes.add(n); intersectionWays.addAll(ways); } } } return intersectionNodes; } private enum ExtPolygonIntersection {