Changeset 9584 in josm


Ignore:
Timestamp:
2016-01-23T15:35:52+01:00 (3 years ago)
Author:
Don-vip
Message:

fix #12377 - detect intersecting rings in multipolygon validator test

File:
1 edited

Legend:

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

    r9583 r9584  
    2424import org.openstreetmap.josm.data.osm.Way;
    2525import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
     26import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
    2627import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData.Intersection;
    2728import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
     
    300301            primitives.add(r);
    301302            primitives.addAll(openNodes);
    302             addError(r, new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY,
    303                     primitives, openNodes));
     303            addError(r, new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY, primitives, openNodes));
    304304        }
    305305
    306306        // For painting is used Polygon class which works with ints only. For validation we need more precision
    307         List<GeneralPath> outerPolygons = createPolygons(polygon.getOuterPolygons());
    308         for (Multipolygon.PolyData pdInner : polygon.getInnerPolygons()) {
     307        List<PolyData> innerPolygons = polygon.getInnerPolygons();
     308        List<PolyData> outerPolygons = innerPolygons.isEmpty() ? Collections.<PolyData>emptyList() : polygon.getOuterPolygons();
     309        List<GeneralPath> innerPolygonsPaths = innerPolygons.isEmpty() ? Collections.<GeneralPath>emptyList() : createPolygons(innerPolygons);
     310        List<GeneralPath> outerPolygonsPaths = innerPolygons.isEmpty() ? Collections.<GeneralPath>emptyList() : createPolygons(outerPolygons);
     311        for (int i = 0; i < innerPolygons.size(); i++) {
     312            PolyData pdInner = innerPolygons.get(i);
     313            // Check for intersection between inner members
     314            for (int j = i+1; j < innerPolygons.size(); j++) {
     315                checkCrossingWays(r, innerPolygons, innerPolygonsPaths, pdInner, j);
     316            }
     317            // Check for intersection between inner and outer members
    309318            boolean outside = true;
    310             for (int i = 0; i < polygon.getOuterPolygons().size(); i++) {
    311                 Intersection intersection = getPolygonIntersection(outerPolygons.get(i), pdInner.getNodes());
    312                 outside = outside & intersection == Intersection.OUTSIDE;
    313                 if (intersection == Intersection.CROSSING) {
    314                     Multipolygon.PolyData outerWay = polygon.getOuterPolygons().get(i);
    315                     if (outerWay != null) {
    316                         addError(r, new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"),
    317                                 CROSSING_WAYS, Collections.singletonList(r), Arrays.asList(pdInner.getNodes(), outerWay.getNodes())));
    318                     }
    319                 }
     319            for (int o = 0; o < outerPolygons.size(); o++) {
     320                outside &= checkCrossingWays(r, outerPolygons, outerPolygonsPaths, pdInner, o) == Intersection.OUTSIDE;
    320321            }
    321322            if (outside) {
     
    324325            }
    325326        }
     327    }
     328
     329    private Intersection checkCrossingWays(Relation r, List<PolyData> polygons, List<GeneralPath> polygonsPaths, PolyData pd, int idx) {
     330        Intersection intersection = getPolygonIntersection(polygonsPaths.get(idx), pd.getNodes());
     331        if (intersection == Intersection.CROSSING) {
     332            PolyData pdOther = polygons.get(idx);
     333            if (pdOther != null) {
     334                addError(r, new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"),
     335                        CROSSING_WAYS, Collections.singletonList(r), Arrays.asList(pd.getNodes(), pdOther.getNodes())));
     336            }
     337        }
     338        return intersection;
    326339    }
    327340
Note: See TracChangeset for help on using the changeset viewer.