Ticket #2302: coor.patch
| File coor.patch, 15.3 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/AlignInCircleAction.java
15 15 import org.openstreetmap.josm.command.MoveCommand; 16 16 import org.openstreetmap.josm.command.SequenceCommand; 17 17 import org.openstreetmap.josm.data.coor.EastNorth; 18 import org.openstreetmap.josm.data.coor.LatLon;19 18 import org.openstreetmap.josm.data.osm.Node; 20 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 20 import org.openstreetmap.josm.data.osm.Way; … … 134 133 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 135 134 Collection<Node> nodes = new LinkedList<Node>(); 136 135 Collection<Way> ways = new LinkedList<Way>(); 137 Nodecenter = null;136 EastNorth center = null; 138 137 double radius = 0; 139 138 boolean regular = false; 140 139 … … 163 162 regular = true; 164 163 } else { 165 164 166 center = ( Node) nodes.toArray()[way.nodes.contains(nodes.toArray()[0]) ? 1 : 0];165 center = ((Node) nodes.toArray()[way.nodes.contains(nodes.toArray()[0]) ? 1 : 0]).eastNorth; 167 166 if (nodes.size() == 2) 168 167 radius = distance(((Node) nodes.toArray()[0]).eastNorth, ((Node) nodes.toArray()[1]).eastNorth); 169 168 } … … 183 182 184 183 // Get average position of circumcircles of the triangles of all triplets of neighbour nodes 185 184 if (center == null) { 186 center = new Node(new LatLon(0, 0)); 187 center.eastNorth = new EastNorth(0, 0); // to be independent of projection 185 center = new EastNorth(0, 0); 188 186 Node n0 = (Node) nodes.toArray()[nodes.size() - 1]; 189 187 Node n1 = (Node) nodes.toArray()[nodes.size() - 2]; 190 188 Node n2; … … 195 193 EastNorth cc = circumcenter(n0.eastNorth, n1.eastNorth, n2.eastNorth); 196 194 if (cc == null) 197 195 return; 198 center .eastNorth = new EastNorth(center.eastNorth.east() + cc.east(), center.eastNorth.north()196 center = new EastNorth(center.east() + cc.east(), center.north() 199 197 + cc.north()); 200 198 } 201 199 202 center .eastNorth = new EastNorth(center.eastNorth.east() / nodes.size(), center.eastNorth.north()200 center = new EastNorth(center.east() / nodes.size(), center.north() 203 201 / nodes.size()); 204 center.coor = Main.proj.eastNorth2latlon(center.eastNorth);205 202 } 206 203 207 204 // Node "center" now is central to all selected nodes. … … 211 208 // relative to the distance from the N or S poles. 212 209 if (radius == 0) { 213 210 for (Node n : nodes) { 214 radius += distance(center .eastNorth, n.eastNorth);211 radius += distance(center, n.eastNorth); 215 212 } 216 213 radius = radius / nodes.size(); 217 214 } … … 222 219 223 220 if (regular) { // Make a regular polygon 224 221 double angle = Math.PI * 2 / nodes.size(); 225 pc = new PolarCoor(((Node) nodes.toArray()[0]).eastNorth, center .eastNorth, 0);222 pc = new PolarCoor(((Node) nodes.toArray()[0]).eastNorth, center, 0); 226 223 227 if (pc.angle > (new PolarCoor(((Node) nodes.toArray()[1]).eastNorth, center .eastNorth, 0).angle))224 if (pc.angle > (new PolarCoor(((Node) nodes.toArray()[1]).eastNorth, center, 0).angle)) 228 225 angle *= -1; 229 226 230 227 pc.radius = radius; … … 235 232 } 236 233 } else { // Move each node to that distance from the centre. 237 234 for (Node n : nodes) { 238 pc = new PolarCoor(n.eastNorth, center .eastNorth, 0);235 pc = new PolarCoor(n.eastNorth, center, 0); 239 236 pc.radius = radius; 240 237 EastNorth no = pc.toEastNorth(); 241 238 cmds.add(new MoveCommand(n, no.east() - n.eastNorth.east(), no.north() - n.eastNorth.north())); -
src/org/openstreetmap/josm/actions/UnGlueAction.java
20 20 import org.openstreetmap.josm.command.ChangeCommand; 21 21 import org.openstreetmap.josm.command.Command; 22 22 import org.openstreetmap.josm.command.SequenceCommand; 23 import org.openstreetmap.josm.data.coor.EastNorth;24 23 import org.openstreetmap.josm.data.osm.Node; 25 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 25 import org.openstreetmap.josm.data.osm.Relation; … … 148 147 // If this wasn't called from menu, place it where the cursor is/was 149 148 if(e.getSource() instanceof JPanel) { 150 149 MapView mv = Main.map.mapView; 151 n.eastNorth = mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY()); 152 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 150 n.setEastNorth(mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY())); 153 151 } 154 152 155 153 cmds.add(new AddCommand(n)); -
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
800 800 // fall through to default action. 801 801 // (for semi-parallel lines, intersection might be miles away!) 802 802 if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) { 803 n. eastNorth = intersection;803 n.setEastNorth(intersection); 804 804 return; 805 805 } 806 806 … … 813 813 double b = P.distanceSq(A); 814 814 double c = A.distanceSq(B); 815 815 q = (a - b + c) / (2*c); 816 n.eastNorth = new EastNorth( 817 B.east() + q * (A.east() - B.east()), 818 B.north() + q * (A.north() - B.north())); 816 n.setEastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())); 819 817 } 820 818 } 821 819 -
src/org/openstreetmap/josm/actions/PasteAction.java
16 16 import org.openstreetmap.josm.command.AddCommand; 17 17 import org.openstreetmap.josm.command.Command; 18 18 import org.openstreetmap.josm.command.SequenceCommand; 19 import org.openstreetmap.josm.data.coor.EastNorth; 19 20 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.data.osm.Relation;21 21 import org.openstreetmap.josm.data.osm.Node; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Relation; 23 24 import org.openstreetmap.josm.data.osm.RelationMember; 24 25 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.data.coor.EastNorth;26 26 import org.openstreetmap.josm.gui.layer.Layer; 27 27 import org.openstreetmap.josm.tools.Shortcut; 28 28 … … 69 69 Node nnew = new Node(n); 70 70 nnew.id = 0; 71 71 if (Main.main.editLayer() == source) { 72 nnew.eastNorth = new EastNorth(nnew.eastNorth.east() + offsetEast, nnew.eastNorth.north() + offsetNorth); 73 nnew.coor = Main.proj.eastNorth2latlon(nnew.eastNorth); 72 nnew.setEastNorth(nnew.eastNorth.add(offsetEast, offsetNorth)); 74 73 } 75 74 map.put(n, nnew); 76 75 } -
src/org/openstreetmap/josm/data/conflict/PositionConflict.java
22 22 23 23 @Override public void apply(OsmPrimitive target, OsmPrimitive other) { 24 24 if (target instanceof Node) { 25 ((Node)target).coor = ((Node)other).coor; 26 ((Node)target).eastNorth = ((Node)other).eastNorth; 25 ((Node)target).setEastNorth(((Node)other).eastNorth); 27 26 int newversion = Math.max(target.version, other.version); 28 27 // set version on "other" as well in case user decides to keep local 29 28 target.version = newversion; -
src/org/openstreetmap/josm/data/osm/Node.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.coor.EastNorth; 7 8 import org.openstreetmap.josm.data.coor.LatLon; 8 import org.openstreetmap.josm.data.coor.EastNorth;9 9 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 10 10 import org.openstreetmap.josm.data.osm.visitor.Visitor; 11 11 … … 19 19 20 20 public LatLon coor; 21 21 public volatile EastNorth eastNorth; 22 22 23 public void setCoor(LatLon coor) { 24 this.coor = coor; 25 this.eastNorth = Main.proj.latlon2eastNorth(coor); 26 } 27 28 public void setEastNorth(EastNorth eastNorth) { 29 this.eastNorth = eastNorth; 30 this.coor = Main.proj.eastNorth2latlon(eastNorth); 31 } 32 33 public void setEastNorth(double east, double north) { 34 this.setEastNorth(new EastNorth(east, north)); 35 } 36 23 37 private static CoordinateFormat mCord; 24 38 25 39 static { … … 46 60 } 47 61 48 62 public Node(LatLon latlon) { 49 this.coor = latlon; 50 eastNorth = Main.proj.latlon2eastNorth(latlon); 63 setCoor(latlon); 51 64 } 52 65 53 66 @Override public void visit(Visitor visitor) { -
src/org/openstreetmap/josm/command/MoveCommand.java
14 14 import javax.swing.tree.DefaultMutableTreeNode; 15 15 import javax.swing.tree.MutableTreeNode; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.data.coor.EastNorth; 19 18 import org.openstreetmap.josm.data.coor.LatLon; 20 19 import org.openstreetmap.josm.data.osm.Node; … … 87 86 */ 88 87 public void moveAgain(double x, double y) { 89 88 for (Node n : objects) { 90 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y); 91 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 89 n.setEastNorth(n.eastNorth.add(x, y)); 92 90 } 93 91 this.x += x; 94 92 this.y += y; … … 96 94 97 95 @Override public boolean executeCommand() { 98 96 for (Node n : objects) { 99 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y); 100 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 97 n.setEastNorth(n.eastNorth.add(x, y)); 101 98 n.modified = true; 102 99 } 103 100 return true; … … 107 104 Iterator<OldState> it = oldState.iterator(); 108 105 for (Node n : objects) { 109 106 OldState os = it.next(); 110 n.eastNorth = os.eastNorth; 111 n.coor = os.latlon; 107 n.setEastNorth(os.eastNorth); 112 108 n.modified = os.modified; 113 109 } 114 110 } -
src/org/openstreetmap/josm/command/RotateCommand.java
12 12 import javax.swing.tree.DefaultMutableTreeNode; 13 13 import javax.swing.tree.MutableTreeNode; 14 14 15 import org.openstreetmap.josm.Main;16 15 import org.openstreetmap.josm.data.coor.EastNorth; 17 import org.openstreetmap.josm.data.coor.LatLon;18 16 import org.openstreetmap.josm.data.osm.Node; 19 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 18 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; … … 35 33 /** 36 34 * pivot point 37 35 */ 38 private Nodepivot;36 private EastNorth pivot; 39 37 40 38 /** 41 39 * angle of rotation starting click to pivot … … 61 59 public RotateCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) { 62 60 63 61 this.objects = AllNodesVisitor.getAllNodes(objects); 64 pivot = new Node(new LatLon(0,0)); 65 pivot.eastNorth = new EastNorth(0,0); 62 pivot = new EastNorth(0,0); 66 63 67 64 for (Node n : this.objects) { 68 65 MoveCommand.OldState os = new MoveCommand.OldState(); … … 70 67 os.latlon = n.coor; 71 68 os.modified = n.modified; 72 69 oldState.put(n, os); 73 pivot .eastNorth = new EastNorth(pivot.eastNorth.east()+os.eastNorth.east(), pivot.eastNorth.north()+os.eastNorth.north());70 pivot = pivot.add(os.eastNorth.east(), os.eastNorth.north()); 74 71 } 75 pivot.eastNorth = new EastNorth(pivot.eastNorth.east()/this.objects.size(), pivot.eastNorth.north()/this.objects.size()); 76 pivot.coor = Main.proj.eastNorth2latlon(pivot.eastNorth); 72 pivot = new EastNorth(pivot.east()/this.objects.size(), pivot.north()/this.objects.size()); 77 73 78 74 rotationAngle = Math.PI/2; 79 75 rotateAgain(start, end); … … 86 82 */ 87 83 public void rotateAgain(EastNorth start, EastNorth end) { 88 84 // compute angle 89 startAngle = Math.atan2(start.east()-pivot.east North.east(), start.north()-pivot.eastNorth.north());90 double endAngle = Math.atan2(end.east()-pivot.east North.east(), end.north()-pivot.eastNorth.north());85 startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 86 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 91 87 rotationAngle += startAngle - endAngle; 92 88 rotateNodes(false); 93 89 } … … 101 97 double cosPhi = Math.cos(rotationAngle); 102 98 double sinPhi = Math.sin(rotationAngle); 103 99 EastNorth oldEastNorth = oldState.get(n).eastNorth; 104 double x = oldEastNorth.east() - pivot.eastNorth.east(); 105 double y = oldEastNorth.north() - pivot.eastNorth.north(); 106 double nx = sinPhi * x + cosPhi * y + pivot.eastNorth.east(); 107 double ny = -cosPhi * x + sinPhi * y + pivot.eastNorth.north(); 108 n.eastNorth = new EastNorth(nx, ny); 109 n.coor = Main.proj.eastNorth2latlon(n.eastNorth); 100 double x = oldEastNorth.east() - pivot.east(); 101 double y = oldEastNorth.north() - pivot.north(); 102 double nx = sinPhi * x + cosPhi * y + pivot.east(); 103 double ny = -cosPhi * x + sinPhi * y + pivot.north(); 104 n.setEastNorth(nx, ny); 110 105 if (setModified) 111 106 n.modified = true; 112 107 } … … 120 115 @Override public void undoCommand() { 121 116 for (Node n : objects) { 122 117 MoveCommand.OldState os = oldState.get(n); 123 n.eastNorth = os.eastNorth; 124 n.coor = os.latlon; 118 n.setEastNorth(os.eastNorth); 125 119 n.modified = os.modified; 126 120 } 127 121 }
