1 /* === S I N F G =========================================================== */
3 ** \brief Rectangle Class
5 ** $Id: rect.h,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_RECT_H
25 #define __SINFG_RECT_H
27 /* === H E A D E R S ======================================================= */
35 /* === M A C R O S ========================================================= */
37 /* === T Y P E D E F S ===================================================== */
39 /* === C L A S S E S & S T R U C T S ======================================= */
43 class Rect : public etl::rect<Real>
47 using etl::rect<Real>::set_point;
48 using etl::rect<Real>::expand;
49 using etl::rect<Real>::set;
51 static Rect full_plane();
65 Rect(const Point& x) { set_point(x); }
67 Rect(const Point& min, const Point& max) { set_point(min); expand(max); }
69 Rect(const value_type &x1,const value_type &y1) { set_point(x1,y1); }
71 Rect(const value_type &x1,const value_type &y1,
72 const value_type &x2,const value_type &y2)
78 void set_point(const Point& max) { set_point(max[0],max[1]); }
80 Rect& expand(const Point& max) { expand(max[0],max[1]); return *this; }
82 Rect& expand(const Real& r) { minx-=r; miny-=r; maxx+=r; maxy+=r; return *this; }
84 Rect& expand_x(const Real& r) { minx-=r; maxx+=r; return *this; }
86 Rect& expand_y(const Real& r) { miny-=r; maxy+=r; return *this; }
88 Rect& set(const Point& min,const Point& max) { set(min[0],min[1],max[0],max[1]); return *this; }
90 Point get_min()const { return Point(minx,miny); }
91 Point get_max()const { return Point(maxx,maxy); }
93 bool is_inside(const Point& x) { return x[0]>minx && x[0]<maxx && x[1]>miny && x[1]<maxy; }
97 return (maxx-minx)*(maxy-miny);
102 Rect& operator+=(const Vector& rhs)
104 minx+=rhs[0]; miny+=rhs[1];
105 maxx+=rhs[0]; maxy+=rhs[1];
109 Rect& operator-=(const Vector& rhs)
111 minx-=rhs[0]; miny-=rhs[1];
112 maxx-=rhs[0]; maxy-=rhs[1];
116 Rect& operator*=(const Real& rhs)
118 minx*=rhs; miny*=rhs;
119 maxx*=rhs; maxy*=rhs;
123 Rect& operator/=(Real rhs)
125 rhs=1.0/rhs; // Avoid doing several divisions
126 minx*=rhs; miny*=rhs;
127 maxx*=rhs; maxy*=rhs;
131 Rect& operator&=(const Rect& rhs)
133 if(rhs.area()>0.00000001 && area()>0.00000001)
134 etl::set_intersect(*this,*this,rhs);
140 Rect& operator|=(const Rect& rhs)
142 if(rhs.area()>0.00000001 && area()>0.00000001)
143 etl::set_union(*this,*this,rhs);
146 if(area()<rhs.area())
152 Rect operator+(const Vector& rhs)const { return Rect(*this)+=rhs; }
154 Rect operator-(const Vector& rhs)const { return Rect(*this)-=rhs; }
156 Rect operator*(const Real& rhs)const { return Rect(*this)*=rhs; }
158 Rect operator/(const Real& rhs)const { return Rect(*this)/=rhs; }
160 Rect operator&(const Rect& rhs)const { return Rect(*this)&=rhs; }
162 Rect operator|(const Rect& rhs)const { return Rect(*this)|=rhs; }
164 bool operator&&(const Rect& rhs)const { return etl::intersect(*this, rhs); }
166 bool is_valid()const { return valid(); }
167 }; // END of class Rect
169 }; // END of namespace sinfg
171 /* === E N D =============================================================== */