Changeset 564 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2008-02-26T01:54:22+01:00 (17 years ago)
Author:
framm
Message:
  • align in circles now works regardless of projection. Patch by Tom Evans <tom_evans_a@…>. Fixes #233.
File:
1 edited

Legend:

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

    r469 r564  
    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>();
    6271                // 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();
    6575                        double dy = n.eastNorth.north() - avn.eastNorth.north();
    66                         double dist = Math.sqrt(avn.eastNorth.distance(n.eastNorth));
     76                        double dist = distances[i++];
    6777                        cmds.add(new MoveCommand(n, (dx * (avdist / dist)) - dx, (dy * (avdist / dist)) - dy));
    6878                }
Note: See TracChangeset for help on using the changeset viewer.