Changeset 11361 in josm
- Timestamp:
- 2016-12-04T21:05:07+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/DefaultGeoProperty.java
r11360 r11361 3 3 4 4 import java.awt.geom.Area; 5 import java.awt.geom.Path2D; 5 6 import java.util.Collection; 6 7 … … 23 24 */ 24 25 public DefaultGeoProperty(Collection<Way> ways) { 25 Area area = null; 26 Path2D path = new Path2D.Double(); 27 path.setWindingRule(Path2D.WIND_EVEN_ODD); 26 28 for (Way w : ways) { 27 Area wayArea = Geometry.getAreaLatLon(w.getNodes()); 28 if (area == null) { 29 area = wayArea; 30 } else { 31 area.add(wayArea); 32 } 29 Geometry.buildPath2DLatLon(w.getNodes(), path); 33 30 } 34 this.area = area;31 this.area = new Area(path); 35 32 } 36 33 -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r11360 r11361 505 505 506 506 /** 507 * Returns the Area of a polygon, from its list of nodes. 508 * @param polygon List of nodes forming polygon 509 * @return Area for the given list of nodes (LatLon coordinates) 510 * @since 6841 511 */ 512 public static Area getAreaLatLon(List<Node> polygon) { 513 Path2D path = new Path2D.Double(); 514 507 * Builds a path from a list of nodes 508 * @param polygon Nodes, forming a closed polygon 509 * @param path path to add to; can be null, then a new path is created 510 * @return the path (LatLon coordinates) 511 */ 512 public static Path2D buildPath2DLatLon(List<Node> polygon, Path2D path) { 513 if (path == null) { 514 path = new Path2D.Double(); 515 } 515 516 boolean begin = true; 516 517 for (Node n : polygon) { … … 525 526 path.closePath(); 526 527 } 527 528 return new Area(path); 528 return path; 529 529 } 530 530 … … 538 538 ? new Multipolygon(multipolygon) 539 539 : MultipolygonCache.getInstance().get(Main.map.mapView, multipolygon); 540 Area result = null; 540 Path2D path = new Path2D.Double(); 541 path.setWindingRule(Path2D.WIND_EVEN_ODD); 541 542 for (Multipolygon.PolyData pd : mp.getCombinedPolygons()) { 542 Area area = getAreaLatLon(pd.getNodes());543 buildPath2DLatLon(pd.getNodes(), path); 543 544 for (Multipolygon.PolyData pdInner : pd.getInners()) { 544 Area areaInner = getAreaLatLon(pdInner.getNodes()); 545 area.subtract(areaInner); 546 } 547 if (result == null) { 548 result = area; 549 } else { 550 result.add(area); 551 } 552 } 553 return result; 545 buildPath2DLatLon(pdInner.getNodes(), path); 546 } 547 } 548 return new Area(path); 554 549 } 555 550
Note: See TracChangeset
for help on using the changeset viewer.