GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2001 GRASS Development Team
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
12 *****************************************************************************/
13
14#include <stdlib.h>
15#include <grass/vector.h>
16
17/*
18 * dig_line_box ()
19 * set box to points extent
20 */
21int dig_line_box(const struct line_pnts *Points, struct bound_box *Box)
22{
23 int i;
24
25 if (Points->n_points <= 0) {
26 G_zero(Box, sizeof(struct bound_box));
27 return 0;
28 }
29
30 Box->E = Points->x[0];
31 Box->W = Points->x[0];
32 Box->N = Points->y[0];
33 Box->S = Points->y[0];
34 Box->T = Points->z[0];
35 Box->B = Points->z[0];
36
37 for (i = 1; i < Points->n_points; i++) {
38 if (Points->x[i] > Box->E)
39 Box->E = Points->x[i];
40 else if (Points->x[i] < Box->W)
41 Box->W = Points->x[i];
42
43 if (Points->y[i] > Box->N)
44 Box->N = Points->y[i];
45 else if (Points->y[i] < Box->S)
46 Box->S = Points->y[i];
47
48 if (Points->z[i] > Box->T)
49 Box->T = Points->z[i];
50 else if (Points->z[i] < Box->B)
51 Box->B = Points->z[i];
52 }
53
54 return 1;
55}
56
57/*
58 * dig_box_copy ()
59 * Copy B to A.
60 */
61int dig_box_copy(struct bound_box *A, struct bound_box *B)
62{
63
64 A->N = B->N;
65 A->S = B->S;
66 A->E = B->E;
67 A->W = B->W;
68 A->T = B->T;
69 A->B = B->B;
70
71 return 1;
72}
73
74/*
75 * dig_box_extend ()
76 * Extend A by B.
77 */
78int dig_box_extend(struct bound_box *A, struct bound_box *B)
79{
80
81 if (B->N > A->N)
82 A->N = B->N;
83 if (B->S < A->S)
84 A->S = B->S;
85 if (B->E > A->E)
86 A->E = B->E;
87 if (B->W < A->W)
88 A->W = B->W;
89 if (B->T > A->T)
90 A->T = B->T;
91 if (B->B < A->B)
92 A->B = B->B;
93
94 return 1;
95}
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
Definition gis/zero.c:21
float Box[8][3]
Vertices for box.
Definition gsd_objs.c:1451
Bounding box.
Definition dig_structs.h:62
double W
West.
Definition dig_structs.h:78
double T
Top.
Definition dig_structs.h:82
double S
South.
Definition dig_structs.h:70
double N
North.
Definition dig_structs.h:66
double E
East.
Definition dig_structs.h:74
double B
Bottom.
Definition dig_structs.h:86
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.
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)