Ignore:
Timestamp:
2015-11-25T09:54:02+01:00 (9 years ago)
Author:
bastiK
Message:

mapcss: partial fill - if partial fill would only leave a small gap in the center, fill area completely (see #12104)

File:
1 edited

Legend:

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

    r9062 r9063  
    951951        return false;
    952952    }
     953
     954    /**
     955     * Data class to hold two double values (area and perimeter of a polygon).
     956     */
     957    public static class AreaAndPerimeter {
     958        private final double area;
     959        private final double perimeter;
     960
     961        public AreaAndPerimeter(double area, double perimeter) {
     962            this.area = area;
     963            this.perimeter = perimeter;
     964        }
     965
     966        public double getArea() {
     967            return area;
     968        }
     969
     970        public double getPerimeter() {
     971            return perimeter;
     972        }
     973    }
     974
     975    /**
     976     * Calculate area and perimeter length of a polygon.
     977     *
     978     * Uses current projection; units are that of the projected coordinates.
     979     *
     980     * @param nodes the list of nodes representing the polygon (must be
     981     * closed, i.e. first node equals last node)
     982     * @return area and perimeter
     983     */
     984    public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes) {
     985        if (nodes.get(0) != nodes.get(nodes.size() - 1)) {
     986            throw new IllegalArgumentException();
     987        }
     988        double area = 0;
     989        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();
     995                area += p1.east() * p2.north() - p2.east() * p1.north();
     996                perimeter += p1.distance(p2);
     997            }
     998            lastN = n;
     999        }
     1000        return new AreaAndPerimeter(Math.abs(area) / 2, perimeter);
     1001    }
    9531002}
Note: See TracChangeset for help on using the changeset viewer.