Changeset 14408 in josm for trunk/src


Ignore:
Timestamp:
2018-11-03T12:00:27+01:00 (6 years ago)
Author:
GerdP
Message:

fix #16942 - improve performance of MultipolygonTest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r12941 r14408  
    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();
     
    272275        allPolygons.addAll(outerPolygons);
    273276        allPolygons.addAll(innerPolygons);
     277
    274278        Map<PolyData, List<PolyData>> crossingPolyMap = findIntersectingWays(r, innerPolygons, outerPolygons);
    275279
     
    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                }
     
    298308            checkRoles(r, allPolygons, wayMap, sharedNodes);
    299309        }
     310    }
     311
     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;
    300325    }
    301326
     
    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
    343      */
    344     private static Set<Node> findIntersectionNodes(Relation r) {
    345         Set<Node> intersectionNodes = new HashSet<>();
     367     * @param sharedNodes We be filled with shared nodes
     368     * @param intersectionWays We be filled with ways that have a shared node
     369     */
     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()) {
     
    361386                ways.add(rm.getWay());
    362387                if (ways.size() > 2 || (ways.size() == 2 && i != 0 && i + 1 != numNodes)) {
    363                     intersectionNodes.add(n);
    364                 }
    365             }
    366         }
    367         return intersectionNodes;
     388                    sharedNodes.add(n);
     389                    intersectionWays.addAll(ways);
     390                }
     391            }
     392        }
    368393    }
    369394
Note: See TracChangeset for help on using the changeset viewer.