Ignore:
Timestamp:
2015-12-11T17:36:59+01:00 (8 years ago)
Author:
bastiK
Message:

mapcss partial fill: move threshold parameter ([9063]) into the mapcss style
(new property fill-extent-threshold)

  • add support for this parameter when area is unclosed
  • smaller extent for unclosed areas

(see #12104)

File:
1 edited

Legend:

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

    r9063 r9099  
    978978     * Uses current projection; units are that of the projected coordinates.
    979979     *
    980      * @param nodes the list of nodes representing the polygon (must be
    981      * closed, i.e. first node equals last node)
     980     * @param nodes the list of nodes representing the polygon
    982981     * @return area and perimeter
    983982     */
    984983    public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes) {
    985         if (nodes.get(0) != nodes.get(nodes.size() - 1)) {
    986             throw new IllegalArgumentException();
    987         }
    988984        double area = 0;
    989985        double perimeter = 0;
    990         Node lastN = null;
    991         for (Node n : nodes) {
    992             if (lastN != null) {
    993                 EastNorth p1 = lastN.getEastNorth();
    994                 EastNorth p2 = n.getEastNorth();
     986        if (!nodes.isEmpty()) {
     987            boolean closed = nodes.get(0) == nodes.get(nodes.size() - 1);
     988            int numSegments = closed ? nodes.size() - 1 : nodes.size();
     989            EastNorth p1 = nodes.get(0).getEastNorth();
     990            for (int i=1; i<=numSegments; i++) {
     991                EastNorth p2 = nodes.get(i == numSegments ? 0 : i).getEastNorth();
    995992                area += p1.east() * p2.north() - p2.east() * p1.north();
    996993                perimeter += p1.distance(p2);
    997             }
    998             lastN = n;
     994                p1 = p2;
     995            }
    999996        }
    1000997        return new AreaAndPerimeter(Math.abs(area) / 2, perimeter);
Note: See TracChangeset for help on using the changeset viewer.