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.QuadBuckets;
|
---|
8 | import org.openstreetmap.josm.data.osm.Way;
|
---|
9 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
10 | import org.openstreetmap.josm.data.validation.Test;
|
---|
11 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
13 | import org.openstreetmap.josm.tools.Geometry;
|
---|
14 | import org.openstreetmap.josm.tools.Predicate;
|
---|
15 | import org.openstreetmap.josm.tools.Utils;
|
---|
16 |
|
---|
17 | public class OverlappingAreas extends Test {
|
---|
18 |
|
---|
19 | protected static int OVERLAPPING_AREAS = 2201;
|
---|
20 | protected QuadBuckets<Way> index = new QuadBuckets<Way>();
|
---|
21 |
|
---|
22 | public OverlappingAreas() {
|
---|
23 | super(tr("Overlapping Areas"));
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public void visit(Way w) {
|
---|
28 | if (w.isUsable() && w.isClosed() && ElemStyles.hasAreaElemStyle(w, false)) {
|
---|
29 | index.add(w);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void endTest() {
|
---|
35 | for (final Way w : index) {
|
---|
36 | Collection<Way> overlaps = Utils.filter(
|
---|
37 | index.search(w.getBBox()),
|
---|
38 | new Predicate<Way>() {
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public boolean evaluate(Way wi) {
|
---|
42 | if (w.equals(wi)) {
|
---|
43 | return false;
|
---|
44 | } else {
|
---|
45 | return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
|
---|
46 | == Geometry.PolygonIntersection.CROSSING;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | });
|
---|
50 | if (!overlaps.isEmpty()) {
|
---|
51 | errors.add(new TestError(this, Severity.OTHER, tr("Overlapping Areas"),
|
---|
52 | OVERLAPPING_AREAS, Collections.singletonList(w), overlaps));
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | }
|
---|