Browse Source

v.generalize: add test for self-intersection, use Vect_line_intersection2()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62162 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 years ago
parent
commit
bf3706c477
1 changed files with 24 additions and 7 deletions
  1. 24 7
      vector/v.generalize/misc.c

+ 24 - 7
vector/v.generalize/misc.c

@@ -192,9 +192,11 @@ 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;
+    struct line_pnts **AXLines, **BXLines;
+    int naxlines, nbxlines;
     static struct line_pnts *BPoints = NULL;
     static struct boxlist *List = NULL;
 
@@ -203,15 +205,29 @@ int check_topo(struct Map_info *Out, int line, struct line_pnts *APoints,
     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_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_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 @@ int check_topo(struct Map_info *Out, int line, struct line_pnts *APoints,
 	 * 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",