TeBox.h File Reference


Detailed Description

Definition in file TeBox.h.

#include "TeDefines.h"
#include "TeCoord2D.h"
#include "float.h"

Go to the source code of this file.

Data Structures

struct  TeBox
 Provides support for dealing with a rectangular a box. Used by all geometrical representations. More...

Functions

TL_DLL int adjustBox (TeBox &bb)
TL_DLL TeBox adjustToCut (TeBox &box, double bWidth, double bHeight)
 finds the correspondent smallest box that allows a box to be cut in blocks of a given size
TL_DLL TeBox makeBox (double x1, double y1, double x2, double y2, const double &tol=0.0)
 builds a box
TL_DLL TePolygon polygonFromBox (const TeBox &bb)
TL_DLL void updateBox (TeBox &box, const TeGeometry &geo)
 update a box to include a geometry
TL_DLL void updateBox (TeBox &box, const TeBox &other)
 update a box to include another box
TL_DLL void updateBox (TeBox &box, const TeCoord2D &pt)
 update a box to include a coordinate
TL_DLL void zoomIn (TeBox &box, double t=.8)
 increases the box by a factor t
TL_DLL void zoomOut (TeBox &box, double t=.8)
 decreases box by a factor of t


Function Documentation

TL_DLL int adjustBox ( TeBox bb  ) 

Definition at line 189 of file TeBox.cpp.

References TeCompareDouble(), TeBox::x1_, TeBox::x2_, TeBox::y1_, and TeBox::y2_.

00190 {
00191         int precision = 4;
00192         double factor =  pow(10., precision);
00193         double tol = 1 / factor;
00194         while (( TeCompareDouble( bb.x1_, bb.x2_, precision ) == true ) || 
00195                    ( TeCompareDouble( bb.y1_, bb.y2_, precision ) == true ) )
00196         {
00197                 precision--;
00198                 tol = 1 / pow(10., precision);
00199                 if ( TeCompareDouble( bb.x1_, bb.x2_, precision ) == true )
00200                 {
00201                         bb.x1_ -= tol;
00202                         bb.x2_ += tol;
00203                 }
00204                 if ( TeCompareDouble( bb.y1_, bb.y2_, precision ) == true )
00205                 {
00206                         bb.y1_ -= tol;
00207                         bb.y2_ += tol;
00208                 }
00209                 if (precision == 0)
00210                         break;          
00211         }
00212         return precision;
00213 }

TL_DLL TeBox adjustToCut ( TeBox box,
double  bWidth,
double  bHeight 
)

Definition at line 120 of file TeBox.cpp.

References TeBox::x1(), TeBox::x2(), TeBox::y1(), and TeBox::y2().

00121 {
00122         double auxD;
00123         int auxI;
00124 
00125         int magicX; 
00126         auxD = box.x1()/bWidth;
00127         auxI = (int)(box.x1()/bWidth);
00128         if (box.x1() < 0 && (auxD - auxI) != 0)
00129                 magicX = (int) (box.x1()/bWidth - 1);
00130         else
00131                 magicX = auxI;
00132 
00133         int magicY;
00134         auxD = box.y1()/bHeight;
00135         auxI = (int)(box.y1()/bHeight);
00136         if (box.y1() < 0 && (auxD - auxI) != 0)
00137                 magicY  = (int)(box.y1()/bHeight - 1);
00138         else
00139                 magicY  = auxI;
00140                 
00141         double xi = magicX*bWidth;
00142         double yi = magicY*bHeight;
00143 
00144         int magicX2;
00145         auxD = box.x2()/bWidth;
00146         auxI = (int)(box.x2()/bWidth);
00147         if ((box.x2() < 0) || (auxD - auxI) == 0)
00148                 magicX2 = (int) (box.x2()/bWidth);
00149         else
00150                 magicX2 = (int) (box.x2()/bWidth + 1);
00151 
00152 
00153         int magicY2;
00154         auxD = box.y2()/bHeight;
00155         auxI = (int)(box.y2()/bHeight);
00156         if ((box.y2() < 0) || (auxD - auxI) == 0)
00157                 magicY2 = (int) (box.y2()/bHeight);
00158         else
00159                 magicY2 = (int) (box.y2()/bHeight + 1);
00160 
00161 
00162         double xf = (magicX2)*bWidth;
00163         double yf = (magicY2)*bHeight;
00164 
00165         return TeBox(xi,yi,xf,yf);
00166 }

TL_DLL TeBox makeBox ( double  x1,
double  y1,
double  x2,
double  y2,
const double &  tol = 0.0 
)

Definition at line 88 of file TeBox.cpp.

00089 {
00090         double xlo, xhi;
00091 
00092         if(x1 > x2)
00093         {
00094                 xhi = x1;
00095                 xlo = x2;
00096         }
00097         else
00098         {
00099                 xhi = x2;
00100                 xlo = x1;
00101         }
00102 
00103         double ylo, yhi;        
00104         if(y1 > y2)
00105         {
00106                 yhi = y1;
00107                 ylo = y2;
00108         }
00109         else
00110         {
00111                 yhi = y2;
00112                 ylo = y1;
00113         }
00114 
00115         return TeBox(xlo - tol, ylo - tol, xhi + tol, yhi + tol);
00116 }

TL_DLL TePolygon polygonFromBox ( const TeBox bb  ) 

Definition at line 168 of file TeBox.cpp.

References TeGeomComposite< T >::add(), TeBox::x1_, TeBox::x2_, TeBox::y1_, and TeBox::y2_.

00169 {
00170         TePolygon poly;
00171         TeLine2D line;
00172         
00173         TeCoord2D ll (bb.x1_, bb.y1_);
00174         TeCoord2D ul (bb.x1_, bb.y2_);
00175         TeCoord2D ur (bb.x2_, bb.y2_);
00176         TeCoord2D lr (bb.x2_, bb.y1_);
00177 
00178         line.add(ll);
00179         line.add(ul);
00180         line.add(ur);
00181         line.add(lr);
00182         line.add(ll);
00183 
00184         TeLinearRing ring(line);
00185         poly.add(ring);
00186         return poly;
00187 }

TL_DLL void updateBox ( TeBox box,
const TeGeometry geo 
)

Definition at line 82 of file TeBox.cpp.

References TeGeometry::box(), and updateBox().

00083 {
00084                 updateBox ( box, geo.box() );
00085 }

TL_DLL void updateBox ( TeBox box,
const TeBox other 
)

Definition at line 69 of file TeBox.cpp.

References TeBox::x1_, TeBox::x2_, TeBox::y1_, and TeBox::y2_.

00070 {
00071                 if ( other.x1_ <= box.x1_ ) 
00072                         box.x1_ = other.x1_;
00073                 if ( other.x2_ >= box.x2_ )
00074                         box.x2_ = other.x2_;
00075                 if ( other.y1_ <= box.y1_ )
00076                         box.y1_ = other.y1_;
00077                 if ( other.y2_ >= box.y2_ )
00078                         box.y2_ = other.y2_;
00079 }

TL_DLL void updateBox ( TeBox box,
const TeCoord2D pt 
)

Definition at line 53 of file TeBox.cpp.

References TeCoord2D::x(), TeBox::x1_, TeBox::x2_, TeCoord2D::y(), TeBox::y1_, and TeBox::y2_.

00054 {
00055         if ( pt.x() <= box.x1_ )
00056                 box.x1_  = pt.x();
00057         
00058         if ( pt.x() >= box.x2_ )
00059                  box.x2_ =  pt.x();
00060 
00061         if ( pt.y() <= box.y1_ )
00062                 box.y1_ =  pt.y();
00063 
00064         if ( pt.y() >= box.y2_ )
00065                 box.y2_ =  pt.y();
00066 }

TL_DLL void zoomIn ( TeBox box,
double  t = .8 
)

Definition at line 27 of file TeBox.cpp.

References TeBox::center(), TeBox::height(), TeBox::width(), TeCoord2D::x(), TeBox::x1_, TeBox::x2_, TeCoord2D::y(), TeBox::y1_, and TeBox::y2_.

00028 {
00029                 TeCoord2D c = box.center ();
00030                 double w    = box.width ()*t/2.;
00031                 double h    = box.height ()*t/2.;
00032                 box.x1_ = c.x() - w;
00033                 box.x2_ = c.x() + w;
00034                 box.y1_ = c.y() - h;
00035                 box.y2_ = c.y() + h;
00036 }

TL_DLL void zoomOut ( TeBox box,
double  t = .8 
)

Definition at line 39 of file TeBox.cpp.

References TeBox::center(), TeBox::height(), TeBox::width(), TeCoord2D::x(), TeBox::x1_, TeBox::x2_, TeCoord2D::y(), TeBox::y1_, and TeBox::y2_.

00040 {
00041                 TeCoord2D c = box.center ();
00042                 double w = box.width ()/t/2.;
00043                 double h = box.height ()/t/2.;
00044                 box.x1_ = c.x() - w;
00045                 box.x2_ = c.x() + w;
00046                 box.y1_ = c.y() - h;
00047                 box.y2_ = c.y() + h;
00048 }


Generated on Sun Jul 29 04:03:43 2012 for TerraLib - Development Source by  doxygen 1.5.3