[GRASS-SVN] r62162 - grass/trunk/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 2 13:27:10 PDT 2014


Author: mmetz
Date: 2014-10-02 13:27:10 -0700 (Thu, 02 Oct 2014)
New Revision: 62162

Modified:
   grass/trunk/vector/v.generalize/misc.c
Log:
v.generalize: add test for self-intersection, use Vect_line_intersection2()

Modified: grass/trunk/vector/v.generalize/misc.c
===================================================================
--- grass/trunk/vector/v.generalize/misc.c	2014-10-02 20:24:10 UTC (rev 62161)
+++ grass/trunk/vector/v.generalize/misc.c	2014-10-02 20:27:10 UTC (rev 62162)
@@ -192,9 +192,11 @@
 int check_topo(struct Map_info *Out, int line, struct line_pnts *APoints,
                struct line_pnts *Points, struct line_cats *Cats)
 {
-    int i, intersect, newline, left_old, right_old,
+    int i, j, intersect, newline, left_old, right_old,
 	left_new, right_new;
     struct bound_box box;
+    struct line_pnts **AXLines, **BXLines;
+    int naxlines, nbxlines;
     static struct line_pnts *BPoints = NULL;
     static struct boxlist *List = NULL;
 
@@ -203,15 +205,29 @@
     if (!List)
 	List = Vect_new_boxlist(1);
 
+    Vect_line_box(Points, &box);
+
+    /* Check the modified boundary for self-intersection */
+    AXLines = BXLines = NULL;
+    Vect_line_intersection2(Points, NULL, &box, &box, &AXLines, &BXLines,
+			   &naxlines, &nbxlines, 0);
+    /* Free */
+    if (naxlines > 0) {
+	for (j = 0; j < naxlines; j++) {
+	    Vect_destroy_line_struct(AXLines[j]);
+	}
+    }
+    if (AXLines)
+	G_free(AXLines);
+    if (naxlines > 0)
+	return 0;
+
     /* Check intersection of the modified boundary with other boundaries */
-    Vect_line_box(Points, &box);
     Vect_select_lines_by_box(Out, &box, GV_BOUNDARY, List);
 
     intersect = 0;
     for (i = 0; i < List->n_values; i++) {
-	int j, bline;
-	struct line_pnts **AXLines, **BXLines;
-	int naxlines, nbxlines;
+	int bline;
 
 	bline = List->id[i];
 	if (bline == line)
@@ -223,8 +239,9 @@
 	 * intersections should be found if any */
 
 	AXLines = BXLines = NULL;
-	Vect_line_intersection(Points, BPoints, &box, &List->box[i], &AXLines, &BXLines,
-			       &naxlines, &nbxlines, 0);
+	Vect_line_intersection2(Points, BPoints, &box, &List->box[i],
+	                        &AXLines, &BXLines,
+			        &naxlines, &nbxlines, 0);
 
 	G_debug(4,
 		"bline = %d intersect = %d naxlines = %d nbxlines = %d",



More information about the grass-commit mailing list