Ticket #20121: 20121.patch

File 20121.patch, 5.4 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

     
    111111
    112112        @Override
    113113        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
    114             if (w1 == w2)
    115                 return false;
    116             if (areLayerOrLevelDifferent(w1, w2)) {
     114            if (areLayerOrLevelDifferent(w1, w2))
    117115                return true;
    118             }
    119116            if (isBuilding(w1) && isBuilding(w2))
    120                 return true;
    121             if (w1.hasKey(HIGHWAY) && w2.hasKey(HIGHWAY) && !Objects.equals(w1.get("level"), w2.get("level"))) {
    122                 return true;
    123             }
     117                return true; // handled by mapcss tests
    124118            if (((isResidentialArea(w1) || w1.hasKey(BARRIER, HIGHWAY, RAILWAY, WATERWAY)) && isResidentialArea(w2))
    125119             || ((isResidentialArea(w2) || w2.hasKey(BARRIER, HIGHWAY, RAILWAY, WATERWAY)) && isResidentialArea(w1)))
    126120                return true;
    127             if (isSubwayOrTramOrRazed(w2)) {
    128                 return true;
    129             }
    130             if (isCoastline(w1) != isCoastline(w2)) {
    131                 return true;
    132             }
    133             if ((w1.hasTag(WATERWAY, "river", "stream", "canal", "drain", "ditch") && w2.hasTag(WATERWAY, "riverbank"))
    134              || (w2.hasTag(WATERWAY, "river", "stream", "canal", "drain", "ditch") && w1.hasTag(WATERWAY, "riverbank"))) {
    135                 return true;
    136             }
    137             return isProposedOrAbandoned(w2);
     121            if (isWaterArea(w1) && isWaterArea(w2))
     122                return true; // handled by mapcss tests
     123            return (w1.hasTag(WATERWAY, "river", "stream", "canal", "drain", "ditch") && w2.hasTag(WATERWAY, "riverbank"))
     124                    || (w2.hasTag(WATERWAY, "river", "stream", "canal", "drain", "ditch") && w1.hasTag(WATERWAY, "riverbank"));
    138125        }
    139126
    140127        @Override
     
    269256    }
    270257
    271258    /**
    272      * Self crossing ways test (for all the rest)
     259     * Self crossing ways test (for all ways)
    273260     */
    274261    public static class SelfCrossing extends CrossingWays {
    275262
    276263        protected static final int CROSSING_SELF = 604;
    277264
    278         CrossingWays.Ways normalTest = new Ways();
    279         CrossingWays.Boundaries boundariesTest = new Boundaries();
    280 
    281265        /**
    282266         * Constructs a new SelfIntersection test.
    283267         */
     
    286270        }
    287271
    288272        @Override
    289         public boolean isPrimitiveUsable(OsmPrimitive p) {
    290             return super.isPrimitiveUsable(p) && !(normalTest.isPrimitiveUsable(p)
    291                     || boundariesTest.isPrimitiveUsable(p));
    292         }
    293 
    294         @Override
    295273        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
    296274            return w1 != w2; // should not happen
    297275        }
     
    327305        return w.hasTag("natural", "water", "coastline") || w.hasTag(LANDUSE, "reservoir");
    328306    }
    329307
     308    static boolean isWaterArea(OsmPrimitive w) {
     309        return w.hasTag("natural", "water") || w.hasTag(LANDUSE, "reservoir");
     310    }
     311
    330312    static boolean isHighway(OsmPrimitive w) {
    331313        return w.hasTagDifferent(HIGHWAY, "rest_area", "services", "bus_stop", "platform");
    332314    }
     
    353335
    354336    @Override
    355337    public void visit(Way w) {
    356         if (this instanceof SelfCrossing) {
     338        boolean findSelfCrossingOnly = this instanceof SelfCrossing;
     339        if (findSelfCrossingOnly) {
    357340            // free memory, we are not interested in previous ways
    358341            cellSegments.clear();
    359342            seenWays.clear();
     
    373356                    List<Way> prims;
    374357                    List<WaySegment> highlight;
    375358
    376                     if (!es1.intersects(es2) || ignoreWaySegmentCombination(es1.way, es2.way)) {
     359                    if (!es1.intersects(es2)
     360                            || (!findSelfCrossingOnly && ignoreWaySegmentCombination(es1.way, es2.way))) {
    377361                        continue;
    378362                    }
    379363
  • test/unit/org/openstreetmap/josm/data/validation/tests/CrossingWaysTest.java

     
    88import java.util.HashMap;
    99import java.util.List;
    1010
     11import org.junit.jupiter.api.Test;
    1112import org.junit.jupiter.api.extension.RegisterExtension;
    12 import org.junit.jupiter.api.Test;
    1313import org.openstreetmap.josm.TestUtils;
    1414import org.openstreetmap.josm.data.coor.EastNorth;
    1515import org.openstreetmap.josm.data.coor.LatLon;
     
    173173    void testSelfCrossing() {
    174174        SelfCrossing test = new CrossingWays.SelfCrossing();
    175175        // isPrimitiveUsable
    176         assertFalse(test.isPrimitiveUsable(newUsableWay("highway=motorway")));
    177         assertFalse(test.isPrimitiveUsable(newUsableWay("barrier=yes")));
    178         assertFalse(test.isPrimitiveUsable(newUsableWay("boundary=administrative")));
    179176        assertFalse(test.isPrimitiveUsable(TestUtils.newWay("amenity=restaurant"))); // Unusable (0 node)
    180         assertTrue(test.isPrimitiveUsable(newUsableWay("amenity=restaurant"))); // Usable (2 nodes)
    181177    }
    182178}