Changeset 11136 in josm for trunk/src/org


Ignore:
Timestamp:
2016-10-16T23:29:37+02:00 (8 years ago)
Author:
bastiK
Message:

applied #13086 - Detect all self-intersecting ways (patch by Gerd Petermann)

Location:
trunk/src/org/openstreetmap/josm/data/validation
Files:
3 edited

Legend:

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

    r11100 r11136  
    105105        CrossingWays.Boundaries.class, // ID  601 ..  699
    106106        CrossingWays.Barrier.class, // ID  601 ..  699
     107        CrossingWays.SelfCrossing.class, // ID  601 ..  699
    107108        SimilarNamedWays.class, // ID  701 ..  799
    108109        Coastlines.class, // ID  901 ..  999
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r11129 r11136  
    66import java.awt.geom.Point2D;
    77import java.util.ArrayList;
    8 import java.util.Arrays;
    98import java.util.HashMap;
    109import java.util.List;
     
    6766        @Override
    6867        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
     68            if (w1 == w2)
     69                return false;
    6970            if (!Objects.equals(getLayer(w1), getLayer(w2))) {
    7071                return true;
     
    172173
    173174    /**
     175     * Self crossing ways test (for all the rest)
     176     */
     177    public static class SelfCrossing extends CrossingWays {
     178        CrossingWays.Ways normalTest = new Ways();
     179        CrossingWays.Barrier barrierTest = new Barrier();
     180        CrossingWays.Boundaries boundariesTest = new Boundaries();
     181
     182        /**
     183         * Constructs a new SelfIntersection test.
     184         */
     185        public SelfCrossing() {
     186            super(tr("Self crossing"));
     187        }
     188
     189        @Override
     190        public boolean isPrimitiveUsable(OsmPrimitive p) {
     191            return super.isPrimitiveUsable(p) && !(normalTest.isPrimitiveUsable(p) || barrierTest.isPrimitiveUsable(p)
     192                    || boundariesTest.isPrimitiveUsable(p));
     193        }
     194
     195        @Override
     196        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
     197            return (w1 != w2); // should not happen
     198        }
     199
     200        @Override
     201        String createMessage(Way w1, Way w2) {
     202            return tr("Self-crossing ways");
     203        }
     204    }
     205
     206    /**
    174207     * Constructs a new {@code CrossingWays} test.
    175208     * @param title The test title
     
    221254    @Override
    222255    public void visit(Way w) {
     256        if (this instanceof SelfCrossing) {
     257            // free memory, we are not interested in previous ways
     258            cellSegments.clear();
     259            seenWays.clear();
     260        }
    223261
    224262        int nodesSize = w.getNodesCount();
     
    231269                continue;
    232270            }
    233             for (List<WaySegment> segments : getSegments(en1, en2)) {
     271            for (List<WaySegment> segments : getSegments(cellSegments, en1, en2)) {
    234272                for (WaySegment es2 : segments) {
    235273                    List<Way> prims;
     
    240278                    }
    241279
    242                     prims = Arrays.asList(es1.way, es2.way);
     280                    prims = new ArrayList<>();
     281                    prims.add(es1.way);
     282                    if (es1.way != es2.way)
     283                        prims.add(es2.way);
    243284                    if ((highlight = seenWays.get(prims)) == null) {
    244285                        highlight = new ArrayList<>();
     
    266307     * Returns all the cells this segment crosses.  Each cell contains the list
    267308     * of segments already processed
    268      *
     309     * @param cellSegments map with already collected way segments
    269310     * @param n1 The first EastNorth
    270311     * @param n2 The second EastNorth
    271312     * @return A list with all the cells the segment crosses
    272313     */
    273     private List<List<WaySegment>> getSegments(EastNorth n1, EastNorth n2) {
     314    public static List<List<WaySegment>> getSegments(Map<Point2D, List<WaySegment>> cellSegments, EastNorth n1, EastNorth n2) {
    274315
    275316        List<List<WaySegment>> cells = new ArrayList<>();
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java

    r11129 r11136  
    3232    public void visit(Way w) {
    3333        Set<Node> nodes = new HashSet<>();
    34 
    35         for (int i = 1; i < w.getNodesCount() - 1; i++) {
     34        int last = w.getNodesCount();
     35        if (last < 2)
     36            return;
     37        if (w.firstNode() == w.lastNode())
     38            last--; // closed way, ignore last node
     39        nodes.add(w.firstNode());
     40        for (int i = 1; i < last; i++) {
    3641            Node n = w.getNode(i);
    3742            if (nodes.contains(n)) {
Note: See TracChangeset for help on using the changeset viewer.