34 #include <Pt/Gfx/Point.h>
35 #include <Pt/Gfx/Size.h>
60 Rect(Float width, Float height)
68 , _s(p2.x() - p1.x(), p2.y() - p1.y())
72 Rect(Float left, Float right, Float top, Float bottom)
74 set(left, right, top, bottom);
85 return (_s.width() == 0 || _s.height() == 0);
103 this->setWidth(p2.x() - p1.x());
104 this->setHeight(p2.y() - p1.y());
107 void set(Float width, Float height)
110 _s.set(width, height);
113 void set(Float left, Float right, Float top, Float bottom)
115 _p =
Point(left, top);
116 _s =
Size(right - left, bottom - top);
119 const Point& origin()
const
124 void setOrigin(
const Point& p)
129 void setSize(
const Size& s)
134 void setWidth(Float w)
139 void setHeight(Float h)
154 const Size& size()
const
181 return _p.x() + _s.width();
186 return _p.y() + _s.height();
189 const Point& topLeft()
const
194 Point topRight()
const
196 return Point(this->x() + this->width(), this->y());
199 Point bottomLeft()
const
201 return Point(this->x(), this->y() + this->height());
204 Point bottomRight()
const
206 return Point(this->x() + this->width(),
207 this->y() + this->height());
210 bool operator==(
const Rect& other)
const
212 return _p == other._p && _s == other._s;
215 bool operator!=(
const Rect& other)
const
217 return _p != other._p || _s != other._s;
220 void shift(Float dx, Float dy)
226 void expand(Float dw, Float dh)
232 void shrink(Float dw, Float dh)
238 void unify(
const Rect& rect)
250 const Float l = std::min(this->left(), rect.left());
251 const Float t = std::min(this->top(), rect.top());
252 const Float r = std::max(this->right(), rect.right());
253 const Float b = std::max(this->bottom(), rect.bottom());
258 Rect intersect(
const Rect& rect)
const
260 const Float l = std::max(this->left(), rect.left());
261 const Float t = std::max(this->top(), rect.top());
262 const Float r = std::min(this->right(), rect.right());
263 const Float b = std::min(this->bottom(), rect.bottom());
265 return r >= l && b >= t ?
Rect(l, r, t, b)
269 bool contains(
const Point& p)
const
271 return p.x() >= _p.x() &&
272 p.x() < _p.x() + _s.width() &&
274 p.y() < _p.y() + _s.height();
302 RectI(Int width, Int height)
310 , _s(p2.x() - p1.x(), p2.y() - p1.y())
314 RectI(Int left, Int right, Int top, Int bottom)
316 set(left, right, top, bottom);
327 return (_s.width() == 0 || _s.height() == 0);
345 this->setWidth(p2.x() - p1.x());
346 this->setHeight(p2.y() - p1.y());
349 void set(Int width, Int height)
352 _s.set(width, height);
355 void set(Int left, Int right, Int top, Int bottom)
358 _s =
SizeI(right - left, bottom - top);
361 const PointI& origin()
const
366 void setOrigin(
const PointI& p)
371 void setSize(
const SizeI& s)
381 void setHeight(Int h)
396 const SizeI& size()
const
423 return _p.x() + _s.width();
428 return _p.y() + _s.height();
431 const PointI& topLeft()
const
438 return PointI(this->x() + this->width(), this->y());
443 return PointI(this->x(), this->y() + this->height());
446 PointI bottomRight()
const
448 return PointI(this->x() + this->width(),
449 this->y() + this->height());
452 bool operator==(
const RectI& other)
const
454 return _p == other._p && _s == other._s;
457 bool operator!=(
const RectI& other)
const
459 return _p != other._p || _s != other._s;
462 void shift(Int dx, Int dy)
468 void expand(Int dw, Int dh)
474 void shrink(Int dw, Int dh)
480 void unify(
const RectI& rect)
492 const Int l = std::min(this->left(), rect.left());
493 const Int t = std::min(this->top(), rect.top());
494 const Int r = std::max(this->right(), rect.right());
495 const Int b = std::max(this->bottom(), rect.bottom());
502 const Int l = std::max(this->left(), rect.left());
503 const Int t = std::max(this->top(), rect.top());
504 const Int r = std::min(this->right(), rect.right());
505 const Int b = std::min(this->bottom(), rect.bottom());
507 return r >= l && b >= t ?
RectI(l, r, t, b)
511 bool contains(
const PointI& p)
const
513 return p.x() >= _p.x() &&
514 p.x() < _p.x() + _s.width() &&
516 p.y() < _p.y() + _s.height();