Changeset 9099 in josm for trunk/src/org/openstreetmap/josm/tools
 Timestamp:
 20151211T17:36:59+01:00 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/tools/Geometry.java
r9063 r9099 978 978 * Uses current projection; units are that of the projected coordinates. 979 979 * 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 982 981 * @return area and perimeter 983 982 */ 984 983 public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes) { 985 if (nodes.get(0) != nodes.get(nodes.size()  1)) {986 throw new IllegalArgumentException();987 }988 984 double area = 0; 989 985 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(); 995 992 area += p1.east() * p2.north()  p2.east() * p1.north(); 996 993 perimeter += p1.distance(p2); 997 }998 lastN = n;994 p1 = p2; 995 } 999 996 } 1000 997 return new AreaAndPerimeter(Math.abs(area) / 2, perimeter);
Note: See TracChangeset
for help on using the changeset viewer.