[GRASS-SVN] r49157 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 9 12:13:57 EST 2011


Author: martinl
Date: 2011-11-09 09:13:57 -0800 (Wed, 09 Nov 2011)
New Revision: 49157

Modified:
   grass/trunk/lib/vector/Vlib/write_nat.c
Log:
vlib: V2__add_line_to_topo_nat() - simplify condition logic (cosmetics)


Modified: grass/trunk/lib/vector/Vlib/write_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_nat.c	2011-11-09 16:04:59 UTC (rev 49156)
+++ grass/trunk/lib/vector/Vlib/write_nat.c	2011-11-09 17:13:57 UTC (rev 49157)
@@ -120,7 +120,7 @@
            I1   I1                        I1   I1                      
    </pre>        
  
-   - reattache all centroids/isles inside new area(s)
+   - re-attach all centroids/isles inside new area(s)
    - attach new isle to area outside
 
   2) line is closed ring (node at the end is new, so it is not case above)
@@ -155,126 +155,125 @@
     Line = plus->Line[line];
     type = Line->type;
 
-    if (plus->built >= GV_BUILD_AREAS) {
-	if (type == GV_BOUNDARY) {
-	    struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
+    if (plus->built >= GV_BUILD_AREAS &&
+	type == GV_BOUNDARY) {
+	struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
+	
+	/* Delete neighbour areas/isles */
+	first = TRUE;
+	for (s = 0; s < 2; s++) {	/* for each node */
+	    node = (s == 0 ? topo->N1 : topo->N2);
+	    G_debug(3,
+		    "  delete neighbour areas/isles: %s node = %d",
+		    (s == 0 ? "first" : "second"), node);
+	    Node = plus->Node[node];
+	    n = 0;
+	    for (i = 0; i < Node->n_lines; i++) {
+		NLine = plus->Line[abs(Node->lines[i])];
+		if (NLine->type == GV_BOUNDARY)
+		    n++;
+	    }
 	    
-	    /* Delete neighbour areas/isles */
-	    first = TRUE;
-	    for (s = 0; s < 2; s++) {	/* for each node */
-		node = (s == 0 ? topo->N1 : topo->N2);
-		G_debug(3,
-			"  delete neighbour areas/isles: %s node = %d",
-			(s == 0 ? "first" : "second"), node);
-		Node = plus->Node[node];
-		n = 0;
-		for (i = 0; i < Node->n_lines; i++) {
-		    NLine = plus->Line[abs(Node->lines[i])];
-		    if (NLine->type == GV_BOUNDARY)
-			n++;
-		}
-
-		G_debug(3, "  number of boundaries at node = %d", n);
-		if (n > 2) {
-		    /* more than 2 boundaries at node ( >= 2 old + 1 new ) */
-		    /* Line above (to the right), it is enough to check to
-		       the right, because if area/isle
-		       exists it is the same to the left */
-		    if (!s)
-			next_line =
-			    dig_angle_next_line(plus, line, GV_RIGHT,
-						GV_BOUNDARY);
-		    else
-			next_line =
-			    dig_angle_next_line(plus, -line, GV_RIGHT,
-						GV_BOUNDARY);
-
-		    if (next_line != 0) {	/* there is a boundary to the right */
-			NLine = plus->Line[abs(next_line)];
-			topo = (struct P_topo_b *)NLine->topo;
-			if (next_line > 0)	/* the boundary is connected by 1. node */
-			    /* we are interested just in this side (close to our line) */
-			    area = topo->right;	
-			else if (next_line < 0)	/* the boundary is connected by 2. node */
-			    area = topo->left;
-
-			G_debug(3, "  next_line = %d area = %d", next_line,
-				area);
-			if (area > 0) {	/* is area */
-			    Vect_get_area_box(Map, area, &box);
-			    if (first) {
-				Vect_box_copy(&abox, &box);
-				first = FALSE;
-			    }
-			    else
-				Vect_box_extend(&abox, &box);
-
-			    if (plus->update_cidx) {
-				V2__delete_area_cats_from_cidx_nat(Map, area);
-			    }
-			    dig_del_area(plus, area);
+	    G_debug(3, "  number of boundaries at node = %d", n);
+	    if (n > 2) {
+		/* more than 2 boundaries at node ( >= 2 old + 1 new ) */
+		/* Line above (to the right), it is enough to check to
+		   the right, because if area/isle
+		   exists it is the same to the left */
+		if (!s)
+		    next_line =
+			dig_angle_next_line(plus, line, GV_RIGHT,
+					    GV_BOUNDARY);
+		else
+		    next_line =
+			dig_angle_next_line(plus, -line, GV_RIGHT,
+					    GV_BOUNDARY);
+		
+		if (next_line != 0) {	/* there is a boundary to the right */
+		    NLine = plus->Line[abs(next_line)];
+		    topo = (struct P_topo_b *)NLine->topo;
+		    if (next_line > 0)	/* the boundary is connected by 1. node */
+			/* we are interested just in this side (close to our line) */
+			area = topo->right;	
+		    else if (next_line < 0)	/* the boundary is connected by 2. node */
+			area = topo->left;
+		    
+		    G_debug(3, "  next_line = %d area = %d", next_line,
+			    area);
+		    if (area > 0) {	/* is area */
+			Vect_get_area_box(Map, area, &box);
+			if (first) {
+			    Vect_box_copy(&abox, &box);
+			    first = FALSE;
 			}
-			else if (area < 0) {	/* is isle */
-			    dig_del_isle(plus, -area);
+			else
+			    Vect_box_extend(&abox, &box);
+			
+			if (plus->update_cidx) {
+			    V2__delete_area_cats_from_cidx_nat(Map, area);
 			}
+			dig_del_area(plus, area);
 		    }
+		    else if (area < 0) {	/* is isle */
+			dig_del_isle(plus, -area);
+		    }
 		}
 	    }
-	    /* Build new areas/isles.
-	     * It's true that we deleted also adjacent areas/isles, but
-	     * if they form new one our boundary must participate, so
-	     * we need to build areas/isles just for our boundary */
-	    for (s = 0; s < 2; s++) {
-		side = (s == 0 ? GV_LEFT : GV_RIGHT);
-		G_debug(3, "  build area/isle on side = %d", side);
-
-		G_debug(3, "Build area for line = %d, side = %d", line, side);
-		area = Vect_build_line_area(Map, line, side);
-		G_debug(3, "Build area for line = %d, side = %d", line, side);
-		if (area > 0) {	/* area */
-		    Vect_get_area_box(Map, area, &box);
-		    if (first) {
-			Vect_box_copy(&abox, &box);
-			first = FALSE;
-		    }
-		    else
-			Vect_box_extend(&abox, &box);
+	}
+	/* Build new areas/isles.
+	 * It's true that we deleted also adjacent areas/isles, but
+	 * if they form new one our boundary must participate, so
+	 * we need to build areas/isles just for our boundary */
+	for (s = 0; s < 2; s++) {
+	    side = (s == 0 ? GV_LEFT : GV_RIGHT);
+	    G_debug(3, "  build area/isle on side = %d", side);
+	    
+	    G_debug(3, "Build area for line = %d, side = %d", line, side);
+	    area = Vect_build_line_area(Map, line, side);
+	    G_debug(3, "Build area for line = %d, side = %d", line, side);
+	    if (area > 0) {	/* area */
+		Vect_get_area_box(Map, area, &box);
+		if (first) {
+		    Vect_box_copy(&abox, &box);
+		    first = FALSE;
 		}
-		else if (area < 0) {
-		    /* isle -> must be attached -> add to abox */
-		    Vect_get_isle_box(Map, -area, &box);
-		    if (first) {
-			Vect_box_copy(&abox, &box);
-			first = FALSE;
-		    }
-		    else
-			Vect_box_extend(&abox, &box);
+		else
+		    Vect_box_extend(&abox, &box);
+	    }
+	    else if (area < 0) {
+		/* isle -> must be attached -> add to abox */
+		Vect_get_isle_box(Map, -area, &box);
+		if (first) {
+		    Vect_box_copy(&abox, &box);
+		    first = FALSE;
 		}
-		new_area[s] = area;
+		else
+		    Vect_box_extend(&abox, &box);
 	    }
-	    /* Reattach all centroids/isles in deleted areas + new area.
-	     * Because isles are selected by box it covers also possible
-	     * new isle created above */
-	    if (!first) { /* i.e. old area/isle was deleted or new one created */
-		/* Reattach isles */
-		if (plus->built >= GV_BUILD_ATTACH_ISLES)
-		    Vect_attach_isles(Map, &abox);
-
-		/* Reattach centroids */
-		if (plus->built >= GV_BUILD_CENTROIDS)
-		    Vect_attach_centroids(Map, &abox);
-	    }
-	    /* Add to category index */
-	    if (plus->update_cidx) {
-		for (s = 0; s < 2; s++) {
-		    if (new_area[s] > 0) {
-			V2__add_area_cats_to_cidx_nat(Map, new_area[s]);
-		    }
+	    new_area[s] = area;
+	}
+	/* Reattach all centroids/isles in deleted areas + new area.
+	 * Because isles are selected by box it covers also possible
+	 * new isle created above */
+	if (!first) { /* i.e. old area/isle was deleted or new one created */
+	    /* Reattach isles */
+	    if (plus->built >= GV_BUILD_ATTACH_ISLES)
+		Vect_attach_isles(Map, &abox);
+	    
+	    /* Reattach centroids */
+	    if (plus->built >= GV_BUILD_CENTROIDS)
+		Vect_attach_centroids(Map, &abox);
+	}
+	/* Add to category index */
+	if (plus->update_cidx) {
+	    for (s = 0; s < 2; s++) {
+		if (new_area[s] > 0) {
+		    V2__add_area_cats_to_cidx_nat(Map, new_area[s]);
 		}
 	    }
 	}
     }
-
+    
     /* Attach centroid */
     if (plus->built >= GV_BUILD_CENTROIDS) {
 	struct P_topo_c *topo;



More information about the grass-commit mailing list