Ticket #233: truecircles.diff

File truecircles.diff, 1.7 KB (added by tom_evans_a@…, 17 years ago)

Patch for decent circles by changing the distance calculation.

  • src/org/openstreetmap/josm/actions/AlignInCircleAction.java

     
    5252                // Node "avn" now is central to all selected nodes.
    5353
    5454                // Now calculate the average distance to each node from the
    55                 // centre.
    56                 double avdist = 0;
    57                 for (Node n : nodes)
    58                         avdist += Math.sqrt(avn.eastNorth.distance(n.eastNorth));
     55                // centre.  This method is ok as long as distances are short
     56                // relative to the distance from the N or S poles.
     57                double distances[] = new double[nodes.size()];
     58                double avdist = 0, latd, lond;
     59                double lonscale = Math.cos(avn.coor.lat() * Math.PI/180.0);
     60                lonscale = lonscale * lonscale;
     61                int i = 0;
     62                for (Node n : nodes) {
     63                        latd = n.coor.lat() - avn.coor.lat();
     64                        lond = n.coor.lon() - avn.coor.lon();
     65                        distances[i] = Math.sqrt(latd * latd + lonscale * lond * lond);
     66                        avdist += distances[i++];
     67                }
    5968                avdist = avdist / nodes.size();
    6069
    6170                Collection<Command> cmds = new LinkedList<Command>();
    62                 // Move each node to that distance from the centre.
     71                // Move each node to that distance from the centre.
     72                i = 0;
    6373                for (Node n : nodes) {
    6474                        double dx = n.eastNorth.east() - avn.eastNorth.east();
    65                         double dy = n.eastNorth.north() - avn.eastNorth.north();
    66                         double dist = Math.sqrt(avn.eastNorth.distance(n.eastNorth));
     75                        double dy = n.eastNorth.north() - avn.eastNorth.north();
     76                        double dist = distances[i++];
    6777                        cmds.add(new MoveCommand(n, (dx * (avdist / dist)) - dx, (dy * (avdist / dist)) - dy));
    6878                }
    6979