Ticket #691: intersection.patch
| File intersection.patch, 3.0 KB (added by , 18 years ago) |
|---|
-
DrawAction.java
313 313 case 0: 314 314 return; 315 315 case 2: 316 // algorithm used here is a bit clumsy, anyone's welcome to replace 317 // it by something else. All it does it compute the intersection between 318 // the two segments and adjust the node position. The code doesnt 316 // This computes the intersection between 317 // the two segments and adjusts the node position. 319 318 Iterator<Pair<Node,Node>> i = segs.iterator(); 320 319 Pair<Node,Node> seg = i.next(); 321 320 EastNorth A = seg.a.eastNorth; … … 324 323 EastNorth C = seg.a.eastNorth; 325 324 EastNorth D = seg.b.eastNorth; 326 325 326 double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north()); 327 328 // Check for parallel segments and do nothing if they are 329 // In practice this will probably only happen when a way has been duplicated 330 331 if (u == 0) return; 332 333 // q is a number between 0 and 1 334 // It is the point in the segment where the intersection occurs 335 // if the segment is scaled to lenght 1 336 337 double q=det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) 338 / u; 327 339 EastNorth intersection = new EastNorth( 328 det(det(A.east(), A.north(), B.east(), B.north()), A.east() - B.east(), 329 det(C.east(), C.north(), D.east(), D.north()), C.east() - D.east())/ 330 det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()), 331 det(det(A.east(), A.north(), B.east(), B.north()), A.north() - B.north(), 332 det(C.east(), C.north(), D.east(), D.north()), C.north() - D.north())/ 333 det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()) 334 ); 340 B.east() + q * (A.east() - B.east()), 341 B.north() + q * (A.north() - B.north())); 342 343 int snapToIntersectionThreshold=0; 344 try { snapToIntersectionThreshold = Integer.parseInt(Main.pref.get("edit.snap-intersection-threshold","10")); } catch (NumberFormatException x) {} 335 345 336 // only adjust to intersection if within 10pixel of mouse click; otherwise346 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise 337 347 // fall through to default action. 338 348 // (for semi-parallel lines, intersection might be miles away!) 339 if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < 10) {349 if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) { 340 350 n.eastNorth = intersection; 341 351 return; 342 352 } … … 349 359 double a = P.distance(B); 350 360 double b = P.distance(A); 351 361 double c = A.distance(B); 352 doubleq = (a - b + c) / (2*c);362 q = (a - b + c) / (2*c); 353 363 n.eastNorth = new EastNorth( 354 364 B.east() + q * (A.east() - B.east()), 355 365 B.north() + q * (A.north() - B.north()));
