Ticket #9680: 9680_alpha.patch
File 9680_alpha.patch, 4.3 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/data/osm/MultipolygonCreate.java
3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.geom.Area; 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; 8 9 import java.util.Collections; … … 25 26 public final List<Way> ways; 26 27 public final List<Boolean> reversed; 27 28 public final List<Node> nodes; 29 public final Area area; 28 30 29 31 public JoinedPolygon(List<Way> ways, List<Boolean> reversed) { 30 32 this.ways = ways; 31 33 this.reversed = reversed; 32 34 this.nodes = this.getNodes(); 35 this.area = Geometry.getArea(nodes); 33 36 } 34 37 35 38 /** … … 37 40 * @param way the way to form the polygon 38 41 */ 39 42 public JoinedPolygon(Way way) { 40 this.ways = Collections.singletonList(way); 41 this.reversed = Collections.singletonList(Boolean.FALSE); 42 this.nodes = this.getNodes(); 43 this(Collections.singletonList(way), Collections.singletonList(Boolean.FALSE)); 43 44 } 44 45 45 46 46 /** 47 47 * Builds a list of nodes for this polygon. First node is not duplicated as last node. 48 48 * @return list of nodes … … 232 232 continue; 233 233 } 234 234 235 PolygonIntersection intersection = Geometry.polygonIntersection(outerWay.nodes, innerWay.nodes); 235 //long start = System.currentTimeMillis(); 236 PolygonIntersection intersection = Geometry.polygonIntersection(outerWay.area, innerWay.area); 237 //long time = System.currentTimeMillis() - start; 238 //if (time > 2) { 239 //System.err.println(time + " ms for comparing "+outerWay+" and "+innerWay); 240 //} 236 241 237 242 if (intersection == PolygonIntersection.FIRST_INSIDE_SECOND) { 238 243 outerGood = false; // outer is inside another polygon -
src/org/openstreetmap/josm/tools/Geometry.java
440 440 return dy1 * dx2 - dx1 * dy2 > 0; 441 441 } 442 442 443 private static Area getArea(List<Node> polygon) { 443 /** 444 * Returns the Area of a polygon, from its list of nodes. 445 * @param polygon List of nodes forming polygon 446 * @return Area for the given list of nodes 447 */ 448 public static Area getArea(List<Node> polygon) { 444 449 Path2D path = new Path2D.Double(); 445 450 446 451 boolean begin = true; … … 461 466 462 467 /** 463 468 * Tests if two polygons intersect. 464 * @param first 465 * @param second 469 * @param first List of nodes forming first polygon 470 * @param second List of nodes forming second polygon 466 471 * @return intersection kind 467 472 */ 468 473 public static PolygonIntersection polygonIntersection(List<Node> first, List<Node> second) { 469 474 //long start = System.currentTimeMillis(); 470 475 Area a1 = getArea(first); 471 476 Area a2 = getArea(second); 477 /*long time = System.currentTimeMillis() - start; 478 if (time > 2) { 479 System.err.println(time + " ms for computing areas"); 480 }*/ 481 return polygonIntersection(a1, a2); 482 } 472 483 484 /** 485 * Tests if two polygons intersect. 486 * @param a1 Area of first polygon 487 * @param a2 Area of second polygon 488 * @return intersection kind 489 */ 490 public static PolygonIntersection polygonIntersection(Area a1, Area a2) { 491 492 //long start = System.currentTimeMillis(); 473 493 Area inter = new Area(a1); 474 494 inter.intersect(a2); 475 495 476 496 Rectangle bounds = inter.getBounds(); 497 /*long time = System.currentTimeMillis() - start; 498 if (time > 2) { 499 System.err.println(time + " ms for computing intersection"); 500 }*/ 477 501 478 502 if (inter.isEmpty() || bounds.getHeight()*bounds.getWidth() <= 1.0) { 479 503 return PolygonIntersection.OUTSIDE;