GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Vlib/box.c
Go to the documentation of this file.
1 
20 #include <stdlib.h>
21 #include <grass/gis.h>
22 #include <grass/Vect.h>
23 
33 int Vect_point_in_box(double x, double y, double z, BOUND_BOX * Box)
34 {
35 
36  if (x >= Box->W && x <= Box->E &&
37  y >= Box->S && y <= Box->N && z >= Box->B && z <= Box->T) {
38  return 1;
39  }
40 
41  return 0;
42 }
43 
53 int Vect_box_overlap(BOUND_BOX * A, BOUND_BOX * B)
54 {
55 
56  if (A->E < B->W || A->W > B->E ||
57  A->N < B->S || A->S > B->N || A->T < B->B || A->B > B->T) {
58  return 0;
59  }
60 
61  return 1;
62 }
63 
72 int Vect_box_copy(BOUND_BOX * A, BOUND_BOX * B)
73 {
74 
75  A->N = B->N;
76  A->S = B->S;
77  A->E = B->E;
78  A->W = B->W;
79  A->T = B->T;
80  A->B = B->B;
81 
82  return 1;
83 }
84 
93 int Vect_box_extend(BOUND_BOX * A, BOUND_BOX * B)
94 {
95 
96  if (B->N > A->N)
97  A->N = B->N;
98  if (B->S < A->S)
99  A->S = B->S;
100  if (B->E > A->E)
101  A->E = B->E;
102  if (B->W < A->W)
103  A->W = B->W;
104  if (B->T > A->T)
105  A->T = B->T;
106  if (B->B < A->B)
107  A->B = B->B;
108 
109  return 1;
110 }
111 
112 
137 int
138 Vect_box_clip(double *x, double *y, double *c_x, double *c_y, BOUND_BOX * Box)
139 {
140  int mod;
141 
142  mod = 0;
143 
144  if (*x < Box->W) {
145  if (*c_x != *x)
146  *y = *y + (Box->W - *x) / (*c_x - *x) * (*c_y - *y);
147  *x = Box->W;
148  mod = 1;
149  }
150  if (*x > Box->E) {
151  if (*c_x != *x)
152  *y = *y + (Box->E - *x) / (*c_x - *x) * (*c_y - *y);
153  *x = Box->E;
154  mod = 1;
155  }
156  if (*c_x < Box->W) {
157  if (*c_x != *x)
158  *c_y = *c_y + (Box->W - *c_x) / (*x - *c_x) * (*y - *c_y);
159  *c_x = Box->W;
160  mod = 1;
161  }
162  if (*c_x > Box->E) {
163  if (*c_x != *x)
164  *c_y = *c_y + (Box->E - *c_x) / (*x - *c_x) * (*y - *c_y);
165  *c_x = Box->E;
166  mod = 1;
167  }
168  if (*y < Box->S) {
169  if (*c_y != *y)
170  *x = *x + (Box->S - *y) / (*c_y - *y) * (*c_x - *x);
171  *y = Box->S;
172  mod = 1;
173  }
174  if (*y > Box->N) {
175  if (*c_y != *y)
176  *x = *x + (Box->N - *y) / (*c_y - *y) * (*c_x - *x);
177  *y = Box->N;
178  mod = 1;
179  }
180  if (*c_y < Box->S) {
181  if (*c_y != *y)
182  *c_x = *c_x + (Box->S - *c_y) / (*y - *c_y) * (*x - *c_x);
183  *c_y = Box->S;
184  mod = 1;
185  }
186  if (*c_y > Box->N) {
187  if (*c_y != *y)
188  *c_x = *c_x + (Box->N - *c_y) / (*y - *c_y) * (*x - *c_x);
189  *c_y = Box->N;
190  mod = 1;
191  }
192 
193  return (mod);
194 }
195 
196 
197 
208 int Vect_get_line_box(struct Map_info *Map, int line, BOUND_BOX * Box)
209 {
210  struct Plus_head *Plus;
211  P_LINE *Line;
212 
213  Plus = &(Map->plus);
214  Line = Plus->Line[line];
215 
216  if (Line == NULL) { /* dead */
217  Box->N = 0;
218  Box->S = 0;
219  Box->E = 0;
220  Box->W = 0;
221  Box->T = 0;
222  Box->B = 0;
223  return 0;
224  }
225  else {
226  Box->N = Line->N;
227  Box->S = Line->S;
228  Box->E = Line->E;
229  Box->W = Line->W;
230  Box->T = Line->T;
231  Box->B = Line->B;
232  }
233 
234  return 1;
235 }
236 
247 int Vect_get_area_box(struct Map_info *Map, int area, BOUND_BOX * Box)
248 {
249  struct Plus_head *Plus;
250  P_AREA *Area;
251 
252  Plus = &(Map->plus);
253  Area = Plus->Area[area];
254 
255  if (Area == NULL) { /* dead */
256  Box->N = 0;
257  Box->S = 0;
258  Box->E = 0;
259  Box->W = 0;
260  Box->T = 0;
261  Box->B = 0;
262  return 0;
263  }
264  else {
265  Box->N = Area->N;
266  Box->S = Area->S;
267  Box->E = Area->E;
268  Box->W = Area->W;
269  Box->T = Area->T;
270  Box->B = Area->B;
271  }
272 
273  return 1;
274 }
275 
286 int Vect_get_isle_box(struct Map_info *Map, int isle, BOUND_BOX * Box)
287 {
288  struct Plus_head *Plus;
289  P_ISLE *Isle;
290 
291  Plus = &(Map->plus);
292  Isle = Plus->Isle[isle];
293 
294  if (Isle == NULL) { /* dead */
295  Box->N = 0;
296  Box->S = 0;
297  Box->E = 0;
298  Box->W = 0;
299  Box->T = 0;
300  Box->B = 0;
301  return 0;
302  }
303  else {
304  Box->N = Isle->N;
305  Box->S = Isle->S;
306  Box->E = Isle->E;
307  Box->W = Isle->W;
308  Box->T = Isle->T;
309  Box->B = Isle->B;
310  }
311 
312  return 1;
313 }
314 
323 int Vect_get_map_box(struct Map_info *Map, BOUND_BOX * Box)
324 {
325  struct Plus_head *Plus;
326 
327  Plus = &(Map->plus);
328 
329  Box->N = Plus->box.N;
330  Box->S = Plus->box.S;
331  Box->E = Plus->box.E;
332  Box->W = Plus->box.W;
333  Box->T = Plus->box.T;
334  Box->B = Plus->box.B;
335 
336  return 1;
337 }
338 
339 
348 int Vect_region_box(struct Cell_head *Window, BOUND_BOX * Box)
349 {
350 
351  Box->N = Window->north;
352  Box->S = Window->south;
353  Box->E = Window->east;
354  Box->W = Window->west;
355  Box->T = PORT_DOUBLE_MAX;
356  Box->B = -PORT_DOUBLE_MAX;
357 
358  return 1;
359 }
int Vect_point_in_box(double x, double y, double z, BOUND_BOX *Box)
Tests for point in box.
Definition: Vlib/box.c:33
float Box[8][3]
Vertices for box.
Definition: gsd_objs.c:1420
int Vect_box_overlap(BOUND_BOX *A, BOUND_BOX *B)
Tests for overlap of two boxes.
Definition: Vlib/box.c:53
int Vect_get_area_box(struct Map_info *Map, int area, BOUND_BOX *Box)
Get boundary box of area.
Definition: Vlib/box.c:247
int y
Definition: plot.c:34
int Vect_region_box(struct Cell_head *Window, BOUND_BOX *Box)
Copy region Window to Box.
Definition: Vlib/box.c:348
int Vect_box_clip(double *x, double *y, double *c_x, double *c_y, BOUND_BOX *Box)
Clip coordinates to box, if necessary, lines extending outside of a box.
Definition: Vlib/box.c:138
int Vect_box_extend(BOUND_BOX *A, BOUND_BOX *B)
Extend box A by box B.
Definition: Vlib/box.c:93
int Vect_box_copy(BOUND_BOX *A, BOUND_BOX *B)
Copy box B to box A.
Definition: Vlib/box.c:72
int Vect_get_map_box(struct Map_info *Map, BOUND_BOX *Box)
Get boundary box of map.
Definition: Vlib/box.c:323
int Vect_get_isle_box(struct Map_info *Map, int isle, BOUND_BOX *Box)
Get boundary box of isle.
Definition: Vlib/box.c:286
return NULL
Definition: dbfopen.c:1394
tuple Map
Definition: render.py:1310
#define N
Definition: inverse.c:8
int Vect_get_line_box(struct Map_info *Map, int line, BOUND_BOX *Box)
Get boundary box of line.
Definition: Vlib/box.c:208