- Timestamp:
- 2017-11-10T21:06:30+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r13106 r13107 21 21 import org.openstreetmap.josm.command.SequenceCommand; 22 22 import org.openstreetmap.josm.data.coor.EastNorth; 23 import org.openstreetmap.josm.data.coor.PolarCoor; 23 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.Node; … … 52 53 } 53 54 54 private static double distance(EastNorth n, EastNorth m) { 55 double easd, nord; 56 easd = n.east() - m.east(); 57 nord = n.north() - m.north(); 58 return Math.sqrt(easd * easd + nord * nord); 59 } 60 61 public static class PolarCoor { 62 private double radius; 63 private double angle; 64 private EastNorth origin = new EastNorth(0, 0); 65 private double azimuth; 66 67 PolarCoor(double radius, double angle) { 68 this(radius, angle, new EastNorth(0, 0), 0); 69 } 70 71 PolarCoor(double radius, double angle, EastNorth origin, double azimuth) { 72 this.radius = radius; 73 this.angle = angle; 74 this.origin = origin; 75 this.azimuth = azimuth; 76 } 77 78 PolarCoor(EastNorth en) { 79 this(en, new EastNorth(0, 0), 0); 80 } 81 82 PolarCoor(EastNorth en, EastNorth origin, double azimuth) { 83 radius = distance(en, origin); 84 angle = Math.atan2(en.north() - origin.north(), en.east() - origin.east()); 85 this.origin = origin; 86 this.azimuth = azimuth; 87 } 88 89 /** 90 * Converts this {@code PolarCoor} to an {@link EastNorth} instance. 91 * @return a new {@code EastNorth} instance 92 */ 93 public EastNorth toEastNorth() { 94 return new EastNorth(radius * Math.cos(angle - azimuth) + origin.east(), radius * Math.sin(angle - azimuth) 95 + origin.north()); 96 } 97 98 /** 99 * Create a MoveCommand to move a node to this PolarCoor. 100 * @param n Node to move 101 * @return new MoveCommand 102 */ 103 public MoveCommand createMoveCommand(Node n) { 104 EastNorth en = toEastNorth(); 105 return new MoveCommand(n, en.east() - n.getEastNorth().east(), en.north() - n.getEastNorth().north()); 106 } 107 } 108 55 /** 56 * Create a {@link MoveCommand} to move a node to a PolarCoor. 57 * @param n Node to move 58 * @param coor polar coordinate where to move the node 59 * @return new MoveCommand 60 * @since 13107 61 */ 62 public static MoveCommand createMoveCommand(Node n, PolarCoor coor) { 63 EastNorth en = coor.toEastNorth(); 64 return new MoveCommand(n, en.east() - n.getEastNorth().east(), en.north() - n.getEastNorth().north()); 65 } 109 66 110 67 /** … … 188 145 } else if (outside.size() == 1 && inside.size() == 1) { 189 146 center = outside.get(0).getEastNorth(); 190 radius = distance(center,inside.get(0).getEastNorth());147 radius = center.distance(inside.get(0).getEastNorth()); 191 148 } else if (inside.size() == 2 && outside.isEmpty()) { 192 149 // 2 nodes inside, define diameter … … 194 151 EastNorth en1 = inside.get(1).getEastNorth(); 195 152 center = new EastNorth((en0.east() + en1.east()) / 2, (en0.north() + en1.north()) / 2); 196 radius = distance(en0,en1) / 2;153 radius = en0.distance(en1) / 2; 197 154 } 198 155 … … 239 196 if (radius == 0) { 240 197 for (Node n : nodes) { 241 radius += distance(center,n.getEastNorth());198 radius += center.distance(n.getEastNorth()); 242 199 } 243 200 radius = radius / nodes.size(); … … 265 222 } 266 223 Node first = nodes.get(i % nodeCount); 267 PolarCoor pcFirst = new PolarCoor(first.getEastNorth(), center, 0); 268 pcFirst.radius = radius; 269 cmds.add(pcFirst.createMoveCommand(first)); 224 PolarCoor pcFirst = new PolarCoor(radius, PolarCoor.computeAngle(first.getEastNorth(), center), center); 225 cmds.add(createMoveCommand(first, pcFirst)); 270 226 if (j > i + 1) { 271 227 double delta; … … 273 229 delta = 2 * Math.PI / nodeCount; 274 230 } else { 275 PolarCoor pcLast = new PolarCoor(nodes.get(j % nodeCount).getEastNorth(), center , 0);231 PolarCoor pcLast = new PolarCoor(nodes.get(j % nodeCount).getEastNorth(), center); 276 232 delta = pcLast.angle - pcFirst.angle; 277 233 if (delta < 0) // Assume each PolarCoor.angle is in range ]-pi; pi] … … 280 236 } 281 237 for (int k = i+1; k < j; k++) { 282 PolarCoor p = new PolarCoor(radius, pcFirst.angle + (k-i)*delta, center , 0);283 cmds.add( p.createMoveCommand(nodes.get(k % nodeCount)));238 PolarCoor p = new PolarCoor(radius, pcFirst.angle + (k-i)*delta, center); 239 cmds.add(createMoveCommand(nodes.get(k % nodeCount), p)); 284 240 } 285 241 } -
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r12984 r13107 21 21 import org.openstreetmap.josm.command.SequenceCommand; 22 22 import org.openstreetmap.josm.data.coor.EastNorth; 23 import org.openstreetmap.josm.data.coor.PolarCoor; 23 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.Node; … … 308 309 double[] angle = new double[4]; 309 310 for (int i = 0; i < 4; i++) { 310 EastNorth p = neighbors.get(i).getEastNorth(); 311 angle[i] = Math.atan2(p.north() - c.north(), p.east() - c.east()); 311 angle[i] = PolarCoor.computeAngle(neighbors.get(i).getEastNorth(), c); 312 312 } 313 313 double[] deltaAngle = new double[3]; -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r12879 r13107 25 25 import org.openstreetmap.josm.data.coor.EastNorth; 26 26 import org.openstreetmap.josm.data.coor.LatLon; 27 import org.openstreetmap.josm.data.coor.PolarCoor; 27 28 import org.openstreetmap.josm.data.osm.DataSet; 28 29 import org.openstreetmap.josm.data.osm.Node; … … 108 109 109 110 PolarNode(EastNorth center, Node n) { 110 EastNorth pt = n.getEastNorth(); 111 this.a = Math.atan2(pt.north() - center.north(), pt.east() - center.east()); 111 this.a = PolarCoor.computeAngle(n.getEastNorth(), center); 112 112 this.node = n; 113 113 } -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r12641 r13107 26 26 import org.openstreetmap.josm.command.SequenceCommand; 27 27 import org.openstreetmap.josm.data.coor.EastNorth; 28 import org.openstreetmap.josm.data.coor.PolarCoor; 28 29 import org.openstreetmap.josm.data.osm.Node; 29 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 575 576 576 577 public static double polar(EastNorth en1, EastNorth en2) { 577 return Math.atan2(en2.north() - en1.north(), en2.east() - en1.east());578 return PolarCoor.computeAngle(en2, en1); 578 579 } 579 580 } -
trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java
r12817 r13107 117 117 Coordinate that = (Coordinate) obj; 118 118 return Double.compare(that.x, x) == 0 && 119 119 Double.compare(that.y, y) == 0; 120 120 } 121 121 }
Note:
See TracChangeset
for help on using the changeset viewer.