Changeset 15458 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2019-10-16T09:32:07+02:00 (5 years ago)
Author:
GerdP
Message:

fix #18228: drastically improve performance of test "Unconnected highways" when long barriers are involved
Test 'Unconnected highways' completed in 25 ms
instead of
Test 'Unconnected highways' completed in 2.3 s
for example attached to #18228.

File:
1 edited

Legend:

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

    r15407 r15458  
    1313import java.util.HashMap;
    1414import java.util.HashSet;
     15import java.util.Iterator;
    1516import java.util.List;
    1617import java.util.Map;
     
    536537
    537538        private boolean barrierBetween(Node endnode) {
    538             EastNorth closest = Geometry.closestPointToSegment(n1.getEastNorth(), n2.getEastNorth(), endnode.getEastNorth());
    539             Node x = new Node();
    540             x.setEastNorth(closest);
     539            EastNorth en = endnode.getEastNorth();
     540            EastNorth closest = Geometry.closestPointToSegment(n1.getEastNorth(), n2.getEastNorth(), en);
     541            Node x = new Node(closest);
    541542            BBox bbox = new BBox(endnode.getCoor(), x.getCoor());
    542             for (Way nearbyWay: ds.searchWays(bbox)) {
    543                 if (nearbyWay != w && nearbyWay.isUsable() && nearbyWay.hasTag("barrier") && !endnode.getParentWays().contains(nearbyWay)) {
    544                     //make sure that the barrier is really between the two nodes, not just close to them
    545                     Way directWay = new Way();
    546                     directWay.addNode(endnode);
    547                     directWay.addNode(x);
    548                     if (!Geometry.addIntersections(Arrays.asList(nearbyWay, directWay), true, new ArrayList<>()).isEmpty())
    549                         return true;
     543            for (Way nearbyWay : ds.searchWays(bbox)) {
     544                if (nearbyWay != w && nearbyWay.isUsable() && nearbyWay.hasTag("barrier")
     545                        && !endnode.getParentWays().contains(nearbyWay)) {
     546                    //make sure that the barrier is really between endnode and the highway segment, not just close to or around them
     547                    Iterator<Node> iter = nearbyWay.getNodes().iterator();
     548                    EastNorth prev = iter.next().getEastNorth();
     549                    while (iter.hasNext()) {
     550                        EastNorth curr = iter.next().getEastNorth();
     551                        if (Geometry.getSegmentSegmentIntersection(closest, en, prev, curr) != null) {
     552                            return true;
     553                        }
     554                        prev = curr;
     555                    }
    550556                }
    551557            }
Note: See TracChangeset for help on using the changeset viewer.