Changeset 11361 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2016-12-04T21:05:07+01:00 (7 years ago)
Author:
bastiK
Message:

see #10387 - use path winding rule instead of Area.subtract

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/DefaultGeoProperty.java

    r11360 r11361  
    33
    44import java.awt.geom.Area;
     5import java.awt.geom.Path2D;
    56import java.util.Collection;
    67
     
    2324     */
    2425    public DefaultGeoProperty(Collection<Way> ways) {
    25         Area area = null;
     26        Path2D path = new Path2D.Double();
     27        path.setWindingRule(Path2D.WIND_EVEN_ODD);
    2628        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);
    3330        }
    34         this.area = area;
     31        this.area = new Area(path);
    3532    }
    3633
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r11360 r11361  
    505505
    506506    /**
    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        }
    515516        boolean begin = true;
    516517        for (Node n : polygon) {
     
    525526            path.closePath();
    526527        }
    527 
    528         return new Area(path);
     528        return path;
    529529    }
    530530
     
    538538                ? new Multipolygon(multipolygon)
    539539                : MultipolygonCache.getInstance().get(Main.map.mapView, multipolygon);
    540         Area result = null;
     540        Path2D path = new Path2D.Double();
     541        path.setWindingRule(Path2D.WIND_EVEN_ODD);
    541542        for (Multipolygon.PolyData pd : mp.getCombinedPolygons()) {
    542             Area area = getAreaLatLon(pd.getNodes());
     543            buildPath2DLatLon(pd.getNodes(), path);
    543544            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);
    554549    }
    555550
Note: See TracChangeset for help on using the changeset viewer.