- Timestamp:
- 2011-12-28T22:51:11+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/BuildingInBuilding.java
r4409 r4738 6 6 import java.util.LinkedList; 7 7 import java.util.List; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 8 10 import org.openstreetmap.josm.data.osm.Node; 9 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 46 48 } 47 49 50 /** 51 * Return true if w is in polygon. 52 */ 48 53 private static boolean isInPolygon(Way w, List<Node> polygon) { 54 // Check that all nodes of w are in polygon 49 55 for (Node n : w.getNodes()) { 50 56 if (!isInPolygon(n, polygon)) { 57 return false; 58 } 59 } 60 // All nodes can be inside polygon and still, w outside: 61 // +-------------+ 62 // /| | 63 // / | | 64 // / | | 65 // / w | | 66 // +----+----+ | 67 // | polygon | 68 // |_______________________| 69 // 70 for (int i=0; i<w.getNodesCount(); i++) { 71 LatLon center = null; 72 if (i > 0) { 73 center = w.getNode(i).getCoor().getCenter(w.getNode(i-1).getCoor()); 74 } else if (w.isClosed()) { 75 center = w.getNode(i).getCoor().getCenter(w.getNode(w.getNodesCount()-2).getCoor()); 76 } 77 if (center != null && !isInPolygon(new Node(center), polygon)) { 51 78 return false; 52 79 } … … 66 93 return false; 67 94 } else if (p instanceof Node) { 68 return isInPolygon((Node) p, object.getNodes()) || object.getNodes().contains( (Node)p);95 return isInPolygon((Node) p, object.getNodes()) || object.getNodes().contains(p); 69 96 } else if (p instanceof Way) { 70 97 return isInPolygon((Way) p, object.getNodes());
Note:
See TracChangeset
for help on using the changeset viewer.