GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
vector/diglib/box.c
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * MODULE: Vector library
4  *
5  * AUTHOR(S): Radim Blazek
6  *
7  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
8  *
9  * COPYRIGHT: (C) 2001 by the GRASS Development Team
10  *
11  * This program is free software under the GNU General Public
12  * License (>=v2). Read the file COPYING that comes with GRASS
13  * for details.
14  *
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 }
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:23
float Box[8][3]
Vertices for box.
Definition: gsd_objs.c:1395
Bounding box.
Definition: dig_structs.h:64
double W
West.
Definition: dig_structs.h:80
double T
Top.
Definition: dig_structs.h:84
double S
South.
Definition: dig_structs.h:72
double N
North.
Definition: dig_structs.h:68
double E
East.
Definition: dig_structs.h:76
double B
Bottom.
Definition: dig_structs.h:88
Feature geometry info - coordinates.
Definition: dig_structs.h:1651
double * y
Array of Y coordinates.
Definition: dig_structs.h:1659
double * x
Array of X coordinates.
Definition: dig_structs.h:1655
int n_points
Number of points.
Definition: dig_structs.h:1667
double * z
Array of Z coordinates.
Definition: dig_structs.h:1663
int dig_box_extend(struct bound_box *A, struct bound_box *B)
int dig_box_copy(struct bound_box *A, struct bound_box *B)
int dig_line_box(const struct line_pnts *Points, struct bound_box *Box)