Index: src/org/openstreetmap/josm/data/gpx/GpxDistance.java
===================================================================
--- src/org/openstreetmap/josm/data/gpx/GpxDistance.java	(revision 14995)
+++ src/org/openstreetmap/josm/data/gpx/GpxDistance.java	(working copy)
@@ -31,7 +31,7 @@
      */
     public static double getLowestDistance(OsmPrimitive p, GpxData gpxData) {
         return gpxData.getTrackPoints()
-                .mapToDouble(tp -> getDistance(p, tp))
+                .mapToDouble(tp -> Geometry.getDistance(p, new Node(tp.getCoor())))
                 .filter(x -> x >= 0)
                 .min().orElse(Double.MAX_VALUE);
     }
@@ -41,16 +41,12 @@
      * @param p OsmPrimitive to get the distance to the WayPoint
      * @param waypoint WayPoint to get the distance from
      * @return The shortest distance between p and waypoint
+     * @deprecated Use {@code Geometry.getDistance(p, new Node(waypoint.getCoor()))}
+     * instead
      */
+    @Deprecated
     public static double getDistance(OsmPrimitive p, WayPoint waypoint) {
-        if (p instanceof Node) {
-            return getDistanceNode((Node) p, waypoint);
-        } else if (p instanceof Way) {
-            return getDistanceWay((Way) p, waypoint);
-        } else if (p instanceof Relation) {
-            return getDistanceRelation((Relation) p, waypoint);
-        }
-        return Double.MAX_VALUE;
+        return Geometry.getDistance(p, new Node(waypoint.getCoor()));
     }
 
     /**
@@ -58,7 +54,10 @@
      * @param relation Relation to get the distance from
      * @param waypoint WayPoint to get the distance to
      * @return The distance between the relation and the waypoint
+     * @deprecated Use {@code Geometry.getDistance(relation, new Node(waypoint.getCoor()))}
+     * instead
      */
+    @Deprecated
     public static double getDistanceRelation(Relation relation, WayPoint waypoint) {
         double shortestDistance = Double.MAX_VALUE;
         List<Node> nodes = new ArrayList<>(relation.getMemberPrimitives(Node.class));
@@ -85,32 +84,12 @@
      * @param way Way to get the distance from
      * @param waypoint WayPoint to get the distance to
      * @return The distance between the way and the waypoint
+     * @deprecated Use {@code Geometry.getDistanceWayNode(way, new Node(waypoint.getCoor()))} instead
      */
+    @Deprecated
     public static double getDistanceWay(Way way, WayPoint waypoint) {
-        double shortestDistance = Double.MAX_VALUE;
-        if (way == null || waypoint == null) return shortestDistance;
-        LatLon llwaypoint = waypoint.getCoor();
-        EastNorth enwaypoint = new EastNorth(llwaypoint.getY(), llwaypoint.getX());
-        for (int i = 0; i < way.getNodesCount() - 1; i++) {
-            double distance = Double.MAX_VALUE;
-            LatLon llfirst = way.getNode(i).getCoor();
-            LatLon llsecond = way.getNode(i + 1).getCoor();
-            EastNorth first = new EastNorth(llfirst.getY(), llfirst.getX());
-            EastNorth second = new EastNorth(llsecond.getY(), llsecond.getX());
-            if (first.isValid() && second.isValid()) {
-                EastNorth closestPoint = Geometry.closestPointToSegment(first, second, enwaypoint);
-                distance = llwaypoint.greatCircleDistance(new LatLon(closestPoint.getX(), closestPoint.getY()));
-            } else if (first.isValid() && !second.isValid()) {
-                distance = getDistanceEastNorth(first, waypoint);
-            } else if (!first.isValid() && second.isValid()) {
-                distance = getDistanceEastNorth(second, waypoint);
-            } else if (!first.isValid() && !second.isValid()) {
-                distance = Double.MAX_VALUE;
-            }
-            if (distance < shortestDistance) shortestDistance = distance;
-
-        }
-        return shortestDistance;
+        if (way == null || waypoint == null) return Double.MAX_VALUE;
+        return Geometry.getDistanceWayNode(way, new Node(waypoint.getCoor()));
     }
 
     /**
@@ -118,10 +97,13 @@
      * @param node Node to get the distance from
      * @param waypoint WayPoint to get the distance to
      * @return The distance between the two points
+     * @deprecated Use {@code Geometry.getDistance(node, new Node(waypoint.getCoor()))}
+     * instead
      */
+    @Deprecated
     public static double getDistanceNode(Node node, WayPoint waypoint) {
-        if (node == null) return Double.MAX_VALUE;
-        return getDistanceLatLon(node.getCoor(), waypoint);
+        if (node == null || waypoint == null) return Double.MAX_VALUE;
+        return Geometry.getDistance(node, new Node(waypoint.getCoor()));
     }
 
     /**
@@ -129,10 +111,12 @@
      * @param en The EastNorth to get the distance to
      * @param waypoint WayPoint to get the distance to
      * @return The distance between the two points
+     * @deprecated Use {@code Geometry.getDistance(new Node(en), new Node(waypoint.getCoor()))} instead
      */
+    @Deprecated
     public static double getDistanceEastNorth(EastNorth en, WayPoint waypoint) {
-        if (en == null || !en.isValid()) return Double.MAX_VALUE;
-        return getDistanceLatLon(new LatLon(en.getY(), en.getX()), waypoint);
+        if (en == null || waypoint == null) return Double.MAX_VALUE;
+        return Geometry.getDistance(new Node(en), new Node(waypoint.getCoor()));
     }
 
     /**
@@ -140,9 +124,11 @@
      * @param latlon LatLon to get the distance from
      * @param waypoint WayPoint to get the distance to
      * @return The distance between the two points
+     * @deprecated Use {@code Geometry.getDistance(new Node(latlon), new Node(waypoint.getCoor()))} instead
      */
+    @Deprecated
     public static double getDistanceLatLon(LatLon latlon, WayPoint waypoint) {
         if (latlon == null || waypoint == null || waypoint.getCoor() == null) return Double.MAX_VALUE;
-        return waypoint.getCoor().greatCircleDistance(latlon);
+        return Geometry.getDistance(new Node(latlon), new Node(waypoint.getCoor()));
     }
 }
Index: src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- src/org/openstreetmap/josm/tools/Geometry.java	(revision 14995)
+++ src/org/openstreetmap/josm/tools/Geometry.java	(working copy)
@@ -8,9 +8,11 @@
 import java.math.BigDecimal;
 import java.math.MathContext;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.EnumSet;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -30,8 +32,10 @@
 import org.openstreetmap.josm.data.osm.MultipolygonBuilder.JoinedPolygon;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.NodePositionComparator;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
 import org.openstreetmap.josm.data.projection.Projection;
@@ -44,6 +48,8 @@
  * @author viesturs
  */
 public final class Geometry {
+    /** A holding map to store calculated {@link WaySegment}s in */
+    static final HashMap<Way, List<WaySegment>> waySegments = new HashMap<>();
 
     private Geometry() {
         // Hide default constructor for utils classes
@@ -1070,4 +1076,278 @@
         }
         return new AreaAndPerimeter(Math.abs(area) / 2, perimeter);
     }
+
+    /**
+     * Get the closest primitive to {@code osm} from the collection of OsmPrimitive {@code primitives}
+     * @param osm The primitive to get the distances from
+     * @param primitives The collection of primitives to get the distance to
+     * @return The closest {@code OsmPrimitive}
+     * @since xxx
+     */
+    public static OsmPrimitive getClosestPrimitive(OsmPrimitive osm, Collection<OsmPrimitive> primitives) {
+        double lowestDistance = Double.MAX_VALUE;
+        OsmPrimitive closest = null;
+        for (OsmPrimitive primitive : primitives) {
+            double distance = getDistance(osm, primitive);
+            if (distance < lowestDistance) {
+                lowestDistance = distance;
+                closest = primitive;
+            }
+        }
+        clearCachedWaySegments(primitives.toArray(new Way[0]));
+        return closest;
+    }
+
+    /**
+     * Get the furthest primitive to {@code osm} from the collection of OsmPrimitive {@code primitives}
+     * @param osm The primitive to get the distances from
+     * @param primitives The collection of primitives to get the distance to
+     * @return The furthest {@code OsmPrimitive}
+     * @since xxx
+     */
+    public static OsmPrimitive getFurthestPrimitive(OsmPrimitive osm, Collection<OsmPrimitive> primitives) {
+        double furthestDistance = Double.NEGATIVE_INFINITY;
+        OsmPrimitive furthest = null;
+        for (OsmPrimitive primitive : primitives) {
+            double distance = getDistance(osm, primitive);
+            if (distance > furthestDistance) {
+                furthestDistance = distance;
+                furthest = primitive;
+            }
+        }
+        clearCachedWaySegments(primitives.toArray(new Way[0]));
+        return furthest;
+    }
+
+    /**
+     * Get the distance between different {@code OsmPrimitive}s
+     * @param one The primitive to get the distance from
+     * @param two The primitive to get the distance to
+     * @return The distance between the primitives
+     * @since xxx
+     */
+    public static double getDistance(OsmPrimitive one, OsmPrimitive two) {
+        double rValue = Double.MAX_VALUE;
+        if (one == null || two == null) return rValue;
+        if (one instanceof Node && two instanceof Node) {
+            rValue = ((Node) one).getCoor().greatCircleDistance(((Node) two).getCoor());
+        } else if (one instanceof Node && two instanceof Way) {
+            rValue = getDistanceWayNode((Way) two, (Node) one);
+        } else if (one instanceof Way && two instanceof Node) {
+            rValue = getDistanceWayNode((Way) one, (Node) two);
+        } else if (one instanceof Way && two instanceof Way) {
+            rValue = getDistanceWayWay((Way) one, (Way) two);
+        } else if (one instanceof Relation && !(two instanceof Relation)) {
+            for (OsmPrimitive osmPrimitive: ((Relation) one).getMemberPrimitives()) {
+                double currentDistance = getDistance(osmPrimitive, two);
+                if (currentDistance < rValue) rValue = currentDistance;
+            }
+        } else if (!(one instanceof Relation) && two instanceof Relation) {
+            for (OsmPrimitive osmPrimitive : ((Relation) two).getMemberPrimitives()) {
+                double currentDistance = getDistance(osmPrimitive, one);
+                if (currentDistance < rValue) rValue = currentDistance;
+            }
+        } else if (one instanceof Relation && two instanceof Relation) {
+            for (OsmPrimitive osmPrimitive1 : ((Relation) one).getMemberPrimitives()) {
+                for (OsmPrimitive osmPrimitive2 : ((Relation) two).getMemberPrimitives()) {
+                    double currentDistance = getDistance(osmPrimitive1, osmPrimitive2);
+                    if (currentDistance < rValue) rValue = currentDistance;
+                }
+            }
+        }
+        return rValue;
+    }
+
+    /**
+     * Get the distance between a way and a node
+     * @param way The way to get the distance from
+     * @param node The node to get the distance to
+     * @return The distance between the {@code way} and the {@code node}
+     * @since xxx
+     */
+    public static double getDistanceWayNode(Way way, Node node) {
+        double rValue = Double.MAX_VALUE;
+        if (way.getNodesCount() < 2) return rValue;
+        List<WaySegment> segments = getWaySegments(way);
+        for (WaySegment segment : segments) {
+            EastNorth point = Geometry.closestPointToSegment(segment.getFirstNode().getEastNorth(), segment.getSecondNode().getEastNorth(), node.getEastNorth());
+            double distance = point.distance(node.getEastNorth());
+            if (distance < rValue) rValue = distance;
+        }
+        return rValue;
+    }
+
+    /**
+     * Get the closest {@code WaySegment} from a way to a primitive
+     * @param way The {@code Way} to get the distance from and the {@code WaySegment}
+     * @param primitive The {@code Primitive} to get the distance to
+     * @return The {@code WaySegment} that is closest to {@code primitive} from {@code way}
+     * @since xxx
+     */
+    public static WaySegment getClosestWaySegment(Way way, OsmPrimitive primitive) {
+        List<WaySegment> segments = getWaySegments(way);
+        double lowestDistance = Double.MAX_VALUE;
+        WaySegment closest = null;
+        for (WaySegment segment : segments) {
+            double distance = getDistance(segment.toWay(), primitive);
+            if (distance < lowestDistance) {
+                lowestDistance = distance;
+                closest = segment;
+            }
+        }
+        return closest;
+    }
+
+    /**
+     * Get the distance between different ways
+     * @param one The way to get the distance from
+     * @param two The {@code Way} to get the distance to
+     * @return The shortest distance between the ways
+     * @since xxx
+     */
+    public static double getDistanceWayWay(Way one, Way two) {
+        double rValue = Double.MAX_VALUE;
+        List<WaySegment> oneSegments = getWaySegments(one);
+        List<WaySegment> twoSegments = getWaySegments(two);
+        for (WaySegment oneSegment : oneSegments) {
+            for (WaySegment twoSegment : twoSegments) {
+                EastNorth en1 = oneSegment.getFirstNode().getEastNorth();
+                EastNorth en2 = oneSegment.getSecondNode().getEastNorth();
+                EastNorth en3 = twoSegment.getFirstNode().getEastNorth();
+                EastNorth en4 = twoSegment.getSecondNode().getEastNorth();
+                if (en1 == null || en2 == null || en3 == null || en4 == null) continue;
+                EastNorth intersection = Geometry.getSegmentSegmentIntersection(
+                        en1, en2, en3, en4);
+                if (intersection != null) return 0.0;
+                double distance = getDistanceSegmentSegment(oneSegment, twoSegment);
+                if (distance < rValue) rValue = distance;
+            }
+        }
+        return rValue;
+    }
+
+    /**
+     * Get the distance between different {@code WaySegment}s
+     * @param one A {@code WaySegment} to get the distance from
+     * @param two A {@code WaySegment} to get the distance to
+     * @return The distance between the two {@code WaySegment}s
+     * @since xxx
+     */
+    public static double getDistanceSegmentSegment(WaySegment one, WaySegment two) {
+        EastNorth vectorOne = one.getSecondNode().getEastNorth().subtract(one.getFirstNode().getEastNorth());
+        EastNorth vectorTwo = two.getSecondNode().getEastNorth().subtract(two.getFirstNode().getEastNorth());
+        EastNorth vectorThree = one.getFirstNode().getEastNorth().subtract(two.getFirstNode().getEastNorth());
+        double smallNumber = 0.00000000001;
+        double a = dot(vectorOne, vectorOne);
+        double b = dot(vectorOne, vectorTwo);
+        double c = dot(vectorTwo, vectorTwo);
+        double d = dot(vectorOne, vectorThree);
+        double e = dot(vectorTwo, vectorThree);
+
+        double dotCombination = a * c - b * b;
+        double sc;
+        double sN;
+        double sD = d;
+        double tc;
+        double tN;
+        double tD = dotCombination;
+        if (dotCombination < smallNumber) {
+            sN = 0.0;
+            sD = 1.0;
+            tN = e;
+            tD = c;
+        } else {
+            sN = (b * e - c * d);
+            tN = (a * e - b * d);
+            if (sN < 0.0) {
+                sN = 0.0;
+                tN = e;
+                tD = c;
+            } else if (sN > sD) {
+                sN = sD;
+                tN = e + b;
+                tD = c;
+            }
+        }
+
+        if (tN < 0.0) {
+            tN = 0.0;
+            if (-d < 0.0) sN = 0.0;
+            else if (-d > a) sN = sD;
+            else {
+                sN = -d;
+                sD = a;
+            }
+        } else if (tN > tD) {
+            tN = tD;
+            if ((-d + b) < 0.0) sN = 0;
+            else if ((-d + b) > a) sN = sD;
+            else {
+                sN = (-d + b);
+                sD = a;
+            }
+        }
+        sc = Math.abs(sN) < smallNumber ? 0.0 : sN / sD;
+        tc = Math.abs(tN) < smallNumber ? 0.0 : tN / tD;
+        EastNorth p1 = one.getFirstNode().getEastNorth().interpolate(one.getSecondNode().getEastNorth(), sc);
+        EastNorth p2 = two.getFirstNode().getEastNorth().interpolate(two.getSecondNode().getEastNorth(), tc);
+        return p1.distance(p2);
+    }
+
+    /**
+     * Get the dot product of two different EastNorth points
+     * @param one The originating EastNorth
+     * @param two The final EastNorth
+     * @return the dot product of the EastNorths
+     * @since xxx
+     */
+    public static double dot(EastNorth one, EastNorth two) {
+        return two.getX() * one.getX() + one.getY() * two.getY();
+    }
+
+    /**
+     * Get the way segments of a way
+     * @param way The way to get the way segments of
+     * @return A list of {@code WaySegment}s
+     * @since xxx
+     */
+    public static List<WaySegment> getWaySegments(Way way) {
+        synchronized (waySegments) {
+            if (waySegments.containsKey(way) && !way.isModified())
+                return waySegments.get(way);
+        }
+        List<WaySegment> segments = new ArrayList<>();
+        int i = 0;
+        do {
+            segments.add(new WaySegment(way, i));
+            i++;
+        } while (i < way.getNodesCount() - 2);
+        synchronized (waySegments) {
+            waySegments.put(way, segments);
+        }
+        return segments;
+    }
+
+    /**
+     * Call to clear cached way segments for performance
+     * @since xxx
+     */
+    public static void clearCachedWaySegments() {
+        synchronized (waySegments) {
+            waySegments.clear();
+        }
+    }
+
+    /**
+     * Clear the cached way segments of a way
+     * @param ways The ways to remove from the cached way segments
+     * @since xxx
+     */
+    public static void clearCachedWaySegments(Way... ways) {
+        synchronized (waySegments) {
+            for (Way way : ways) {
+                waySegments.remove(way);
+            }
+        }
+    }
 }
Index: test/unit/org/openstreetmap/josm/tools/GeometryTest.java
===================================================================
--- test/unit/org/openstreetmap/josm/tools/GeometryTest.java	(revision 14995)
+++ test/unit/org/openstreetmap/josm/tools/GeometryTest.java	(working copy)
@@ -4,6 +4,7 @@
 import static org.junit.Assert.assertEquals;
 
 import java.io.FileInputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -15,7 +16,9 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.RelationMember;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.io.OsmReader;
@@ -158,4 +161,117 @@
         assertEquals(new EastNorth(125, 300), Geometry.getCentroidEN(Arrays.asList(en1, en2)));
         assertEquals(new EastNorth(150, 266d + 2d/3d), Geometry.getCentroidEN(Arrays.asList(en1, en2, en3)));
     }
+
+    /**
+     * Test of {@link Geometry#getDistance} method.
+     */
+    @Test
+    public void testGetDistance() {
+        Node node1 = new Node(new LatLon(0, 0));
+        Node node2 = new Node(new LatLon(0, 1));
+        Node node3 = new Node(new LatLon(1, 0));
+        Node node4 = new Node(new LatLon(1, 1));
+        Way way1 = TestUtils.newWay("", node1, node2);
+        Way way2 = TestUtils.newWay("", node3, node4);
+        Relation testRelation1 = new Relation();
+        Relation testRelation2 = new Relation();
+        testRelation1.addMember(new RelationMember("", way1));
+        testRelation1.addMember(new RelationMember("", way2));
+        testRelation2.addMember(new RelationMember("", node1));
+        testRelation2.addMember(new RelationMember("", node2));
+        testRelation2.addMember(new RelationMember("", node3));
+        testRelation2.addMember(new RelationMember("", node4));
+
+        double distance = Geometry.getDistance(null, node3);
+        assertEquals(Double.MAX_VALUE, distance, 0.1);
+
+        distance = Geometry.getDistance(way1, null);
+        assertEquals(Double.MAX_VALUE, distance, 0.1);
+
+        distance = Geometry.getDistance(null, null);
+        assertEquals(Double.MAX_VALUE, distance, 0.1);
+
+        distance = Geometry.getDistance(node1, node2);
+        assertEquals(111319.49079327357, distance, 0.1);
+
+        distance = Geometry.getDistance(way1, node3);
+        assertEquals(111325.1428663855, distance, 0.1);
+
+        distance = Geometry.getDistance(node3, way1);
+        assertEquals(111325.1428663855, distance, 0.1);
+
+        distance = Geometry.getDistance(way1, way2);
+        assertEquals(111325.1428663855, distance, 0.1);
+
+        distance = Geometry.getDistance(testRelation1, new Node(new LatLon(0, 0.5)));
+        assertEquals(0.0, distance, 0.1);
+
+        distance = Geometry.getDistance(new Node(new LatLon(0, 0.5)), testRelation1);
+        assertEquals(0.0, distance, 0.1);
+
+        distance = Geometry.getDistance(testRelation1, testRelation2);
+        assertEquals(0.0, distance, 0.1);
+    }
+
+    /**
+     * Test of {@link Geometry#getClosestPrimitive} method
+     */
+    @Test
+    public void testGetClosestPrimitive() {
+        Node node1 = new Node(new LatLon(0, 0));
+        Node node2 = new Node(new LatLon(0, 1));
+        Node node3 = new Node(new LatLon(1, 0));
+        Node node4 = new Node(new LatLon(1, 1));
+        Way way1 = TestUtils.newWay("", node1, node2);
+        Way way2 = TestUtils.newWay("", node3, node4);
+
+        List<OsmPrimitive> primitives = new ArrayList<>();
+        primitives.add(way1);
+        primitives.add(way2);
+        OsmPrimitive closest = Geometry.getClosestPrimitive(node1, primitives);
+        assertEquals(way1, closest);
+    }
+
+    /**
+     * Test of {@link Geometry#getFurthestPrimitive} method
+     */
+    @Test
+    public void testGetFurthestPrimitive() {
+        Node node1 = new Node(new LatLon(0, 0));
+        Node node2 = new Node(new LatLon(0, 1));
+        Node node3 = new Node(new LatLon(1, 0));
+        Node node4 = new Node(new LatLon(1, 1));
+        Way way1 = TestUtils.newWay("", node1, node2);
+        Way way2 = TestUtils.newWay("", node3, node4);
+        Way way3 = TestUtils.newWay("", node2, node4);
+        Way way4 = TestUtils.newWay("", node1, node3);
+
+        List<OsmPrimitive> primitives = new ArrayList<>();
+        primitives.add(way1);
+        OsmPrimitive furthest = Geometry.getFurthestPrimitive(new Node(new LatLon(0, 0.75)), primitives);
+        assertEquals(way1, furthest);
+        primitives.add(way2);
+        primitives.add(way3);
+        primitives.add(way4);
+        furthest = Geometry.getFurthestPrimitive(new Node(new LatLon(0, 0.5)), primitives);
+        assertEquals(way2, furthest);
+        furthest = Geometry.getFurthestPrimitive(new Node(new LatLon(.25, 0.5)), primitives);
+        assertEquals(way2, furthest);
+    }
+
+    /**
+     * Test of {@link Geometry#getClosestWaySegment} method
+     */
+    @Test
+    public void testGetClosestWaySegment() {
+        Node node1 = new Node(new LatLon(0, 0));
+        Node node2 = new Node(new LatLon(0, 1));
+        Node node3 = new Node(new LatLon(1, 0));
+        Node node4 = new Node(new LatLon(1, 1));
+        Way way1 = TestUtils.newWay("", node1, node2, node3, node4);
+
+        Way closestSegment = Geometry.getClosestWaySegment(way1, new Node(new LatLon(0, 0.5))).toWay();
+        Assert.assertTrue(closestSegment.containsNode(node1));
+        Assert.assertTrue(closestSegment.containsNode(node2));
+    }
 }
