34 #include <Pt/Gfx/Point.h>
35 #include <Pt/Gfx/Size.h>
46 explicit BasicRect(
const BasicPoint<T>& p = BasicPoint<T>(0, 0),
47 const BasicSize<T>& s = BasicSize<T>(0, 0) )
53 explicit BasicRect(
const BasicSize<T>& s)
59 BasicRect(
const BasicPoint<T>& p1,
const BasicPoint<T>& p2)
61 , _s( p2.x() - p1.x() + 1, p2.y() - p1.y() + 1 )
65 BasicRect(
const T left,
const T right,
const T top,
const T bottom)
67 set( left, right, top, bottom );
70 BasicRect(
const BasicRect<T>& val)
78 return (_s.width() == 0 || _s.height() == 0 );
87 void set(
const BasicPoint<T>& p,
const BasicSize<T>& s)
93 void set(
const BasicPoint<T>& p1,
const BasicPoint<T>& p2)
95 this->setOrigin( p1 );
96 this->setWidth(p2.x() - p1.x() + 1);
97 this->setHeight(p2.y() - p1.y() + 1);
100 void set(
const T left,
const T right,
const T top,
const T bottom)
102 _p = BasicPoint<T>( left, top );
103 _s = BasicSize<T>( right - left + 1 , bottom - top + 1);
106 void setOrigin(
const BasicPoint<T>& p)
111 void setSize(
const BasicSize<T>& s)
136 const BasicSize<T>& size()
const
163 return _p.x() + _s.width() - 1;
168 return _p.y() + _s.height() - 1;
171 const BasicPoint<T>& topLeft()
const
176 const BasicPoint<T> topRight()
const
178 return BasicPoint<T>(this->x() + this->width() -1 , this->y());
181 const BasicPoint<T> bottomLeft()
const
183 return BasicPoint<T>(this->x(), this->y() + this->height() -1);
186 const BasicPoint<T> bottomRight()
const
188 return BasicPoint<T>(this->x() + this->width() -1,
189 this->y() + this->height() - 1);
192 bool operator==(
const BasicRect& other)
const
194 return _p == other._p && _s == other._s;
197 bool operator!=(
const BasicRect& other)
const
199 return _p != other._p || _s != other._s;
202 void unify(
const BasicRect<T>& rect)
214 const T l = std::min( this->left(), rect.left() );
215 const T t = std::min( this->top(), rect.top() );
216 const T r = std::max( this->right(), rect.right() );
217 const T b = std::max( this->bottom(), rect.bottom() );
222 BasicRect<T> intersect(
const BasicRect<T>& rect)
const
224 const T l = std::max( this->left(), rect.left() );
225 const T t = std::max( this->top(), rect.top() );
226 const T r = std::min( this->right(), rect.right() );
227 const T b = std::min( this->bottom(), rect.bottom() );
229 return r >= l && b >= t ? BasicRect<T>(l, r, t, b)
233 bool contains(
const BasicPoint<T>& p)
const
235 return p.x() >= _p.x() &&
236 p.x() < _p.x() + _s.width() &&
238 p.y() < _p.y() + _s.height();
246 typedef BasicRect<Pt::ssize_t> Rect;
247 typedef BasicRect<double> RectF;
249 inline Rect round(
const RectF& r)
251 return Rect( round(r.topLeft()),