GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
vector/diglib/box.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: Vector library
5  *
6  * AUTHOR(S): Radim Blazek
7  *
8  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
9  *
10  * COPYRIGHT: (C) 2001 by the GRASS Development Team
11  *
12  * This program is free software under the GNU General Public
13  * License (>=v2). Read the file COPYING that comes with GRASS
14  * for details.
15  *
16  *****************************************************************************/
17 #include <stdlib.h>
18 #include <grass/vector.h>
19 
20 /*
21  * dig_line_box ()
22  * set box to points extent
23  */
24 int dig_line_box(const struct line_pnts *Points, struct bound_box * Box)
25 {
26  int i;
27 
28  if (Points->n_points <= 0) {
29  G_zero(Box, sizeof(struct bound_box));
30  return 0;
31  }
32 
33  Box->E = Points->x[0];
34  Box->W = Points->x[0];
35  Box->N = Points->y[0];
36  Box->S = Points->y[0];
37  Box->T = Points->z[0];
38  Box->B = Points->z[0];
39 
40  for (i = 1; i < Points->n_points; i++) {
41  if (Points->x[i] > Box->E)
42  Box->E = Points->x[i];
43  else if (Points->x[i] < Box->W)
44  Box->W = Points->x[i];
45 
46  if (Points->y[i] > Box->N)
47  Box->N = Points->y[i];
48  else if (Points->y[i] < Box->S)
49  Box->S = Points->y[i];
50 
51  if (Points->z[i] > Box->T)
52  Box->T = Points->z[i];
53  else if (Points->z[i] < Box->B)
54  Box->B = Points->z[i];
55  }
56 
57  return 1;
58 }
59 
60 /*
61  * dig_box_copy ()
62  * Copy B to A.
63  */
64 int dig_box_copy(struct bound_box * A, struct bound_box * B)
65 {
66 
67  A->N = B->N;
68  A->S = B->S;
69  A->E = B->E;
70  A->W = B->W;
71  A->T = B->T;
72  A->B = B->B;
73 
74  return 1;
75 }
76 
77 /*
78  * dig_box_extend ()
79  * Extend A by B.
80  */
81 int dig_box_extend(struct bound_box * A, struct bound_box * B)
82 {
83 
84  if (B->N > A->N)
85  A->N = B->N;
86  if (B->S < A->S)
87  A->S = B->S;
88  if (B->E > A->E)
89  A->E = B->E;
90  if (B->W < A->W)
91  A->W = B->W;
92  if (B->T > A->T)
93  A->T = B->T;
94  if (B->B < A->B)
95  A->B = B->B;
96 
97  return 1;
98 }
Bounding box.
Definition: dig_structs.h:65
double W
West.
Definition: dig_structs.h:82
int dig_line_box(const struct line_pnts *Points, struct bound_box *Box)
int dig_box_extend(struct bound_box *A, struct bound_box *B)
float Box[8][3]
Vertices for box.
Definition: gsd_objs.c:1421
int n_points
Number of points.
Definition: dig_structs.h:1692
double E
East.
Definition: dig_structs.h:78
double N
North.
Definition: dig_structs.h:70
double * x
Array of X coordinates.
Definition: dig_structs.h:1680
Feature geometry info - coordinates.
Definition: dig_structs.h:1675
double B
Bottom.
Definition: dig_structs.h:90
double T
Top.
Definition: dig_structs.h:86
double * y
Array of Y coordinates.
Definition: dig_structs.h:1684
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:23
double S
South.
Definition: dig_structs.h:74
double * z
Array of Z coordinates.
Definition: dig_structs.h:1688
int dig_box_copy(struct bound_box *A, struct bound_box *B)