Ticket #16942: 16942-v2.patch

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

     
    265265        if (wayMap.isEmpty())
    266266            return;
    267267
    268         Set<Node> sharedNodes = findIntersectionNodes(r);
     268        Set<Node> sharedNodes = new HashSet<>();
     269        Set<Way> intersectionWays = new HashSet<>();
     270        findIntersectionNodes(r, sharedNodes, intersectionWays);
     271
    269272        List<PolyData> innerPolygons = polygon.getInnerPolygons();
    270273        List<PolyData> outerPolygons = polygon.getOuterPolygons();
    271274        List<PolyData> allPolygons = new ArrayList<>();
    272275        allPolygons.addAll(outerPolygons);
    273276        allPolygons.addAll(innerPolygons);
     277
    274278        Map<PolyData, List<PolyData>> crossingPolyMap = findIntersectingWays(r, innerPolygons, outerPolygons);
    275279
    276280        if (!sharedNodes.isEmpty()) {
     
    277281            for (int i = 0; i < allPolygons.size(); i++) {
    278282                PolyData pd1 = allPolygons.get(i);
    279283                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
    280289                for (int j = i + 1; j < allPolygons.size(); j++) {
    281290                    PolyData pd2 = allPolygons.get(j);
    282291                    if (!checkProblemMap(crossingPolyMap, pd1, pd2)) {
    283                         checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes);
     292                        if (hasIntersectionWay(pd2, intersectionWays))
     293                            checkPolygonsForSharedNodes(r, pd1, pd2, sharedNodes);
    284294                    }
    285295                }
    286296            }
     
    300310    }
    301311
    302312    /**
     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    /**
    303328     * Check if a polygon ring is self-intersecting when the ring was build from multiple ways.
    304329     * An self intersection in a single way is checked in {@link SelfIntersectingWay}.
    305330     * @param r the relation
     
    339364     * Detect intersections of multipolygon ways at nodes. If any way node is used by more than two ways
    340365     * or two times in one way and at least once in another way we found an intersection.
    341366     * @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
    343369     */
    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) {
    346371        Map<Node, List<Way>> nodeMap = new HashMap<>();
    347372        for (RelationMember rm : r.getMembers()) {
    348373            if (!rm.isWay())
     
    360385                }
    361386                ways.add(rm.getWay());
    362387                if (ways.size() > 2 || (ways.size() == 2 && i != 0 && i + 1 != numNodes)) {
    363                     intersectionNodes.add(n);
     388                    sharedNodes.add(n);
     389                    intersectionWays.addAll(ways);
    364390                }
    365391            }
    366392        }
    367         return intersectionNodes;
    368393    }
    369394
    370395    private enum ExtPolygonIntersection {