Changeset 13712 in josm for trunk/src/org/openstreetmap/josm/tools
 Timestamp:
 20180507T23:40:50+02:00 (18 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/tools/Geometry.java
r13670 r13712 16 16 import java.util.Set; 17 17 import java.util.function.Predicate; 18 import java.util.stream.Collectors; 18 19 19 20 import org.openstreetmap.josm.Main; … … 796 797 } 797 798 798 /** 799 /** 799 800 * Get angles in radians and return it's value in range [0, 180]. 800 801 * … … 814 815 */ 815 816 public static EastNorth getCentroid(List<Node> nodes) { 817 return getCentroidEN(nodes.stream().map(Node::getEastNorth).collect(Collectors.toList())); 818 } 819 820 /** 821 * Compute the centroid/barycenter of nodes 822 * @param nodes Coordinates for which the centroid is wanted 823 * @return the centroid of nodes 824 * @since 13712 825 */ 826 public static EastNorth getCentroidEN(List<EastNorth> nodes) { 827 828 final int size = nodes.size(); 829 if (size == 1) { 830 return nodes.get(0); 831 } else if (size == 2) { 832 return nodes.get(0).getCenter(nodes.get(1)); 833 } 816 834 817 835 BigDecimal area = BigDecimal.ZERO; … … 819 837 BigDecimal east = BigDecimal.ZERO; 820 838 821 // See https://en.wikipedia.org/wiki/Centroid#Centroid_of_ polygon for the equation used here822 for (int i = 0; i < nodes.size(); i++) {823 EastNorth n0 = nodes.get(i) .getEastNorth();824 EastNorth n1 = nodes.get((i+1) % nodes.size()).getEastNorth();839 // See https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon for the equation used here 840 for (int i = 0; i < size; i++) { 841 EastNorth n0 = nodes.get(i); 842 EastNorth n1 = nodes.get((i+1) % size); 825 843 826 844 if (n0 != null && n1 != null && n0.isValid() && n1.isValid()) {
Note: See TracChangeset
for help on using the changeset viewer.