Changeset 10817 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-08-15T21:30:34+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r10797 r10817 12 12 import java.util.Comparator; 13 13 import java.util.EnumSet; 14 import java.util.HashSet;15 14 import java.util.LinkedHashSet; 16 15 import java.util.List; … … 26 25 import org.openstreetmap.josm.data.osm.BBox; 27 26 import org.openstreetmap.josm.data.osm.MultipolygonBuilder; 27 import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon; 28 28 import org.openstreetmap.josm.data.osm.Node; 29 29 import org.openstreetmap.josm.data.osm.NodePositionComparator; 30 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;32 31 import org.openstreetmap.josm.data.osm.Relation; 33 import org.openstreetmap.josm.data.osm.RelationMember;34 32 import org.openstreetmap.josm.data.osm.Way; 35 33 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; … … 863 861 } 864 862 865 public static class MultiPolygonMembers {866 public final Set<Way> outers = new HashSet<>();867 public final Set<Way> inners = new HashSet<>();868 869 public MultiPolygonMembers(Relation multiPolygon) {870 for (RelationMember m : multiPolygon.getMembers()) {871 if (m.getType().equals(OsmPrimitiveType.WAY)) {872 if ("outer".equals(m.getRole())) {873 outers.add(m.getWay());874 } else if ("inner".equals(m.getRole())) {875 inners.add(m.getWay());876 }877 }878 }879 }880 }881 882 863 /** 883 864 * Tests if the {@code node} is inside the multipolygon {@code multiPolygon}. The nullable argument … … 904 885 public static boolean isPolygonInsideMultiPolygon(List<Node> nodes, Relation multiPolygon, Predicate<Way> isOuterWayAMatch) { 905 886 // Extract outer/inner members from multipolygon 906 final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon); 907 // Construct complete rings for the inner/outer members 908 final List<MultipolygonBuilder.JoinedPolygon> outerRings; 909 final List<MultipolygonBuilder.JoinedPolygon> innerRings; 887 final Pair<List<JoinedPolygon>, List<JoinedPolygon>> outerInner; 910 888 try { 911 outerRings = MultipolygonBuilder.joinWays(mpm.outers); 912 innerRings = MultipolygonBuilder.joinWays(mpm.inners); 889 outerInner = MultipolygonBuilder.joinWays(multiPolygon); 913 890 } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) { 914 891 Main.trace(ex); … … 917 894 } 918 895 // Test if object is inside an outer member 919 for ( MultipolygonBuilder.JoinedPolygon out : outerRings) {896 for (JoinedPolygon out : outerInner.a) { 920 897 if (nodes.size() == 1 921 898 ? nodeInsidePolygon(nodes.get(0), out.getNodes()) … … 924 901 boolean insideInner = false; 925 902 // If inside an outer, check it is not inside an inner 926 for ( MultipolygonBuilder.JoinedPolygon in : innerRings) {903 for (JoinedPolygon in : outerInner.b) { 927 904 if (polygonIntersection(in.getNodes(), out.getNodes()) == PolygonIntersection.FIRST_INSIDE_SECOND 928 905 && (nodes.size() == 1
Note:
See TracChangeset
for help on using the changeset viewer.