GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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/Vect.h>
19 
20 /*
21  * dig_line_box ()
22  * set box to points extent
23  */
24 int dig_line_box(struct line_pnts *Points, BOUND_BOX * Box)
25 {
26  int i;
27 
28  if (Points->n_points <= 0) {
29  Box->N = 0;
30  Box->S = 0;
31  Box->E = 0;
32  Box->W = 0;
33  Box->T = 0;
34  Box->B = 0;
35  return 0;
36  }
37 
38  Box->E = Points->x[0];
39  Box->W = Points->x[0];
40  Box->N = Points->y[0];
41  Box->S = Points->y[0];
42  Box->T = Points->z[0];
43  Box->B = Points->z[0];
44 
45  for (i = 1; i < Points->n_points; i++) {
46  if (Points->x[i] > Box->E)
47  Box->E = Points->x[i];
48  else if (Points->x[i] < Box->W)
49  Box->W = Points->x[i];
50 
51  if (Points->y[i] > Box->N)
52  Box->N = Points->y[i];
53  else if (Points->y[i] < Box->S)
54  Box->S = Points->y[i];
55 
56  if (Points->z[i] > Box->T)
57  Box->T = Points->z[i];
58  else if (Points->z[i] < Box->B)
59  Box->B = Points->z[i];
60  }
61 
62  return 1;
63 }
64 
65 /*
66  * dig_box_copy ()
67  * Copy B to A.
68  */
69 int dig_box_copy(BOUND_BOX * A, BOUND_BOX * B)
70 {
71 
72  A->N = B->N;
73  A->S = B->S;
74  A->E = B->E;
75  A->W = B->W;
76  A->T = B->T;
77  A->B = B->B;
78 
79  return 1;
80 }
81 
82 /*
83  * dig_box_extend ()
84  * Extend A by B.
85  */
86 int dig_box_extend(BOUND_BOX * A, BOUND_BOX * B)
87 {
88 
89  if (B->N > A->N)
90  A->N = B->N;
91  if (B->S < A->S)
92  A->S = B->S;
93  if (B->E > A->E)
94  A->E = B->E;
95  if (B->W < A->W)
96  A->W = B->W;
97  if (B->T > A->T)
98  A->T = B->T;
99  if (B->B < A->B)
100  A->B = B->B;
101 
102  return 1;
103 }
int dig_line_box(struct line_pnts *Points, BOUND_BOX *Box)
Definition: diglib/box.c:24
float Box[8][3]
Vertices for box.
Definition: gsd_objs.c:1420
int dig_box_extend(BOUND_BOX *A, BOUND_BOX *B)
Definition: diglib/box.c:86
int dig_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Definition: diglib/box.c:69