# Changeset 1029 in josm

Ignore:
Timestamp:
2008-10-06T02:13:30+02:00 (16 years ago)
Message:
• introduced new config option snap-intersection-threshold (default:10) that controls how far away from an intersection you may click. Patch by <zorkos@…>, closes #691.
File:
1 edited

Unmodified
Added
Removed
• ## trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

 r1023 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 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()) ); // only adjust to intersection if within 10 pixel of mouse click; otherwise 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 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 b = P.distanceSq(A); double c = A.distanceSq(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()),
Note: See TracChangeset for help on using the changeset viewer.