Ver código fonte

Vlib: simplify code

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52529 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 anos atrás
pai
commit
b7f949b782
1 arquivos alterados com 103 adições e 100 exclusões
  1. 103 100
      lib/vector/Vlib/box.c

+ 103 - 100
lib/vector/Vlib/box.c

@@ -206,6 +206,7 @@ int Vect_get_line_box(const struct Map_info *Map, int line, struct bound_box * B
 {
     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 @@ int Vect_get_line_box(const struct Map_info *Map, int line, struct bound_box * B
 	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;
+	}
+	else if (type == GV_BOUNDARY) {
+	    struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
+
+	    node = topo->N1;
+	}
+	
+	if (list == NULL) {
+	    list = Vect_new_boxlist(1);
 	}
-	/* all other: retrieve box from spatial index */
-	else {
-	    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;
-	    }
-	    else if (type == GV_BOUNDARY) {
-		struct P_topo_b *topo = (struct P_topo_b *)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;
-
-	    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);
-
-	    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;
+	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;
+
+	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);
+
+	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 (!Vect_is_3d(Map)) {
+	    Box->T =  PORT_DOUBLE_MAX;
+	    Box->B = -PORT_DOUBLE_MAX;
 	}
+
+	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,35 +311,34 @@ int Vect_get_area_box(const struct Map_info *Map, int area, struct bound_box * B
         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;
-
-	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);
+    Line = Plus->Line[abs(Area->lines[0])];
+    topo = (struct P_topo_b *)Line->topo;
+    Node = Plus->Node[topo->N1];
 
-	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 @@ int Vect_get_isle_box(const struct Map_info *Map, int isle, struct bound_box * B
 	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;
-
-	dig_boxlist_add(list, isle, bbox);
-	
-	if (dig_find_isle_box(Plus, list) == 0)
-	    G_fatal_error(_("Could not find area 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;
+    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 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;
 
     return 1;
 }