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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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<>();
Note: See TracChangeset for help on using the changeset viewer.