00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <grass/Vect.h>
00021
00022
00023
00024
00025
00026 int
00027 dig_line_box (struct line_pnts *Points, BOUND_BOX *Box){
00028 int i;
00029
00030 if ( Points->n_points <= 0 ) {
00031 Box->N = 0;
00032 Box->S = 0;
00033 Box->E = 0;
00034 Box->W = 0;
00035 Box->T = 0;
00036 Box->B = 0;
00037 return 0;
00038 }
00039
00040 Box->E = Points->x[0];
00041 Box->W = Points->x[0];
00042 Box->N = Points->y[0];
00043 Box->S = Points->y[0];
00044 Box->T = Points->z[0];
00045 Box->B = Points->z[0];
00046
00047 for ( i = 1; i < Points->n_points; i++ ) {
00048 if ( Points->x[i] > Box->E ) Box->E = Points->x[i];
00049 else if ( Points->x[i] < Box->W ) Box->W = Points->x[i];
00050
00051 if ( Points->y[i] > Box->N ) Box->N = Points->y[i];
00052 else if ( Points->y[i] < Box->S ) Box->S = Points->y[i];
00053
00054 if ( Points->z[i] > Box->T ) Box->T = Points->z[i];
00055 else if ( Points->z[i] < Box->B ) Box->B = Points->z[i];
00056 }
00057
00058 return 1;
00059 }
00060
00061
00062
00063
00064
00065 int
00066 dig_box_copy (BOUND_BOX *A, BOUND_BOX *B)
00067 {
00068
00069 A->N = B->N;
00070 A->S = B->S;
00071 A->E = B->E;
00072 A->W = B->W;
00073 A->T = B->T;
00074 A->B = B->B;
00075
00076 return 1;
00077 }
00078
00079
00080
00081
00082
00083 int
00084 dig_box_extend (BOUND_BOX *A, BOUND_BOX *B)
00085 {
00086
00087 if ( B->N > A->N ) A->N = B->N;
00088 if ( B->S < A->S ) A->S = B->S;
00089 if ( B->E > A->E ) A->E = B->E;
00090 if ( B->W < A->W ) A->W = B->W;
00091 if ( B->T > A->T ) A->T = B->T;
00092 if ( B->B < A->B ) A->B = B->B;
00093
00094 return 1;
00095 }
00096