- Timestamp:
- 2007-10-15T01:34:39+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r388 r389 13 13 import java.util.HashMap; 14 14 import java.util.HashSet; 15 import java.util.Iterator; 15 16 import java.util.Map; 16 17 import java.util.Set; … … 224 225 } 225 226 227 /* 228 * Adjusts the position of a node to lie on a segment (or a segment 229 * intersection). 230 * 231 * If one or more than two segments are passed, the node is adjusted 232 * to lie on the first segment that is passed. 233 * 234 * If two segments are passed, the node is adjusted to be at their 235 * intersection. 236 * 237 * No action is taken if no segments are passed. 238 * 239 * @param segs the segments to use as a reference when adjusting 240 * @param n the node to adjust 241 */ 226 242 private static void adjustNode(Collection<NodePair> segs, Node n) { 227 // FIXME: find intersection if more than one seg. 228 if (segs.size() >= 1) { 229 EastNorth P = n.eastNorth; 230 NodePair seg = segs.iterator().next(); 243 244 switch (segs.size()) { 245 case 0: 246 return; 247 case 2: 248 // algorithm used here is a bit clumsy, anyone's welcome to replace 249 // it by something else. All it does it compute the intersection between 250 // the two segments and adjust the node position. The code doesnt 251 Iterator<NodePair> i = segs.iterator(); 252 NodePair seg = i.next(); 231 253 EastNorth A = seg.a.eastNorth; 232 254 EastNorth B = seg.b.eastNorth; 255 seg = i.next(); 256 EastNorth C = seg.a.eastNorth; 257 EastNorth D = seg.b.eastNorth; 258 259 EastNorth intersection = new EastNorth( 260 det(det(A.east(), A.north(), B.east(), B.north()), A.east() - B.east(), 261 det(C.east(), C.north(), D.east(), D.north()), C.east() - D.east())/ 262 det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()), 263 det(det(A.east(), A.north(), B.east(), B.north()), A.north() - B.north(), 264 det(C.east(), C.north(), D.east(), D.north()), C.north() - D.north())/ 265 det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()) 266 ); 267 268 // only adjust to intersection if within 10 pixel of mouse click; otherwise 269 // fall through to default action. 270 // (for semi-parallel lines, intersection might be miles away!) 271 if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < 10) { 272 n.eastNorth = intersection; 273 return; 274 } 275 276 default: 277 EastNorth P = n.eastNorth; 278 seg = segs.iterator().next(); 279 A = seg.a.eastNorth; 280 B = seg.b.eastNorth; 233 281 double a = P.distance(B); 234 282 double b = P.distance(A); … … 241 289 } 242 290 291 // helper for adjustNode 292 static double det(double a, double b, double c, double d) 293 { 294 return a * d - b * c; 295 } 296 297 243 298 @Override public String getModeHelpText() { 244 299 return "Click to add a new node. Ctrl: no node re-use/auto-insert. Shift: no auto-connect. Alt: new way";
Note:
See TracChangeset
for help on using the changeset viewer.
