[GRASS-SVN] r53770 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 11 10:45:37 PST 2012


Author: mmetz
Date: 2012-11-11 10:45:36 -0800 (Sun, 11 Nov 2012)
New Revision: 53770

Modified:
   grass/trunk/lib/vector/Vlib/intersect.c
Log:
Vlib: optimization

Modified: grass/trunk/lib/vector/Vlib/intersect.c
===================================================================
--- grass/trunk/lib/vector/Vlib/intersect.c	2012-11-11 18:43:43 UTC (rev 53769)
+++ grass/trunk/lib/vector/Vlib/intersect.c	2012-11-11 18:45:36 UTC (rev 53770)
@@ -83,7 +83,7 @@
 #if 0
 static int ident(double x1, double y1, double x2, double y2, double thresh);
 #endif
-static int cross_seg(int id, struct RTree_Rect rect, int *arg);
+static int cross_seg(int id, const struct RTree_Rect *rect, int *arg);
 static int find_cross(int id, const struct RTree_Rect *rect, int *arg);
 
 #define D  ((ax2-ax1)*(by1-by2) - (ay2-ay1)*(bx1-bx2))
@@ -182,8 +182,8 @@
      *       Can it be a problem to set the tolerance to 0.0 ? */
     dtol = 0.0;
     if (fabs(d) > dtol) {
-	r1 = D1 / d;
-	r2 = D2 / d;
+	r1 = d1 / d;
+	r2 = d2 / d;
 
 	G_debug(2, " -> not parallel/collinear: r1 = %f, r2 = %f", r1, r2);
 
@@ -203,7 +203,7 @@
     /* segments are parallel or collinear */
     G_debug(3, " -> parallel/collinear");
 
-    if (D1 || D2) {		/* lines are parallel */
+    if (d1 || d2) {		/* lines are parallel */
 	G_debug(2, "  -> parallel");
 	return 0;
     }
@@ -542,7 +542,7 @@
 static struct line_pnts *APnts, *BPnts;
 
 /* break segments (called by rtree search) */
-static int cross_seg(int id, struct RTree_Rect rect, int *arg)
+static int cross_seg(int id, const struct RTree_Rect *rect, int *arg)
 {
     double x1, y1, z1, x2, y2, z2;
     int i, j, ret;
@@ -693,6 +693,7 @@
 
     /* Create rtree for B line */
     MyRTree = RTreeCreateTree(-1, 0, 2);
+    RTreeSetOverflow(MyRTree, 0);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];
@@ -767,6 +768,7 @@
     }
 
     /* Snap breaks to nearest vertices within RE threshold */
+    /* Calculate distances along segments */
     for (i = 0; i < n_cross; i++) {
 	/* 1. of A seg */
 	seg = cross[i].segment[0];
@@ -775,6 +777,8 @@
 	x = APoints->x[seg];
 	y = APoints->y[seg];
 
+	cross[i].distance[0] = curdist;
+
 	/* 2. of A seg */
 	dist =
 	    dist2(cross[i].x, cross[i].y, APoints->x[seg + 1],
@@ -789,12 +793,15 @@
 	seg = cross[i].segment[1];
 	dist =
 	    dist2(cross[i].x, cross[i].y, BPoints->x[seg], BPoints->y[seg]);
+	cross[i].distance[1] = dist;
+
 	if (dist < curdist) {
 	    curdist = dist;
 	    x = BPoints->x[seg];
 	    y = BPoints->y[seg];
 	}
-	dist = dist2(cross[i].x, cross[i].y, BPoints->x[seg + 1], BPoints->y[seg + 1]);	/* 2. of B seg */
+	/* 2. of B seg */
+	dist = dist2(cross[i].x, cross[i].y, BPoints->x[seg + 1], BPoints->y[seg + 1]);
 	if (dist < curdist) {
 	    curdist = dist;
 	    x = BPoints->x[seg + 1];
@@ -803,19 +810,17 @@
 	if (curdist < rethresh * rethresh) {
 	    cross[i].x = x;
 	    cross[i].y = y;
+
+	    /* Update distances along segments */
+	    seg = cross[i].segment[0];
+	    cross[i].distance[0] =
+		dist2(APoints->x[seg], APoints->y[seg], cross[i].x, cross[i].y);
+	    seg = cross[i].segment[1];
+	    cross[i].distance[1] =
+		dist2(BPoints->x[seg], BPoints->y[seg], cross[i].x, cross[i].y);
 	}
     }
 
-    /* Calculate distances along segments */
-    for (i = 0; i < n_cross; i++) {
-	seg = cross[i].segment[0];
-	cross[i].distance[0] =
-	    dist2(APoints->x[seg], APoints->y[seg], cross[i].x, cross[i].y);
-	seg = cross[i].segment[1];
-	cross[i].distance[1] =
-	    dist2(BPoints->x[seg], BPoints->y[seg], cross[i].x, cross[i].y);
-    }
-
     /* l = 1 ~ line A, l = 2 ~ line B */
     for (l = 1; l < 3; l++) {
 	for (i = 0; i < n_cross; i++)
@@ -1240,6 +1245,7 @@
 
     /* Create rtree for B line */
     MyRTree = RTreeCreateTree(-1, 0, 2);
+    RTreeSetOverflow(MyRTree, 0);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];



More information about the grass-commit mailing list