Index: /issm/trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp	(revision 22457)
+++ /issm/trunk-jpl/src/c/modules/ExpToLevelSetx/ExpToLevelSetxt.cpp	(revision 22458)
@@ -47,4 +47,5 @@
 
 void ContourToLevelSet(double* dist,double* contourx, double* contoury, int contournods, double* x, double* y, int i0, int i1){/*{{{*/
+
 	double x0,y0;
 	double x1,y1;
@@ -68,8 +69,10 @@
 	}
 }
-double ddistance(double x1,double y1,double x2,double y2){ return sqrt(pow(x2-x1,2)+pow(y2-y1,2)); }
-double ddot(double x1, double y1, double x2, double y2){ return x1*x2+y1*y2; }
 double minimum_distance(double x1, double y1, double x2, double y2, double x0, double y0){
-	/* Return minimum distance between line segment [(x1,y1) (x2,y2)] and point (x0,y0) (v=(x1,y1), w=(x2,y2) and p=(x0,y0)*/
+	/* Return minimum distance between line segment [(x1,y1) (x2,y2)] and point (x0,y0)
+	 * We use the following notations:
+	 * segment: v=(x1,y1), w=(x2,y2)
+	 * point:   p=(x0,y0) 
+	 */
 
    /*Get segment length square (avoid sqrt) |w-v|^2*/
@@ -77,23 +80,22 @@
 
    /*segment is single point: v == w*/
-	if(l2 == 0.) return ddistance(x0,y0,x1,y1);
+	if(l2 == 0.) return sqrt(pow(x1-x0,2)+pow(y1-y0,2));
 
 	/*Consider the line extending the segment, parameterized as v + t (w - v).
-	We find projection of point p onto the line. 
-	It falls where t = [(p-v) . (w-v)] / |w-v|^2*/
-	double t = ddot(x0-x1,y0-y1, x2-x1, y2-y1) / l2;
+	We find projection of point p onto the line.  It falls where t = [(p-v) . (w-v)] / |w-v|^2*/
+	double t = ((x0-x1)*(x2-x1) + (y0-y1)*(y2-y1)) / l2;
 	if(t < 0.){
       /*Beyond the 'v' end of the segment*/
-      return ddistance(x0,y0, x1, y1);
+      return sqrt(pow(x1-x0,2)+pow(y1-y0,2));
    }
 	else if(t > 1.){
       /*Beyond the 'w' end of the segment*/
-      return ddistance(x0,y0, x2,y2);
+      return sqrt(pow(x2-x0,2)+pow(y2-y0,2));
    }
 	
-   /*Projection falls on segment!*/
-	double projectionx= x1 + t* (x2-x1);
-	double projectiony= y1 + t* (y2-y1);
-	return ddistance(x0, y0, projectionx, projectiony);
+   /*Projection falls on segment*/
+	double projx= x1 + t* (x2-x1);
+	double projy= y1 + t* (y2-y1);
+	return sqrt(pow(projx-x0,2)+pow(projy-y0,2));
 }
 /*}}}*/
