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

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

File:
1 edited

Legend:

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

    r13670 r13712  
    1616import java.util.Set;
    1717import java.util.function.Predicate;
     18import java.util.stream.Collectors;
    1819
    1920import org.openstreetmap.josm.Main;
     
    796797    }
    797798
    798     /** 
     799    /**
    799800     * Get angles in radians and return it's value in range [0, 180].
    800801     *
     
    814815     */
    815816    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        }
    816834
    817835        BigDecimal area = BigDecimal.ZERO;
     
    819837        BigDecimal east = BigDecimal.ZERO;
    820838
    821         // See https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon for the equation used here
    822         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);
    825843
    826844            if (n0 != null && n1 != null && n0.isValid() && n1.isValid()) {
Note: See TracChangeset for help on using the changeset viewer.