| 1 | package org.openstreetmap.josm.data.validation.tests;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.util.Collection;
|
|---|
| 6 | import java.util.Collections;
|
|---|
| 7 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 8 | import org.openstreetmap.josm.data.osm.QuadBuckets;
|
|---|
| 9 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 10 | import org.openstreetmap.josm.data.validation.Severity;
|
|---|
| 11 | import org.openstreetmap.josm.data.validation.Test;
|
|---|
| 12 | import org.openstreetmap.josm.data.validation.TestError;
|
|---|
| 13 | import org.openstreetmap.josm.gui.mappaint.AreaElemStyle;
|
|---|
| 14 | import org.openstreetmap.josm.gui.mappaint.ElemStyle;
|
|---|
| 15 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
|---|
| 16 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
|---|
| 17 | import org.openstreetmap.josm.tools.Geometry;
|
|---|
| 18 | import org.openstreetmap.josm.tools.Predicate;
|
|---|
| 19 | import org.openstreetmap.josm.tools.Utils;
|
|---|
| 20 |
|
|---|
| 21 | public class OverlappingAreas extends Test {
|
|---|
| 22 |
|
|---|
| 23 | protected static int OVERLAPPING_AREAS = 2201;
|
|---|
| 24 | protected QuadBuckets<Way> index = new QuadBuckets<Way>();
|
|---|
| 25 | private static ElemStyles styles = MapPaintStyles.getStyles();
|
|---|
| 26 |
|
|---|
| 27 | public OverlappingAreas() {
|
|---|
| 28 | super(tr("Overlapping Areas"));
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | @Override
|
|---|
| 32 | public void visit(Way w) {
|
|---|
| 33 | if (w.isUsable() && w.isClosed() && hasAreaElemStyle(w)) {
|
|---|
| 34 | index.add(w);
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | @Override
|
|---|
| 39 | public void endTest() {
|
|---|
| 40 | for (final Way w : index) {
|
|---|
| 41 | Collection<Way> overlaps = Utils.filter(
|
|---|
| 42 | index.search(w.getBBox()),
|
|---|
| 43 | new Predicate<Way>() {
|
|---|
| 44 |
|
|---|
| 45 | @Override
|
|---|
| 46 | public boolean evaluate(Way wi) {
|
|---|
| 47 | if (w.equals(wi)) {
|
|---|
| 48 | return false;
|
|---|
| 49 | } else {
|
|---|
| 50 | return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
|
|---|
| 51 | == Geometry.PolygonIntersection.CROSSING;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | });
|
|---|
| 55 | if (!overlaps.isEmpty()) {
|
|---|
| 56 | errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"),
|
|---|
| 57 | OVERLAPPING_AREAS, Collections.singletonList(w), overlaps));
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | private boolean hasAreaElemStyle(OsmPrimitive p) {
|
|---|
| 63 | for (ElemStyle s : styles.generateStyles(p, 1.0, null, false).a) {
|
|---|
| 64 | if (s instanceof AreaElemStyle) {
|
|---|
| 65 | return true;
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | return false;
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|