Index: molecuilder/src/tesselation.cpp
===================================================================
--- molecuilder/src/tesselation.cpp	(revision 3dea054386081f1f8d242f01fa90478d3f0a2780)
+++ molecuilder/src/tesselation.cpp	(revision 2495226744580cd906314ed3640dd9e680f09c3a)
@@ -3135,5 +3135,5 @@
   // for each point, check its lines, remember closest
   Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;
-  BoundaryLineSet *ClosestLine = NULL;
+  LineSet ClosestLines;
   double MinDistance = 1e+16;
   Vector BaseLineIntersection;
@@ -3157,13 +3157,14 @@
 
       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) {  // intersection would be outside, take closer endpoint
-        if ((lengthEndA < MinDistance) && (lengthEndA < lengthEndB)) {
-          ClosestLine = LineRunner->second;
-          MinDistance = lengthEndA;
-          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEndA << "." << endl;
-        } else if (lengthEndB < MinDistance) {
-          ClosestLine = LineRunner->second;
-          MinDistance = lengthEndB;
-          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is closer with " << lengthEndB << "." << endl;
-        } else {
+        const double lengthEnd = Min(lengthEndA, lengthEndB);
+        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
+          ClosestLines.clear();
+          ClosestLines.insert(LineRunner->second);
+          MinDistance = lengthEnd;
+          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;
+        } else if  (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
+          ClosestLines.insert(LineRunner->second);
+          Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;
+        } else { // line is worse
           Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl;
         }
@@ -3179,8 +3180,8 @@
           eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;
         }
-        if ((ClosestLine == NULL) || (distance < MinDistance)) {
-          ClosestLine = LineRunner->second;
+        if ((ClosestLines.empty()) || (distance < MinDistance)) {
+          ClosestLines.insert(LineRunner->second);
           MinDistance = distance;
-          Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;
+          Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;
         } else {
           Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;
@@ -3192,10 +3193,11 @@
 
   // check whether closest line is "too close" :), then it's inside
-  if (ClosestLine == NULL) {
+  if (ClosestLines.empty()) {
     Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;
     return NULL;
   }
   TriangleList * candidates = new TriangleList;
-  for (TriangleMap::iterator Runner = ClosestLine->triangles.begin(); Runner != ClosestLine->triangles.end(); Runner++) {
+  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
+    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
     candidates->push_back(Runner->second);
   }
