Index: src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 3613)
+++ src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(working copy)
@@ -193,7 +193,7 @@
                         initialN2en.getX() - en.getX(),
                         initialN2en.getY() - en.getY()));
             }
-            
+
             // Signifies that nothing has happened yet
             newN1en = null;
             newN2en = null;
@@ -305,9 +305,10 @@
 
                     //find if the new points overlap existing segments (in case of 90 degree angles)
                     Node prevNode = getPreviousNode(selectedSegment.lowerIndex);
-                    boolean nodeOverlapsSegment = prevNode != null && pointsColinear(prevNode.getEastNorth(), initialN1en, newN1en);
+                    boolean nodeOverlapsSegment = prevNode != null && segmentsParralel(initialN1en, prevNode.getEastNorth(), initialN1en, newN1en);
+                    boolean hasOtherWays = this.hasNodeOtherWays(selectedSegment.getFirstNode(), selectedSegment.way);
 
-                    if (nodeOverlapsSegment && !alwaysCreateNodes) {
+                    if (nodeOverlapsSegment && !alwaysCreateNodes && !hasOtherWays) {
                         //move existing node
                         Node n1Old = selectedSegment.getFirstNode();
                         cmds.add(new MoveCommand(n1Old, Main.proj.eastNorth2latlon(newN1en)));
@@ -321,9 +322,10 @@
 
                     //find if the new points overlap existing segments (in case of 90 degree angles)
                     Node nextNode = getNextNode(selectedSegment.lowerIndex + 1);
-                    nodeOverlapsSegment = nextNode != null && pointsColinear(nextNode.getEastNorth(), initialN2en, newN2en);
+                    nodeOverlapsSegment = nextNode != null && segmentsParralel(initialN2en, nextNode.getEastNorth(), initialN2en, newN2en);
+                    hasOtherWays = this.hasNodeOtherWays(selectedSegment.getFirstNode(), selectedSegment.way);
 
-                    if (nodeOverlapsSegment && !alwaysCreateNodes) {
+                    if (nodeOverlapsSegment && !alwaysCreateNodes && !hasOtherWays) {
                         //move existing node
                         Node n2Old = selectedSegment.getSecondNode();
                         cmds.add(new MoveCommand(n2Old, Main.proj.eastNorth2latlon(newN2en)));
@@ -361,6 +363,22 @@
         }
     }
 
+
+    /**
+     * This method tests if a node has other ways apart from the given one.
+     * @param node
+     * @param myWay
+     * @return true of node belongs only to myWay, false if there are more ways.
+     */
+    private boolean hasNodeOtherWays(Node node, Way myWay) {
+        for (OsmPrimitive p : node.getReferrers()) {
+            if (p instanceof Way && p.isUsable() && p!= myWay)
+                return true;
+        }
+
+        return false;
+    }
+
     /***
      * This method calculates offset amount by witch to move the given segment perpendicularly for it to be in line with mouse position.
      * @param segmentP1
@@ -368,28 +386,25 @@
      * @param targetPos
      * @return offset amount of P1 and P2.
      */
-    private static EastNorth calculateSegmentOffset(EastNorth segmentP1, EastNorth segmentP2 ,EastNorth moveDirection , EastNorth targetPos)
-    {
-        EastNorth intersectionPoint = getLineLineIntersection(
-                segmentP1,
-                segmentP2,
-                targetPos,
-                new EastNorth(targetPos.getX() + moveDirection.getX(), targetPos.getY() + moveDirection.getY()));
+    private static EastNorth calculateSegmentOffset(EastNorth segmentP1, EastNorth segmentP2, EastNorth moveDirection,
+            EastNorth targetPos) {
+        EastNorth intersectionPoint = getLineLineIntersection(segmentP1, segmentP2, targetPos, new EastNorth(targetPos
+                .getX()
+                + moveDirection.getX(), targetPos.getY() + moveDirection.getY()));
 
         if (intersectionPoint == null)
             return null;
         else
             //return distance form base to target position
-            return new EastNorth(targetPos.getX() - intersectionPoint.getX(), targetPos.getY() - intersectionPoint.getY());
+            return new EastNorth(targetPos.getX() - intersectionPoint.getX(), targetPos.getY()
+                    - intersectionPoint.getY());
     }
 
     /**
-     * Finds the intersection of two lines of inifinite length
-     * @return EastNorth null if no intersection was found, the Lon coordinates of the intersection otherwise
+     * Finds the intersection of two lines of inifinite length.
+     * @return EastNorth null if no intersection was found, the coordinates of the intersection otherwise
      */
-    static public EastNorth getLineLineIntersection(
-            EastNorth p1, EastNorth p2,
-            EastNorth p3, EastNorth p4) {
+    static public EastNorth getLineLineIntersection(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
 
         // Convert line from (point, point) form to ax+by=c
         double a1 = p2.getY() - p1.getY();
@@ -401,44 +416,58 @@
         double c2 = p4.getX() * p3.getY() - p3.getX() * p4.getY();
 
         // Solve the equations
-        double det = a1*b2 - a2*b1;
-        if(det == 0) return null; // Lines are parallel
+        double det = a1 * b2 - a2 * b1;
+        if (det == 0)
+            return null; // Lines are parallel
 
-        return new EastNorth(
-                (b1*c2 - b2*c1)/det,
-                (a2*c1 - a1*c2)/det);
+        return new EastNorth((b1 * c2 - b2 * c1) / det, (a2 * c1 - a1 * c2) / det);
     }
 
+    private static boolean segmentsParralel(EastNorth p1, EastNorth p2, EastNorth p3, EastNorth p4) {
+
+        // Convert line from (point, point) form to ax+by=c
+        double a1 = p2.getY() - p1.getY();
+        double b1 = p1.getX() - p2.getX();
+
+        double a2 = p4.getY() - p3.getY();
+        double b2 = p3.getX() - p4.getX();
+
+        // Solve the equations
+        double det = a1 * b2 - a2 * b1;
+        return Math.abs(det) < 1e-13;
+    }
+
     /**
-     * Returns true if all points are on the same line.
+     * Calcualtes closest point to a line segment.
+     * @param segmentP1
+     * @param segmentP2
+     * @param point
+     * @return segmentP1 if it is the closest point, segmentP2 if it is the closest point,
+     * a new point if closest point is between segmentP1 and segmentP2.
      */
-    private static boolean pointsColinear(EastNorth p1, EastNorth p2, EastNorth p3) {
+    private static EastNorth closestPointToSegment(EastNorth segmentP1, EastNorth segmentP2, EastNorth point) {
 
-        //the simple dumb way of triangle side lengths.
-        double distance1 = p1.distance(p2);
-        double distance2 = p1.distance(p3);
-        double distance3 = p2.distance(p3);
+        double ldx = segmentP2.getX() - segmentP1.getX();
+        double ldy = segmentP2.getY() - segmentP1.getY();
 
-        //sort so that distance 1 is the greatest
-        if (distance1 < distance2) {
-            double temp = distance1;
-            distance1 = distance2;
-            distance2 = temp;
-        }
+        if (ldx == 0 && ldy == 0) //segment zero length
+            return segmentP1;
 
-        if (distance1 < distance3) {
-            double temp = distance1;
-            distance1 = distance3;
-            distance3 = temp;
-        }
+        double pdx = point.getX() - segmentP1.getX();
+        double pdy = point.getY() - segmentP1.getY();
 
-        //test with some treshold
-        double difference = distance1 - distance2 - distance3;
+        double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy);
 
-        return (Math.abs(difference) < 1e-15);
+        if (offset <= 0)
+            return segmentP1;
+        else if (offset >= 1)
+            return segmentP2;
+        else
+            return new EastNorth(segmentP1.getX() + ldx * offset, segmentP1.getY() + ldy * offset);
 
     }
 
+
     /**
      * Gets a node from selected way before given index.
      * @param index  index of current node
