# Changeset 13712 in josm for trunk/src/org/openstreetmap/josm/tools

Ignore:
Timestamp:
2018-05-07T23:40:50+02:00 (18 months ago)
Message:

see #16256 - improve "building with almost square angle" autofix: try to move only the highlighted node

File:
1 edited

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

 r13670 import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; import org.openstreetmap.josm.Main; } /** /** * Get angles in radians and return it's value in range [0, 180]. * */ public static EastNorth getCentroid(List nodes) { return getCentroidEN(nodes.stream().map(Node::getEastNorth).collect(Collectors.toList())); } /** * Compute the centroid/barycenter of nodes * @param nodes Coordinates for which the centroid is wanted * @return the centroid of nodes * @since 13712 */ public static EastNorth getCentroidEN(List nodes) { final int size = nodes.size(); if (size == 1) { return nodes.get(0); } else if (size == 2) { return nodes.get(0).getCenter(nodes.get(1)); } BigDecimal area = BigDecimal.ZERO; BigDecimal east = BigDecimal.ZERO; // See https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon for the equation used here for (int i = 0; i < nodes.size(); i++) { EastNorth n0 = nodes.get(i).getEastNorth(); EastNorth n1 = nodes.get((i+1) % nodes.size()).getEastNorth(); // See https://en.wikipedia.org/wiki/Centroid#Centroid_of_a_polygon for the equation used here for (int i = 0; i < size; i++) { EastNorth n0 = nodes.get(i); EastNorth n1 = nodes.get((i+1) % size); if (n0 != null && n1 != null && n0.isValid() && n1.isValid()) {
Note: See TracChangeset for help on using the changeset viewer.