[GRASS-SVN] r64198 - grass/branches/releasebranch_7_0/lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 15 12:44:16 PST 2015


Author: mmetz
Date: 2015-01-15 12:44:15 -0800 (Thu, 15 Jan 2015)
New Revision: 64198

Modified:
   grass/branches/releasebranch_7_0/lib/vector/diglib/line_dist.c
Log:
diglib: add numerical stability to dig_distance2_point_to_line()

Modified: grass/branches/releasebranch_7_0/lib/vector/diglib/line_dist.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/diglib/line_dist.c	2015-01-15 20:44:00 UTC (rev 64197)
+++ grass/branches/releasebranch_7_0/lib/vector/diglib/line_dist.c	2015-01-15 20:44:15 UTC (rev 64198)
@@ -80,19 +80,28 @@
 							       dy * dy +
 							       dz * dz);
 
-	if (t < 0.0) {		/* go to x1,y1,z1 */
-	    t = 0.0;
-	    st = -1;
+	if (t <= 0.0) {		/* go to x1,y1,z1 */
+	    if (t < 0.0) {
+		st = -1;
+	    }
+	    tpx = x1;
+	    tpy = y1;
+	    tpz = z1;
 	}
-	else if (t > 1.0) {	/* go to x2,y2,z2 */
-	    t = 1.0;
-	    st = 1;
+	else if (t >= 1.0) {	/* go to x2,y2,z2 */
+	    if (t > 1.0) {
+		st = 1;
+	    }
+	    tpx = x2;
+	    tpy = y2;
+	    tpz = z2;
 	}
-
-	/* go t from x1,y1,z1 towards x2,y2,z2 */
-	tpx = dx * t + x1;
-	tpy = dy * t + y1;
-	tpz = dz * t + z1;
+	else {
+	    /* go t from x1,y1,z1 towards x2,y2,z2 */
+	    tpx = dx * t + x1;
+	    tpy = dy * t + y1;
+	    tpz = dz * t + z1;
+	}
 	dx = tpx - x;
 	dy = tpy - y;
 	dz = tpz - z;



More information about the grass-commit mailing list