Ignore:
Timestamp:
2008-10-06T02:13:30+02:00 (16 years ago)
Author:
framm
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

Legend:

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

    r1023 r1029  
    511511                        return;
    512512                case 2:
    513                         // algorithm used here is a bit clumsy, anyone's welcome to replace
    514                         // it by something else. All it does it compute the intersection between
    515                         // the two segments and adjust the node position. The code doesnt
     513                        // This computes the intersection between
     514                        // the two segments and adjusts the node position.
    516515                        Iterator<Pair<Node,Node>> i = segs.iterator();
    517516                        Pair<Node,Node> seg = i.next();
     
    522521                        EastNorth D = seg.b.eastNorth;
    523522
     523                        double u=det(B.east() - A.east(), B.north() - A.north(), C.east() - D.east(), C.north() - D.north());
     524                       
     525                        // Check for parallel segments and do nothing if they are
     526                        // In practice this will probably only happen when a way has been duplicated
     527                       
     528                        if (u == 0) return;
     529                       
     530                        // q is a number between 0 and 1
     531                        // It is the point in the segment where the intersection occurs
     532                        // if the segment is scaled to lenght 1
     533                       
     534                        double q = det(B.north() - C.north(), B.east() - C.east(), D.north() - C.north(), D.east() - C.east()) / u;
    524535                        EastNorth intersection = new EastNorth(
    525                                 det(det(A.east(), A.north(), B.east(), B.north()), A.east() - B.east(),
    526                                         det(C.east(), C.north(), D.east(), D.north()), C.east() - D.east())/
    527                                         det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north()),
    528                                 det(det(A.east(), A.north(), B.east(), B.north()), A.north() - B.north(),
    529                                         det(C.east(), C.north(), D.east(), D.north()), C.north() - D.north())/
    530                                         det(A.east() - B.east(), A.north() - B.north(), C.east() - D.east(), C.north() - D.north())
    531                         );
    532 
    533                         // only adjust to intersection if within 10 pixel of mouse click; otherwise
     536                                        B.east() + q * (A.east() - B.east()),
     537                                        B.north() + q * (A.north() - B.north()));
     538
     539                        int snapToIntersectionThreshold=0;
     540                        try { snapToIntersectionThreshold = Integer.parseInt(Main.pref.get("edit.snap-intersection-threshold","10")); } catch (NumberFormatException x) {}
     541
     542                        // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise
    534543                        // fall through to default action.
    535544                        // (for semi-parallel lines, intersection might be miles away!)
    536                         if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < 10) {
     545                        if (Main.map.mapView.getPoint(n.eastNorth).distance(Main.map.mapView.getPoint(intersection)) < snapToIntersectionThreshold) {
    537546                                n.eastNorth = intersection;
    538547                                return;
     
    547556                        double b = P.distanceSq(A);
    548557                        double c = A.distanceSq(B);
    549                         double q = (a - b + c) / (2*c);
     558            q = (a - b + c) / (2*c);
    550559                        n.eastNorth = new EastNorth(
    551560                                B.east() + q * (A.east() - B.east()),
Note: See TracChangeset for help on using the changeset viewer.