# Ticket #691: intersection.patch

File intersection.patch, 3.0 KB (added by zorkos@…, 15 years ago)
• ## DrawAction.java

 case 0: return; case 2: // algorithm used here is a bit clumsy, anyone's welcome to replace // it by something else. All it does it compute the intersection between // the two segments and adjust the node position. The code doesnt // This computes the intersection between // the two segments and adjusts the node position. Iterator> i = segs.iterator(); Pair seg = i.next(); EastNorth A = seg.a.eastNorth; EastNorth C = seg.a.eastNorth; EastNorth D = seg.b.eastNorth; double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north()); // Check for parallel segments and do nothing if they are // In practice this will probably only happen when a way has been duplicated if (u == 0) return; // q is a number between 0 and 1 // It is the point in the segment where the intersection occurs // if the segment is scaled to lenght 1 double q=det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u; EastNorth intersection = new EastNorth( det(det(A.east(), A.north(), B.east(), B.north()), A.east() - B.east(), det(C.east(), C.north(), D.east(), D.north()), C.east() - D.east())/ det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()), det(det(A.east(), A.north(), B.east(), B.north()), A.north() - B.north(), det(C.east(), C.north(), D.east(), D.north()), C.north() - D.north())/ det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()) ); B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north())); int snapToIntersectionThreshold=0; try { snapToIntersectionThreshold = Integer.parseInt(Main.pref.get("edit.snap-intersection-threshold","10")); } catch (NumberFormatException x) {} // only adjust to intersection if within 10 pixel of mouse click; otherwise // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise // fall through to default action. // (for semi-parallel lines, intersection might be miles away!) if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < 10) { if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) { n.eastNorth = intersection; return; } double a = P.distance(B); double b = P.distance(A); double c = A.distance(B); double q = (a - b + c) / (2*c); q = (a - b + c) / (2*c); n.eastNorth = new EastNorth( B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()));