Ticket #233: truecircles.diff
File truecircles.diff, 1.7 KB (added by , 17 years ago) |
---|
-
src/org/openstreetmap/josm/actions/AlignInCircleAction.java
52 52 // Node "avn" now is central to all selected nodes. 53 53 54 54 // 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 } 59 68 avdist = avdist / nodes.size(); 60 69 61 70 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; 63 73 for (Node n : nodes) { 64 74 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++]; 67 77 cmds.add(new MoveCommand(n, (dx * (avdist / dist)) - dx, (dy * (avdist / dist)) - dy)); 68 78 } 69 79