GRASS Programmer's Manual 6.4.1(2011)
|
00001 /* 00002 **************************************************************************** 00003 * 00004 * MODULE: Vector library 00005 * 00006 * AUTHOR(S): Radim Blazek 00007 * 00008 * PURPOSE: Lower level functions for reading/writing/manipulating vectors. 00009 * 00010 * COPYRIGHT: (C) 2001 by the GRASS Development Team 00011 * 00012 * This program is free software under the GNU General Public 00013 * License (>=v2). Read the file COPYING that comes with GRASS 00014 * for details. 00015 * 00016 *****************************************************************************/ 00017 #include <stdlib.h> 00018 #include <grass/Vect.h> 00019 00020 /* 00021 * dig_line_box () 00022 * set box to points extent 00023 */ 00024 int dig_line_box(struct line_pnts *Points, BOUND_BOX * Box) 00025 { 00026 int i; 00027 00028 if (Points->n_points <= 0) { 00029 Box->N = 0; 00030 Box->S = 0; 00031 Box->E = 0; 00032 Box->W = 0; 00033 Box->T = 0; 00034 Box->B = 0; 00035 return 0; 00036 } 00037 00038 Box->E = Points->x[0]; 00039 Box->W = Points->x[0]; 00040 Box->N = Points->y[0]; 00041 Box->S = Points->y[0]; 00042 Box->T = Points->z[0]; 00043 Box->B = Points->z[0]; 00044 00045 for (i = 1; i < Points->n_points; i++) { 00046 if (Points->x[i] > Box->E) 00047 Box->E = Points->x[i]; 00048 else if (Points->x[i] < Box->W) 00049 Box->W = Points->x[i]; 00050 00051 if (Points->y[i] > Box->N) 00052 Box->N = Points->y[i]; 00053 else if (Points->y[i] < Box->S) 00054 Box->S = Points->y[i]; 00055 00056 if (Points->z[i] > Box->T) 00057 Box->T = Points->z[i]; 00058 else if (Points->z[i] < Box->B) 00059 Box->B = Points->z[i]; 00060 } 00061 00062 return 1; 00063 } 00064 00065 /* 00066 * dig_box_copy () 00067 * Copy B to A. 00068 */ 00069 int dig_box_copy(BOUND_BOX * A, BOUND_BOX * B) 00070 { 00071 00072 A->N = B->N; 00073 A->S = B->S; 00074 A->E = B->E; 00075 A->W = B->W; 00076 A->T = B->T; 00077 A->B = B->B; 00078 00079 return 1; 00080 } 00081 00082 /* 00083 * dig_box_extend () 00084 * Extend A by B. 00085 */ 00086 int dig_box_extend(BOUND_BOX * A, BOUND_BOX * B) 00087 { 00088 00089 if (B->N > A->N) 00090 A->N = B->N; 00091 if (B->S < A->S) 00092 A->S = B->S; 00093 if (B->E > A->E) 00094 A->E = B->E; 00095 if (B->W < A->W) 00096 A->W = B->W; 00097 if (B->T > A->T) 00098 A->T = B->T; 00099 if (B->B < A->B) 00100 A->B = B->B; 00101 00102 return 1; 00103 }