box.c

Go to the documentation of this file.
00001 /*
00002 ****************************************************************************
00003 *
00004 * MODULE:       Vector library 
00005 *               
00006 * AUTHOR(S):    Radim Blazek
00007 *
00008 * PURPOSE:      Higher 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 "gis.h"
00019 #include "Vect.h"
00020 
00027 int 
00028 Vect_point_in_box (double x, double y, double z, BOUND_BOX *Box)
00029 {
00030   
00031     if ( x >= Box->W && x <= Box->E &&
00032          y >= Box->S && y <= Box->N &&
00033          z >= Box->B && z <= Box->T )
00034     {
00035         return 1;
00036     }
00037 
00038     return 0;
00039 }
00040 
00047 int 
00048 Vect_box_overlap (BOUND_BOX *A, BOUND_BOX *B)
00049 {
00050 
00051     if ( A->E < B->W || A->W > B->E ||
00052          A->N < B->S || A->S > B->N ||
00053          A->T < B->B || A->B > B->T )
00054     {
00055         return 0;
00056     }
00057 
00058     return 1;
00059 }
00060 
00067 int 
00068 Vect_box_copy (BOUND_BOX *A, BOUND_BOX *B)
00069 {
00070 
00071     A->N = B->N;
00072     A->S = B->S;
00073     A->E = B->E;
00074     A->W = B->W;
00075     A->T = B->T;
00076     A->B = B->B;
00077 
00078     return 1;
00079 }
00080 
00087 int 
00088 Vect_box_extend (BOUND_BOX *A, BOUND_BOX *B)
00089 {
00090 
00091     if ( B->N > A->N ) A->N = B->N;
00092     if ( B->S < A->S ) A->S = B->S;
00093     if ( B->E > A->E ) A->E = B->E;
00094     if ( B->W < A->W ) A->W = B->W;
00095     if ( B->T > A->T ) A->T = B->T;
00096     if ( B->B < A->B ) A->B = B->B;
00097 
00098     return 1;
00099 }
00100 
00107 int 
00108 Vect_get_line_box (struct Map_info *Map, int line, BOUND_BOX *Box )
00109 {
00110     struct    Plus_head *Plus;
00111     P_LINE    *Line;
00112     
00113     Plus = &(Map->plus);
00114     Line = Plus->Line[line];
00115     
00116     if ( Line == NULL ) {  /* dead */
00117         Box->N = 0;
00118         Box->S = 0;
00119         Box->E = 0;
00120         Box->W = 0;
00121         Box->T = 0;
00122         Box->B = 0;
00123         return 0;
00124     } else {
00125         Box->N = Line->N;
00126         Box->S = Line->S;
00127         Box->E = Line->E;
00128         Box->W = Line->W;
00129         Box->T = Line->T;
00130         Box->B = Line->B;
00131     }
00132 
00133     return 1;
00134 }
00135 
00142 int 
00143 Vect_get_area_box (struct Map_info *Map, int area, BOUND_BOX *Box )
00144 {
00145     struct    Plus_head *Plus;
00146     P_AREA    *Area;
00147     
00148     Plus = &(Map->plus);
00149     Area = Plus->Area[area];
00150     
00151     if ( Area == NULL ) {  /* dead */
00152         Box->N = 0;
00153         Box->S = 0;
00154         Box->E = 0;
00155         Box->W = 0;
00156         Box->T = 0;
00157         Box->B = 0;
00158         return 0;
00159     } else {
00160         Box->N = Area->N;
00161         Box->S = Area->S;
00162         Box->E = Area->E;
00163         Box->W = Area->W;
00164         Box->T = Area->T;
00165         Box->B = Area->B;
00166     }
00167 
00168     return 1;
00169 }
00170 
00177 int 
00178 Vect_get_isle_box (struct Map_info *Map, int isle, BOUND_BOX *Box )
00179 {
00180     struct    Plus_head *Plus;
00181     P_ISLE    *Isle;
00182     
00183     Plus = &(Map->plus);
00184     Isle = Plus->Isle[isle];
00185     
00186     if ( Isle == NULL ) {  /* dead */
00187         Box->N = 0;
00188         Box->S = 0;
00189         Box->E = 0;
00190         Box->W = 0;
00191         Box->T = 0;
00192         Box->B = 0;
00193         return 0;
00194     } else {
00195         Box->N = Isle->N;
00196         Box->S = Isle->S;
00197         Box->E = Isle->E;
00198         Box->W = Isle->W;
00199         Box->T = Isle->T;
00200         Box->B = Isle->B;
00201     }
00202 
00203     return 1;
00204 }
00205 
00212 int 
00213 Vect_get_map_box (struct Map_info *Map, BOUND_BOX *Box )
00214 {
00215     struct    Plus_head *Plus;
00216     
00217     Plus = &(Map->plus);
00218     
00219     Box->N = Plus->box.N;
00220     Box->S = Plus->box.S;
00221     Box->E = Plus->box.E;
00222     Box->W = Plus->box.W;
00223     Box->T = Plus->box.T;
00224     Box->B = Plus->box.B;
00225 
00226     return 1;
00227 }
00228 
00229 
00236 int 
00237 Vect_region_box ( struct Cell_head *Window, BOUND_BOX *Box )
00238 {
00239     
00240     Box->N = Window->north;
00241     Box->S = Window->south;
00242     Box->E = Window->east;
00243     Box->W = Window->west;
00244     Box->T = PORT_DOUBLE_MAX;
00245     Box->B = -PORT_DOUBLE_MAX;
00246 
00247     return 1;
00248 }
00249 

Generated on Sat Jul 22 22:05:56 2006 for GRASS by  doxygen 1.4.7