Ver código fonte

v.generalize: add test for self intersection

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@64471 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 anos atrás
pai
commit
897cdb62a3
1 arquivos alterados com 29 adições e 5 exclusões
  1. 29 5
      vector/v.generalize/misc.c

+ 29 - 5
vector/v.generalize/misc.c

@@ -192,26 +192,50 @@ int copy_tables_by_cats(struct Map_info *In, struct Map_info *Out)
 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);
 
-    /* Check intersection of the modified boundary with other boundaries */
     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_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)