Index: src/tesselation.cpp
===================================================================
--- src/tesselation.cpp	(revision 498ea07d7fcc0fdeb6f45c601642ecac6893a4a2)
+++ src/tesselation.cpp	(revision 04b6f9c4cd8d885f794fa20c327103eb776d9cb1)
@@ -939,5 +939,5 @@
 TesselPoint::TesselPoint()
 {
-  Info FunctionInfo(__func__);
+  //Info FunctionInfo(__func__);
   node = NULL;
   nr = -1;
@@ -949,5 +949,5 @@
 TesselPoint::~TesselPoint()
 {
-  Info FunctionInfo(__func__);
+  //Info FunctionInfo(__func__);
 };
 
@@ -976,5 +976,5 @@
 PointCloud::PointCloud()
 {
-	Info FunctionInfo(__func__);
+	//Info FunctionInfo(__func__);
 };
 
@@ -983,5 +983,5 @@
 PointCloud::~PointCloud()
 {
-	Info FunctionInfo(__func__);
+	//Info FunctionInfo(__func__);
 };
 
@@ -1174,6 +1174,5 @@
  * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
  */
-void
-Tesselation::GuessStartingTriangle()
+void Tesselation::GuessStartingTriangle()
 {
 	Info FunctionInfo(__func__);
@@ -3378,10 +3377,9 @@
  * @param *LC LinkedCell structure
  *
- * @return >0 if outside, ==0 if on surface, <0 if inside (Note that distance can be at most LinkedCell::RADIUS.)
- */
-double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const
+ * @return >0 if outside, ==0 if on surface, <0 if inside
+ */
+double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
 {
   Info FunctionInfo(__func__);
-  class BoundaryTriangleSet *result = FindClosestTriangleToVector(&Point, LC);
   Vector Center;
   Vector helper;
@@ -3390,12 +3388,12 @@
   double distance = 0.;
 
-  if (result == NULL) {// is boundary point or only point in point cloud?
-    Log() << Verbose(1) << Point << " is the only point in vicinity." << endl;
-    return LC->RADIUS;
+  if (triangle == NULL) {// is boundary point or only point in point cloud?
+    Log() << Verbose(1) << "No triangle given!" << endl;
+    return -1.;
   } else {
-    Log() << Verbose(1) << "INFO: Closest triangle found is " << *result << " with normal vector " << result->NormalVector << "." << endl;
-  }
-
-  result->GetCenter(&Center);
+    Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;
+  }
+
+  triangle->GetCenter(&Center);
   Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;
   DistanceToCenter.CopyVector(&Center);
@@ -3404,12 +3402,12 @@
 
   // check whether we are on boundary
-  if (fabs(DistanceToCenter.ScalarProduct(&result->NormalVector)) < MYEPSILON) {
+  if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     // calculate whether inside of triangle
     DistanceToCenter.CopyVector(&Point);
     Center.CopyVector(&Point);
-    Center.SubtractVector(&result->NormalVector); // points towards MolCenter
-    DistanceToCenter.AddVector(&result->NormalVector); // points outside
+    Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
+    DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
     Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;
-    if (result->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
+    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
       Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;
       return 0.;
@@ -3420,10 +3418,9 @@
   } else {
     // calculate smallest distance
-    distance = result->GetClosestPointInsideTriangle(&Point, &Intersection);
+    distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
     Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;
-    distance = Min(distance, (LC->RADIUS*LC->RADIUS));
 
     // then check direction to boundary
-    if (DistanceToCenter.ScalarProduct(&result->NormalVector) > MYEPSILON) {
+    if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
       Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;
       return -distance;
@@ -3433,4 +3430,17 @@
     }
   }
+};
+
+/** Calculates distance to a tesselated surface.
+ * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
+ * \param &Point point to calculate distance from
+ * \param *LC needed for finding closest points fast
+ * \return distance squared to closest point on surface
+ */
+double Tesselation::GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const
+{
+  BoundaryTriangleSet *triangle = FindClosestTriangleToVector(&Point, LC);
+  const double distance = GetDistanceSquaredToTriangle(Point, triangle);
+  return Min(distance, LC->RADIUS);
 };
 
@@ -3695,5 +3705,5 @@
  * @return list of the all points linked to the provided one
  */
-list< TesselPointList *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
+ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
 {
 	Info FunctionInfo(__func__);
@@ -3811,5 +3821,5 @@
  * @return list of the closed paths
  */
-list<TesselPointList *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
+ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
 {
 	Info FunctionInfo(__func__);
