[GRASS-SVN] r70596 - grass/trunk/lib/vector/vedit

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 15 22:34:17 PST 2017


Author: hcho
Date: 2017-02-15 22:34:17 -0800 (Wed, 15 Feb 2017)
New Revision: 70596

Modified:
   grass/trunk/lib/vector/vedit/extend.c
Log:
vedit: Fix extend onto line_to

Modified: grass/trunk/lib/vector/vedit/extend.c
===================================================================
--- grass/trunk/lib/vector/vedit/extend.c	2017-02-16 05:09:41 UTC (rev 70595)
+++ grass/trunk/lib/vector/vedit/extend.c	2017-02-16 06:34:17 UTC (rev 70596)
@@ -176,7 +176,7 @@
 
     /* avoid too much indentation */
     do {
-	int n_points, seg, is;
+	int n_points, seg, is, line_to_extended;
 	double x, y, px, py, x1, y1;
 	double dist, spdist, lpdist, length;
 	double angle_t, angle_f;
@@ -210,6 +210,8 @@
 			       NULL))
 	    break;
 
+	line_to_extended = 0;
+
 	/* extend both lines and find intersection */
 	if (!find_extended_intersection(x, y, angle_f, px, py, angle_t,
 					&x1, &y1)) {
@@ -245,9 +247,13 @@
 		    break;
 
 		if (seg == 1) {
+		    line_to_extended = 1;
+
 		    x2 = Points_to->x[0];
 		    y2 = Points_to->y[0];
 		} else {
+		    line_to_extended = 2;
+
 		    x2 = Points_to->x[Points_to->n_points - 1];
 		    y2 = Points_to->y[Points_to->n_points - 1];
 		}
@@ -274,45 +280,46 @@
 				     Cats_from);
 	/* Vect_list_append(List, line_new); */
 
-	length = Vect_line_length(Points_to);
 	Vect_reset_line(Points_final);
-	if (lpdist == 0.0) {
-	    /* extend line_to start node */
-	    Vect_append_point(Points_final, x1, y1, 0.0);
-	    for (is = 0; is < Points_to->n_points; is++)
-		Vect_append_point(Points_final, Points_to->x[is],
-				  Points_to->y[is], Points_to->z[is]);
-	    line_new = Vect_rewrite_line(Map, line_to, type_to, Points_final,
-					 Cats_to);
-	} else if (lpdist == length) {
-	    /* extend line_to end node */
-	    for (is = 0; is < Points_to->n_points; is++)
-		Vect_append_point(Points_final, Points_to->x[is],
-				  Points_to->y[is], Points_to->z[is]);
-	    Vect_append_point(Points_final, x1, y1, 0.0);
-	    line_new = Vect_rewrite_line(Map, line_to, type_to, Points_final,
-					 Cats_to);
-	} else {
-	    /* break line_to */
-	    /* update line_to  -- first part */
-	    for (is = 0; is < seg; is++)
-		Vect_append_point(Points_final, Points_to->x[is],
-				  Points_to->y[is], Points_to->z[is]);
-	    Vect_append_point(Points_final, x1, y1, 0.0);
-	    line_new = Vect_rewrite_line(Map, line_to, type_to, Points_final,
-					 Cats_to);
-	    /* Vect_list_append(List, line_new); */
+	switch (line_to_extended) {
+	    case 1:
+		/* extend line_to start node */
+		Vect_append_point(Points_final, x1, y1, 0.0);
+		for (is = 0; is < Points_to->n_points; is++)
+		    Vect_append_point(Points_final, Points_to->x[is],
+				      Points_to->y[is], Points_to->z[is]);
+		line_new = Vect_rewrite_line(Map, line_to, type_to,
+					     Points_final, Cats_to);
+		break;
+	    case 2:
+		/* extend line_to end node */
+		for (is = 0; is < Points_to->n_points; is++)
+		    Vect_append_point(Points_final, Points_to->x[is],
+				      Points_to->y[is], Points_to->z[is]);
+		Vect_append_point(Points_final, x1, y1, 0.0);
+		line_new = Vect_rewrite_line(Map, line_to, type_to,
+					     Points_final, Cats_to);
+		break;
+	    default:
+		/* break line_to */
+		/* update line_to  -- first part */
+		for (is = 0; is < seg; is++)
+		    Vect_append_point(Points_final, Points_to->x[is],
+				      Points_to->y[is], Points_to->z[is]);
+		Vect_append_point(Points_final, x1, y1, 0.0);
+		line_new = Vect_rewrite_line(Map, line_to, type_to,
+					     Points_final, Cats_to);
+		/* Vect_list_append(List, line_new); */
 
-	    /* write second part */
-	    Vect_reset_line(Points_final);
-	    Vect_append_point(Points_final, x1, y1, 0.0);
-	    for (is = seg; is < Points_to->n_points; is++)
-		Vect_append_point(Points_final, Points_to->x[is],
-				  Points_to->y[is], Points_to->z[is]);
-
-	    /* rewrite first part */
-	    line_new = Vect_write_line(Map, type_to, Points_final, Cats_to);
-	    /* Vect_list_append(List, line_new); */
+		/* write second part */
+		Vect_reset_line(Points_final);
+		Vect_append_point(Points_final, x1, y1, 0.0);
+		for (is = seg; is < Points_to->n_points; is++)
+		    Vect_append_point(Points_final, Points_to->x[is],
+				      Points_to->y[is], Points_to->z[is]);
+		line_new = Vect_write_line(Map, type_to, Points_final, Cats_to);
+		/* Vect_list_append(List, line_new); */
+		break;
 	}
     } while(0);
 



More information about the grass-commit mailing list