diglib/box.c

Go to the documentation of this file.
00001 /*
00002 * $Id: box.c,v 1.4 2006/02/09 03:08:58 glynn Exp $
00003 *
00004 ****************************************************************************
00005 *
00006 * MODULE:       Vector library 
00007 *               
00008 * AUTHOR(S):    Radim Blazek
00009 *
00010 * PURPOSE:      Lower level functions for reading/writing/manipulating vectors.
00011 *
00012 * COPYRIGHT:    (C) 2001 by the GRASS Development Team
00013 *
00014 *               This program is free software under the GNU General Public
00015 *               License (>=v2). Read the file COPYING that comes with GRASS
00016 *               for details.
00017 *
00018 *****************************************************************************/
00019 #include <stdlib.h>
00020 #include <grass/Vect.h>
00021 
00022 /* 
00023 *  dig_line_box ()
00024 *  set box to points extent
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 *  dig_box_copy ()
00063 *  Copy B to A.
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 * dig_box_extend ()
00081 * Extend A by B.
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 

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5