Index: DrawAction.java
===================================================================
--- DrawAction.java	(revision 604)
+++ DrawAction.java	(working copy)
@@ -313,9 +313,8 @@
 		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<Pair<Node,Node>> i = segs.iterator();
 			Pair<Node,Node> seg = i.next();
 			EastNorth A = seg.a.eastNorth;
@@ -324,19 +323,30 @@
 			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;
 			}
@@ -349,7 +359,7 @@
 			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()));
