Changeset 12879 in josm for trunk


Ignore:
Timestamp:
2017-09-20T10:17:35+02:00 (7 years ago)
Author:
bastiK
Message:

applied #15327 - small cleanup and "fix" for CreateCircleAction (patch by naoliv)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r12837 r12879  
    162162        if (nodes.size() == 2) {
    163163            // diameter: two single nodes needed or a way with two nodes
    164             Node n1 = nodes.get(0);
    165             double x1 = n1.getEastNorth().east();
    166             double y1 = n1.getEastNorth().north();
    167             Node n2 = nodes.get(1);
    168             double x2 = n2.getEastNorth().east();
    169             double y2 = n2.getEastNorth().north();
    170 
    171             // calculate the center (xc/yc)
    172             double xc = 0.5 * (x1 + x2);
    173             double yc = 0.5 * (y1 + y2);
    174             center = new EastNorth(xc, yc);
     164            EastNorth n1 = nodes.get(0).getEastNorth();
     165            EastNorth n2 = nodes.get(1).getEastNorth();
     166
     167            center = n1.getCenter(n2);
    175168        } else {
    176169            // triangle: three single nodes needed or a way with three nodes
     
    184177        // calculate the radius (r)
    185178        EastNorth n1 = nodes.get(0).getEastNorth();
    186         double r = Math.sqrt(Math.pow(center.east()-n1.east(), 2) +
    187                 Math.pow(center.north()-n1.north(), 2));
     179        double r = n1.distance(center);
    188180
    189181        // see #10777
     
    194186
    195187        int numberOfNodesInCircle = (int) Math.ceil(6.0 * Math.pow(radiusInMeters, 0.5));
     188        // an odd number of nodes makes the distribution uneven
     189        if ((numberOfNodesInCircle % 2) == 1) {
     190            // add 1 to make it even
     191            numberOfNodesInCircle += 1;
     192        }
    196193        if (numberOfNodesInCircle < 6) {
    197            numberOfNodesInCircle = 6;
     194            numberOfNodesInCircle = 6;
    198195        }
    199196
Note: See TracChangeset for help on using the changeset viewer.