Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyHelper.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyHelper.java	(revision 7775)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyHelper.java	(revision 7776)
@@ -143,25 +143,19 @@
             ++i;
 
-            // Finding intersection of the segment with its altitude from p (c)
-            EastNorth altitudeIntersection = Geometry.getSegmentAltituteIntersection(wpp.a.getEastNorth(),
-                    wpp.b.getEastNorth(), pEN);
-
-            if (altitudeIntersection != null) {
-                // If the segment intersects with the altitude from p
-                currentDistance = pEN.distance(altitudeIntersection);
-
-                // Making an angle too big to let this candidate win any others
+            EastNorth a = wpp.a.getEastNorth();
+            EastNorth b = wpp.b.getEastNorth();
+            
+            // Finding intersection of the segment with its altitude from p
+            EastNorth altitudeIntersection = Geometry.closestPointToSegment(a, b, pEN);
+            currentDistance = pEN.distance(altitudeIntersection);
+            
+            if (!altitudeIntersection.equals(a) && !altitudeIntersection.equals(b)) {
+                // If the segment intersects with the altitude from p,
+                // make an angle too big to let this candidate win any others
                 // having the same distance.
                 currentAngle = Double.MAX_VALUE;
-
             } else {
-                // Otherwise: Distance is equal to the shortest distance from p
-                // to a or b
-                currentDistance = Math.min(pEN.distance(wpp.a.getEastNorth()),
-                        pEN.distance(wpp.b.getEastNorth()));
-
-                // Measuring the angle
-                currentAngle = Math.abs(Geometry.getCornerAngle(
-                        wpp.a.getEastNorth(), pEN, wpp.b.getEastNorth()));
+                // Otherwise measure the angle
+                currentAngle = Math.abs(Geometry.getCornerAngle(a, pEN, b));
             }
 
Index: trunk/src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 7775)
+++ trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 7776)
@@ -824,42 +824,4 @@
         double yC = inv12*b1 + inv22*b2;
         return new EastNorth(xC, yC);
-    }
-
-    /**
-     * Returns the coordinate of intersection of segment sp1-sp2 and an altitude
-     * to it starting at point ap. If the line defined with sp1-sp2 intersects
-     * its altitude out of sp1-sp2, null is returned.
-     *
-     * @param sp1
-     * @param sp2
-     * @param ap
-     * @return Intersection coordinate or null
-     */
-    public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) {
-
-        CheckParameterUtil.ensureValidCoordinates(sp1, "sp1");
-        CheckParameterUtil.ensureValidCoordinates(sp2, "sp2");
-        CheckParameterUtil.ensureValidCoordinates(ap, "ap");
-
-        Double segmentLenght = sp1.distance(sp2);
-        Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
-
-        // Taking a random point on the altitude line (angle is known).
-        EastNorth ap2 = new EastNorth(ap.east() + 1000
-                * Math.cos(altitudeAngle), ap.north() + 1000
-                * Math.sin(altitudeAngle));
-
-        // Finding the intersection of two lines
-        EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2,
-                ap, ap2);
-
-        // Filtering result
-        if (resultCandidate != null
-                && resultCandidate.distance(sp1) * .999 < segmentLenght
-                && resultCandidate.distance(sp2) * .999 < segmentLenght) {
-            return resultCandidate;
-        } else {
-            return null;
-        }
     }
 
