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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 8 04:45:35 EDT 2011


Author: mmetz
Date: 2011-04-08 01:45:35 -0700 (Fri, 08 Apr 2011)
New Revision: 45874

Modified:
   grass/trunk/lib/vector/Vlib/buffer2.c
   grass/trunk/lib/vector/Vlib/dgraph.c
   grass/trunk/lib/vector/Vlib/e_intersect.c
Log:
vector lib update for v.buffer (backport from devbr)

Modified: grass/trunk/lib/vector/Vlib/buffer2.c
===================================================================
--- grass/trunk/lib/vector/Vlib/buffer2.c	2011-04-08 08:33:37 UTC (rev 45873)
+++ grass/trunk/lib/vector/Vlib/buffer2.c	2011-04-08 08:45:35 UTC (rev 45874)
@@ -481,7 +481,7 @@
 
     /* close the output line */
     Vect_append_point(nPoints, nPoints->x[0], nPoints->y[0], nPoints->z[0]);
-    /*    Vect_line_prune ( nPoints ); */
+    Vect_line_prune ( nPoints );
 }
 
 /*
@@ -586,7 +586,7 @@
 	    break;
 	if (opt_side == 1) {
 	    if (vert->edges[opt_j]->visited_right) {
-		G_warning(_("Next edge was visited but it is not the first one !!! breaking loop"));
+		G_warning(_("Next edge was visited (right) but it is not the first one !!! breaking loop"));
 		G_debug(4,
 			"ec: v0=%d, v=%d, eside=%d, edge->v1=%d, edge->v2=%d",
 			v, (edge->v1 == v) ? (edge->v2) : (edge->v1),
@@ -597,7 +597,7 @@
 	}
 	else {
 	    if (vert->edges[opt_j]->visited_left) {
-		G_warning(_("Next edge was visited but it is not the first one !!! breaking loop"));
+		G_warning(_("Next edge was visited (left) but it is not the first one !!! breaking loop"));
 		G_debug(4,
 			"ec: v0=%d, v=%d, eside=%d, edge->v1=%d, edge->v2=%d",
 			v, (edge->v1 == v) ? (edge->v2) : (edge->v1),
@@ -616,6 +616,7 @@
 	eangle = vert0->angles[opt_j];
     }
     Vect_append_point(nPoints, vert->x, vert->y, 0);
+    Vect_line_prune(nPoints);
     G_debug(4, "ec: append point x=%.18f y=%.18f", vert->x, vert->y);
 
     return;
@@ -881,14 +882,32 @@
     res = extract_inner_contour(pg2, &winding, cPoints);
     while (res != 0) {
 	if (winding == 0) {
-	    if (!Vect_point_in_poly(cPoints->x[0], cPoints->y[0], area_outer)) {
-		if (Vect_get_point_in_poly(cPoints, &px, &py) != 0)
-		    G_fatal_error(_("Vect_get_point_in_poly() failed"));
-		if (!point_in_buf(area_outer, px, py, da, db, dalpha)) {
-		    add_line_to_array(cPoints, &arrPoints, &count, &allocated,
-				      more);
-		    cPoints = Vect_new_line_struct();
+	    int check_poly = 1;
+	    double area_size;
+
+	    dig_find_area_poly(cPoints, &area_size);
+	    if (area_size == 0) {
+		G_warning(_("zero area size"));
+		check_poly = 0;
+	    }
+	    if (cPoints->x[0] != cPoints->x[cPoints->n_points - 1] ||
+		cPoints->y[0] != cPoints->y[cPoints->n_points - 1]) {
+
+		G_warning(_("Line was not closed"));
+		check_poly = 0;
+	    }
+
+	    if (check_poly && !Vect_point_in_poly(cPoints->x[0], cPoints->y[0], area_outer)) {
+		if (Vect_get_point_in_poly(cPoints, &px, &py) == 0) {
+		    if (!point_in_buf(area_outer, px, py, da, db, dalpha)) {
+			add_line_to_array(cPoints, &arrPoints, &count, &allocated,
+					  more);
+			cPoints = Vect_new_line_struct();
+		    }
 		}
+		else {
+		    G_warning(_("Vect_get_point_in_poly() failed"));
+		}
 	    }
 	}
 	res = extract_inner_contour(pg2, &winding, cPoints);
@@ -910,18 +929,36 @@
 	res = extract_inner_contour(pg2, &winding, cPoints);
 	while (res != 0) {
 	    if (winding == -1) {
+		int check_poly = 1;
+		double area_size;
+
+		dig_find_area_poly(cPoints, &area_size);
+		if (area_size == 0) {
+		    G_warning(_("zero area size"));
+		    check_poly = 0;
+		}
+		if (cPoints->x[0] != cPoints->x[cPoints->n_points - 1] ||
+		    cPoints->y[0] != cPoints->y[cPoints->n_points - 1]) {
+
+		    G_warning(_("Line was not closed"));
+		    check_poly = 0;
+		}
+
 		/* we need to check if the area is in the buffer.
 		   I've simplfied convolution_line(), so that it runs faster,
 		   however that leads to ocasional problems */
-		if (Vect_point_in_poly
+		if (check_poly && Vect_point_in_poly
 		    (cPoints->x[0], cPoints->y[0], area_isles[i])) {
-		    if (Vect_get_point_in_poly(cPoints, &px, &py) != 0)
-			G_fatal_error(_("Vect_get_point_in_poly() failed"));
-		    if (!point_in_buf(area_isles[i], px, py, da, db, dalpha)) {
-			add_line_to_array(cPoints, &arrPoints, &count,
-					  &allocated, more);
-			cPoints = Vect_new_line_struct();
+		    if (Vect_get_point_in_poly(cPoints, &px, &py) == 0) {
+			if (!point_in_buf(area_isles[i], px, py, da, db, dalpha)) {
+			    add_line_to_array(cPoints, &arrPoints, &count,
+					      &allocated, more);
+			    cPoints = Vect_new_line_struct();
+			}
 		    }
+		    else {
+			G_warning(_("Vect_get_point_in_poly() failed"));
+		    }
 		}
 	    }
 	    res = extract_inner_contour(pg2, &winding, cPoints);
@@ -972,7 +1009,7 @@
     int isles_allocated = 0;
 
     G_debug(2, "Vect_line_buffer()");
-    
+
     Vect_line_prune((struct line_pnts *)Points);
 
     if (Points->n_points == 1)

Modified: grass/trunk/lib/vector/Vlib/dgraph.c
===================================================================
--- grass/trunk/lib/vector/Vlib/dgraph.c	2011-04-08 08:33:37 UTC (rev 45873)
+++ grass/trunk/lib/vector/Vlib/dgraph.c	2011-04-08 08:45:35 UTC (rev 45874)
@@ -228,9 +228,7 @@
     /*int res2
        double x1_, y1_, x2_, y2_, z1_, z2_; */
     struct seg_intersections *si;
-
     struct seg_intersection_list *il;
-
     struct intersection_point **sorted;
 
     G_debug(3, "find_all_intersections()");
@@ -342,6 +340,7 @@
 		    si->ip[si->il[i].a[j].ip].x, si->ip[si->il[i].a[j].ip].y);
 	}
     }
+    G_free(sorted);
 
     return si;
 }

Modified: grass/trunk/lib/vector/Vlib/e_intersect.c
===================================================================
--- grass/trunk/lib/vector/Vlib/e_intersect.c	2011-04-08 08:33:37 UTC (rev 45873)
+++ grass/trunk/lib/vector/Vlib/e_intersect.c	2011-04-08 08:45:35 UTC (rev 45874)
@@ -18,16 +18,16 @@
 #include <grass/gis.h>
 #include "e_intersect.h"
 
-#define SWAP(a,b) {t = a; a = b; b = t;}
+#define SWAP(a,b) {double t = a; a = b; b = t;}
 #ifndef MIN
 #define MIN(X,Y) ((X<Y)?X:Y)
 #endif
 #ifndef MAX
 #define MAX(X,Y) ((X>Y)?X:Y)
 #endif
-#define D (ax2-ax1)*(by1-by2) - (ay2-ay1)*(bx1-bx2)
-#define DA (bx1-ax1)*(by1-by2) - (by1-ay1)*(bx1-bx2)
-#define DB (ax2-ax1)*(by1-ay1) - (ay2-ay1)*(bx1-ax1)
+#define D ((ax2-ax1)*(by1-by2) - (ay2-ay1)*(bx1-bx2))
+#define DA ((bx1-ax1)*(by1-by2) - (by1-ay1)*(bx1-bx2))
+#define DB ((ax2-ax1)*(by1-ay1) - (ay2-ay1)*(bx1-ax1))
 
 
 #ifdef ASDASDASFDSAFFDAS



More information about the grass-commit mailing list