[GRASS-SVN] r64197 - grass/trunk/lib/vector/diglib
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 15 12:44:00 PST 2015
Author: mmetz
Date: 2015-01-15 12:44:00 -0800 (Thu, 15 Jan 2015)
New Revision: 64197
Modified:
grass/trunk/lib/vector/diglib/line_dist.c
Log:
diglib: add numerical stability to dig_distance2_point_to_line()
Modified: grass/trunk/lib/vector/diglib/line_dist.c
===================================================================
--- grass/trunk/lib/vector/diglib/line_dist.c 2015-01-15 20:37:27 UTC (rev 64196)
+++ grass/trunk/lib/vector/diglib/line_dist.c 2015-01-15 20:44:00 UTC (rev 64197)
@@ -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