source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingAreas.java@ 5269

Last change on this file since 5269 was 5269, checked in by simon04, 14 years ago

fix #7759 - Validator progress monitor does not update after "Building in Building" check (patch by mrwojo)

File size: 2.0 KB
Line 
1package org.openstreetmap.josm.data.validation.tests;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.util.Collection;
6import java.util.Collections;
7
8import org.openstreetmap.josm.data.osm.QuadBuckets;
9import org.openstreetmap.josm.data.osm.Way;
10import org.openstreetmap.josm.data.validation.Severity;
11import org.openstreetmap.josm.data.validation.Test;
12import org.openstreetmap.josm.data.validation.TestError;
13import org.openstreetmap.josm.gui.mappaint.ElemStyles;
14import org.openstreetmap.josm.tools.Geometry;
15import org.openstreetmap.josm.tools.Predicate;
16import org.openstreetmap.josm.tools.Utils;
17
18public class OverlappingAreas extends Test {
19
20 protected static final int OVERLAPPING_AREAS = 2201;
21 protected QuadBuckets<Way> index = new QuadBuckets<Way>();
22
23 public OverlappingAreas() {
24 super(tr("Overlapping Areas"), tr("This test checks if areas overlap."));
25 }
26
27 @Override
28 public void visit(Way w) {
29 if (w.isUsable() && w.isClosed() && ElemStyles.hasAreaElemStyle(w, false)) {
30 index.add(w);
31 }
32 }
33
34 @Override
35 public void endTest() {
36 for (final Way w : index) {
37 Collection<Way> overlaps = Utils.filter(
38 index.search(w.getBBox()),
39 new Predicate<Way>() {
40
41 @Override
42 public boolean evaluate(Way wi) {
43 if (w.equals(wi))
44 return false;
45 else
46 return Geometry.polygonIntersection(w.getNodes(), wi.getNodes())
47 == Geometry.PolygonIntersection.CROSSING;
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 super.endTest();
57 }
58
59}
Note: See TracBrowser for help on using the repository browser.