[GRASS-SVN] r64471 - grass/branches/releasebranch_7_0/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 5 05:46:12 PST 2015


Author: mmetz
Date: 2015-02-05 05:46:12 -0800 (Thu, 05 Feb 2015)
New Revision: 64471

Modified:
   grass/branches/releasebranch_7_0/vector/v.generalize/misc.c
Log:
v.generalize: add test for self intersection

Modified: grass/branches/releasebranch_7_0/vector/v.generalize/misc.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.generalize/misc.c	2015-02-05 12:22:04 UTC (rev 64470)
+++ grass/branches/releasebranch_7_0/vector/v.generalize/misc.c	2015-02-05 13:46:12 UTC (rev 64471)
@@ -192,26 +192,50 @@
 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;
     static struct line_pnts *BPoints = NULL;
     static struct boxlist *List = NULL;
+    struct line_pnts **AXLines, **BXLines;
+    int naxlines, nbxlines;
 
     if (!BPoints)
 	BPoints = Vect_new_line_struct();
     if (!List)
 	List = Vect_new_boxlist(1);
 
+    Vect_line_box(Points, &box);
+
+    /* Check the modified boundary for self-intersection */
+    AXLines = BXLines = NULL;
+    Vect_line_intersection(Points, Points, &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 (nbxlines > 0) {
+	for (j = 0; j < nbxlines; j++) {
+	    Vect_destroy_line_struct(BXLines[j]);
+	}
+    }
+    if (BXLines)
+	G_free(BXLines);
+
+    if (naxlines > 0 || nbxlines > 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)



More information about the grass-commit mailing list