Bläddra i källkod

vlib: V2__add_line_to_topo_nat() - simplify condition logic (cosmetics)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49157 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 år sedan
förälder
incheckning
43390539fc
1 ändrade filer med 107 tillägg och 108 borttagningar
  1. 107 108
      lib/vector/Vlib/write_nat.c

+ 107 - 108
lib/vector/Vlib/write_nat.c

@@ -120,7 +120,7 @@ static void V2__add_area_cats_to_cidx_nat(struct Map_info *Map, int area)
            I1   I1                        I1   I1                      
            I1   I1                        I1   I1                      
    </pre>        
    </pre>        
  
  
-   - reattache all centroids/isles inside new area(s)
+   - re-attach all centroids/isles inside new area(s)
    - attach new isle to area outside
    - attach new isle to area outside
 
 
   2) line is closed ring (node at the end is new, so it is not case above)
   2) line is closed ring (node at the end is new, so it is not case above)
@@ -155,126 +155,125 @@ static void V2__add_line_to_topo_nat(struct Map_info *Map, int line,
     Line = plus->Line[line];
     Line = plus->Line[line];
     type = Line->type;
     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);
 		    }
 		    }
-		}
-	    }
-	    /* 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) {	/* is isle */
+			dig_del_isle(plus, -area);
 		    }
 		    }
-		    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;
-		    }
-		    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;
 		}
 		}
-		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);
+	    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);
 	    }
 	    }
-	    /* 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 */
     /* Attach centroid */
     if (plus->built >= GV_BUILD_CENTROIDS) {
     if (plus->built >= GV_BUILD_CENTROIDS) {
 	struct P_topo_c *topo;
 	struct P_topo_c *topo;