[GRASS-SVN] r45203 - grass/branches/develbranch_6/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 26 14:35:18 EST 2011


Author: mmetz
Date: 2011-01-26 11:35:17 -0800 (Wed, 26 Jan 2011)
New Revision: 45203

Modified:
   grass/branches/develbranch_6/lib/vector/Vlib/snap.c
Log:
snap to nearest anchor, not to first assigned anchor

Modified: grass/branches/develbranch_6/lib/vector/Vlib/snap.c
===================================================================
--- grass/branches/develbranch_6/lib/vector/Vlib/snap.c	2011-01-26 19:27:52 UTC (rev 45202)
+++ grass/branches/develbranch_6/lib/vector/Vlib/snap.c	2011-01-26 19:35:17 UTC (rev 45203)
@@ -209,10 +209,26 @@
 	    dy = XPnts[pointb].y - XPnts[point].y;
 	    dist2 = dx * dx + dy * dy;
 
-	    if (dist2 <= thresh2) {
+	    if (dist2 > thresh2) /* outside threshold */
+		continue;
+		
+	    /* doesn't have an anchor yet */
+	    if (XPnts[pointb].anchor == -1) {
 		XPnts[pointb].anchor = point;
 		ntosnap++;
 	    }
+	    else if (XPnts[pointb].anchor > 0) {   /* check distance to previously assigned anchor */
+		double dist2_a;
+
+		dx = XPnts[XPnts[pointb].anchor].x - XPnts[pointb].x;
+		dy = XPnts[XPnts[pointb].anchor].y - XPnts[pointb].y;
+		dist2_a = dx * dx + dy * dy;
+
+		/* replace old anchor */
+		if (dist2 < dist2_a) {
+		    XPnts[pointb].anchor = point;
+		}
+	    }
 	}
     }
 
@@ -454,7 +470,8 @@
 	if (!(ltype & type))
 	    continue;
 
-	Vect_list_append(List, line);
+	/* Vect_list_append(List, line); */
+	dig_list_add(List, line);
     }
 
     Vect_snap_lines_list(Map, List, thresh, Err);



More information about the grass-commit mailing list