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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 5 01:04:36 PDT 2012


Author: mmetz
Date: 2012-08-05 01:04:36 -0700 (Sun, 05 Aug 2012)
New Revision: 52529

Modified:
   grass/trunk/lib/vector/Vlib/box.c
Log:
Vlib: simplify code

Modified: grass/trunk/lib/vector/Vlib/box.c
===================================================================
--- grass/trunk/lib/vector/Vlib/box.c	2012-08-04 21:04:23 UTC (rev 52528)
+++ grass/trunk/lib/vector/Vlib/box.c	2012-08-05 08:04:36 UTC (rev 52529)
@@ -206,6 +206,7 @@
 {
     struct Plus_head *Plus;
     struct P_line *Line;
+    int type;
     static struct line_pnts *Points = NULL;
     static struct boxlist *list = NULL;
 
@@ -216,59 +217,64 @@
 	G_zero(Box, sizeof(struct bound_box));
 	return 0;
     }
-    else {
-	int type = Line->type;
 	
-	/* GV_POINTS: read line */
-	if (type & GV_POINTS) {
-	    if (Points == NULL)
-		Points = Vect_new_line_struct();
+    type = Line->type;
 
-	    Vect_read_line(Map, Points, NULL, line);
-	    dig_line_box(Points, Box);
+    /* GV_LINES: retrieve box from spatial index */
+    if (type & GV_LINES) {
+	int node = 0;
+	struct bound_box bbox;
+
+	if (type == GV_LINE) {
+	    struct P_topo_l *topo = (struct P_topo_l *)Line->topo;
+
+	    node = topo->N1;
 	}
-	/* all other: retrieve box from spatial index */
-	else {
-	    int node = 0;
-	    struct bound_box bbox;
+	else if (type == GV_BOUNDARY) {
+	    struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
 
-	    if (type == GV_LINE) {
-		struct P_topo_l *topo = (struct P_topo_l *)Line->topo;
+	    node = topo->N1;
+	}
+	
+	if (list == NULL) {
+	    list = Vect_new_boxlist(1);
+	}
+	Vect_reset_boxlist(list);
+	
+	bbox.N = Plus->Node[node]->y;
+	bbox.S = Plus->Node[node]->y;
+	bbox.E = Plus->Node[node]->x;
+	bbox.W = Plus->Node[node]->x;
+	bbox.T = Plus->Node[node]->z;
+	bbox.B = Plus->Node[node]->z;
 
-		node = topo->N1;
-	    }
-	    else if (type == GV_BOUNDARY) {
-		struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
+	dig_boxlist_add(list, line, bbox);
+	
+	if (dig_find_line_box(Plus, list) == 0)
+	    G_fatal_error(_("Unable to find bbox for feature %d"), line);
 
-		node = topo->N1;
-	    }
-	    
-	    if (list == NULL) {
-		list = Vect_new_boxlist(1);
-	    }
-	    Vect_reset_boxlist(list);
-	    
-	    bbox.N = Plus->Node[node]->y;
-	    bbox.S = Plus->Node[node]->y;
-	    bbox.E = Plus->Node[node]->x;
-	    bbox.W = Plus->Node[node]->x;
-	    bbox.T = Plus->Node[node]->z;
-	    bbox.B = Plus->Node[node]->z;
+	Box->N = list->box[0].N;
+	Box->S = list->box[0].S;
+	Box->E = list->box[0].E;
+	Box->W = list->box[0].W;
+	Box->T = list->box[0].T;
+	Box->B = list->box[0].B;
 
-	    dig_boxlist_add(list, line, bbox);
-	    
-	    if (dig_find_line_box(Plus, list) == 0)
-		G_fatal_error(_("Unable to find bbox for featured %d"), line);
+	if (!Vect_is_3d(Map)) {
+	    Box->T =  PORT_DOUBLE_MAX;
+	    Box->B = -PORT_DOUBLE_MAX;
+	}
 
-	    Box->N = list->box[0].N;
-	    Box->S = list->box[0].S;
-	    Box->E = list->box[0].E;
-	    Box->W = list->box[0].W;
-	    Box->T = list->box[0].T;
-	    Box->B = list->box[0].B;
-	}
+	return 1;
     }
 
+    /* all other: read line */
+    if (Points == NULL)
+	Points = Vect_new_line_struct();
+
+    Vect_read_line(Map, Points, NULL, line);
+    dig_line_box(Points, Box);
+
     if (!Vect_is_3d(Map)) {
 	Box->T =  PORT_DOUBLE_MAX;
 	Box->B = -PORT_DOUBLE_MAX;
@@ -305,36 +311,35 @@
         G_zero(Box, sizeof(struct bound_box));
 	return 0;
     }
-    else {
-	Line = Plus->Line[abs(Area->lines[0])];
-	topo = (struct P_topo_b *)Line->topo;
-	Node = Plus->Node[topo->N1];
 
-	if (list == NULL) {
-	    list = Vect_new_boxlist(TRUE);
-	}
-	Vect_reset_boxlist(list);
-	
-	bbox.N = Node->y;
-	bbox.S = Node->y;
-	bbox.E = Node->x;
-	bbox.W = Node->x;
-	bbox.T = Node->z;
-	bbox.B = Node->z;
+    Line = Plus->Line[abs(Area->lines[0])];
+    topo = (struct P_topo_b *)Line->topo;
+    Node = Plus->Node[topo->N1];
 
-	dig_boxlist_add(list, area, bbox);
-	
-	if (dig_find_area_box(Plus, list) == 0)
-	    G_fatal_error(_("Unable to get bounding box for area %d"), area);
-
-	Box->N = list->box[0].N;
-	Box->S = list->box[0].S;
-	Box->E = list->box[0].E;
-	Box->W = list->box[0].W;
-	Box->T = list->box[0].T;
-	Box->B = list->box[0].B;
+    if (list == NULL) {
+	list = Vect_new_boxlist(TRUE);
     }
+    Vect_reset_boxlist(list);
+    
+    bbox.N = Node->y;
+    bbox.S = Node->y;
+    bbox.E = Node->x;
+    bbox.W = Node->x;
+    bbox.T = Node->z;
+    bbox.B = Node->z;
 
+    dig_boxlist_add(list, area, bbox);
+    
+    if (dig_find_area_box(Plus, list) == 0)
+	G_fatal_error(_("Unable to get bounding box for area %d"), area);
+
+    Box->N = list->box[0].N;
+    Box->S = list->box[0].S;
+    Box->E = list->box[0].E;
+    Box->W = list->box[0].W;
+    Box->T = list->box[0].T;
+    Box->B = list->box[0].B;
+
     return 1;
 }
 
@@ -370,36 +375,34 @@
 	Box->B = 0;
 	return 0;
     }
-    else {
 
-	Line = Plus->Line[abs(Isle->lines[0])];
-	topo = (struct P_topo_b *)Line->topo;
-	Node = Plus->Node[topo->N1];
+    Line = Plus->Line[abs(Isle->lines[0])];
+    topo = (struct P_topo_b *)Line->topo;
+    Node = Plus->Node[topo->N1];
 
-	if (list == NULL) {
-	    list = Vect_new_boxlist(1);
-	}
-	Vect_reset_boxlist(list);
-	
-	bbox.N = Node->y;
-	bbox.S = Node->y;
-	bbox.E = Node->x;
-	bbox.W = Node->x;
-	bbox.T = Node->z;
-	bbox.B = Node->z;
+    if (list == NULL) {
+	list = Vect_new_boxlist(1);
+    }
+    Vect_reset_boxlist(list);
+    
+    bbox.N = Node->y;
+    bbox.S = Node->y;
+    bbox.E = Node->x;
+    bbox.W = Node->x;
+    bbox.T = Node->z;
+    bbox.B = Node->z;
 
-	dig_boxlist_add(list, isle, bbox);
-	
-	if (dig_find_isle_box(Plus, list) == 0)
-	    G_fatal_error(_("Could not find area box"));
+    dig_boxlist_add(list, isle, bbox);
+    
+    if (dig_find_isle_box(Plus, list) == 0)
+	G_fatal_error(_("Could not find isle box"));
 
-	Box->N = list->box[0].N;
-	Box->S = list->box[0].S;
-	Box->E = list->box[0].E;
-	Box->W = list->box[0].W;
-	Box->T = list->box[0].T;
-	Box->B = list->box[0].B;
-    }
+    Box->N = list->box[0].N;
+    Box->S = list->box[0].S;
+    Box->E = list->box[0].E;
+    Box->W = list->box[0].W;
+    Box->T = list->box[0].T;
+    Box->B = list->box[0].B;
 
     return 1;
 }



More information about the grass-commit mailing list