34#include <Pt/Gfx/Point.h>
35#include <Pt/Gfx/Size.h>
85 explicit Rect(
const Size& s)
91 Rect(Float width, Float height)
99 , _s(p2.x() - p1.x(), p2.y() - p1.y())
103 Rect(
const Rect& val)
113 return (_s.width() == 0 || _s.height() == 0);
118 static Rect
fromLTRB(Float left, Float top, Float right, Float bottom)
120 return Rect(
Point(left, top),
Size(right - left, bottom - top));
125 static Rect
fromXYWH(Float x, Float y, Float w, Float h)
136 void set(
const Point& p,
const Size& s)
142 void set(
const Point& p1,
const Point& p2)
145 this->setWidth(p2.x() - p1.x());
146 this->setHeight(p2.y() - p1.y());
149 void set(Float width, Float height)
152 _s.set(width, height);
155 const Point& origin()
const
160 void setOrigin(
const Point& p)
165 void setSize(
const Size& s)
170 void setWidth(Float w)
175 void setHeight(Float h)
190 const Size& size()
const
217 return _p.x() + _s.width();
222 return _p.y() + _s.height();
225 const Point& topLeft()
const
230 Point topRight()
const
232 return Point(this->x() + this->width(), this->y());
235 Point bottomLeft()
const
237 return Point(this->x(), this->y() + this->height());
240 Point bottomRight()
const
242 return Point(this->x() + this->width(),
243 this->y() + this->height());
246 bool isEqual(
const Rect& other, Float eps = FloatNearlyZero)
const
248 return _p.isEqual(other._p, eps) && _s.isEqual(other._s, eps);
251 void move(Float dx, Float dy)
257 void expand(Float dw, Float dh)
263 void shrink(Float dw, Float dh)
269 void unify(
const Rect& rect)
281 const Float l = std::min(this->left(), rect.left());
282 const Float t = std::min(this->top(), rect.top());
283 const Float r = std::max(this->right(), rect.right());
284 const Float b = std::max(this->bottom(), rect.bottom());
287 _s = Size(r - l, b - t);
294 const Float l = std::max(this->left(), rect.left());
295 const Float t = std::max(this->top(), rect.top());
296 const Float r = std::min(this->right(), rect.right());
297 const Float b = std::min(this->bottom(), rect.bottom());
307 return p.x() >= _p.x() &&
308 p.x() < _p.x() + _s.width() &&
310 p.y() < _p.y() + _s.height();
317 return r.left() >= this->left() &&
318 r.right() <= this->right() &&
319 r.top() >= this->top() &&
320 r.bottom() <= this->bottom();
327 return this->right() > r.left() &&
328 r.right() > this->left() &&
329 this->bottom() > r.top() &&
330 r.bottom() > this->top();
337 return Point(_p.x() + _s.width() / 2, _p.y() + _s.height() / 2);
347 _s.setWidth(-_s.width());
351 _p.addY(_s.height());
352 _s.setHeight(-_s.height());
423 explicit RectI(
const SizeI& s)
429 RectI(Int width, Int height)
437 , _s(p2.x() - p1.x(), p2.y() - p1.y())
441 RectI(
const RectI& val)
451 return (_s.width() == 0 || _s.height() == 0);
456 static RectI
fromLTRB(Int left, Int top, Int right, Int bottom)
458 return RectI(
PointI(left, top),
SizeI(right - left, bottom - top));
474 void set(
const PointI& p,
const SizeI& s)
480 void set(
const PointI& p1,
const PointI& p2)
483 this->setWidth(p2.x() - p1.x());
484 this->setHeight(p2.y() - p1.y());
487 void set(Int width, Int height)
490 _s.set(width, height);
493 const PointI& origin()
const
498 void setOrigin(
const PointI& p)
503 void setSize(
const SizeI& s)
513 void setHeight(Int h)
528 const SizeI& size()
const
555 return _p.x() + _s.width();
560 return _p.y() + _s.height();
563 const PointI& topLeft()
const
568 PointI topRight()
const
570 return PointI(this->x() + this->width(), this->y());
573 PointI bottomLeft()
const
575 return PointI(this->x(), this->y() + this->height());
578 PointI bottomRight()
const
580 return PointI(this->x() + this->width(),
581 this->y() + this->height());
584 bool operator==(
const RectI& other)
const
586 return _p == other._p && _s == other._s;
589 bool operator!=(
const RectI& other)
const
591 return _p != other._p || _s != other._s;
594 void move(Int dx, Int dy)
600 void expand(Int dw, Int dh)
606 void shrink(Int dw, Int dh)
612 void unify(
const RectI& rect)
624 const Int l = std::min(this->left(), rect.left());
625 const Int t = std::min(this->top(), rect.top());
626 const Int r = std::max(this->right(), rect.right());
627 const Int b = std::max(this->bottom(), rect.bottom());
630 _s = SizeI(r - l, b - t);
637 const Int l = std::max(this->left(), rect.left());
638 const Int t = std::max(this->top(), rect.top());
639 const Int r = std::min(this->right(), rect.right());
640 const Int b = std::min(this->bottom(), rect.bottom());
650 return p.x() >= _p.x() &&
651 p.x() < _p.x() + _s.width() &&
653 p.y() < _p.y() + _s.height();
660 return r.left() >= this->left() &&
661 r.right() <= this->right() &&
662 r.top() >= this->top() &&
663 r.bottom() <= this->bottom();
670 return this->right() > r.left() &&
671 r.right() > this->left() &&
672 this->bottom() > r.top() &&
673 r.bottom() > this->top();
680 return PointI(_p.x() + _s.width() / 2, _p.y() + _s.height() / 2);
690 _s.setWidth(-_s.width());
694 _p.addY(_s.height());
695 _s.setHeight(-_s.height());
727 return RectI(_p.round(), _s.round());
732 return RectI(_p.floor(), _s.floor());
737 return RectI(_p.ceil(), _s.ceil());
742 const Int l =
static_cast<Int
>(std::floor(this->left()));
743 const Int t =
static_cast<Int
>(std::floor(this->top()));
744 const Int r =
static_cast<Int
>(std::ceil(this->right()));
745 const Int b =
static_cast<Int
>(std::ceil(this->bottom()));
751 const Int l =
static_cast<Int
>(std::ceil(this->left()));
752 const Int t =
static_cast<Int
>(std::ceil(this->top()));
753 const Int r =
static_cast<Int
>(std::floor(this->right()));
754 const Int b =
static_cast<Int
>(std::floor(this->bottom()));
Integer X and Y coordinates.
Definition Point.h:292
Floating-point X and Y coordinates.
Definition Point.h:73
Integer rectangle.
Definition Rect.h:414
bool contains(const RectI &r) const
Returns true if the given rect is entirely inside this rect.
Definition Rect.h:658
static RectI fromXYWH(Int x, Int y, Int w, Int h)
Creates a rect from x, y, width, and height.
Definition Rect.h:463
bool contains(const PointI &p) const
Returns true if the given point is inside or on the edge of this rect.
Definition Rect.h:648
bool intersects(const RectI &r) const
Returns true if this rect overlaps with the given rect.
Definition Rect.h:668
static RectI fromLTRB(Int left, Int top, Int right, Int bottom)
Creates a rect from left, top, right, and bottom edges.
Definition Rect.h:456
RectI toNormalized() const
Returns a normalized copy of this rect.
Definition Rect.h:701
RectI toIntersected(const RectI &rect) const
Returns the intersection of this rect and another, or an empty rect if they do not overlap.
Definition Rect.h:635
PointI center() const
Returns the center point of this rect.
Definition Rect.h:678
void normalize()
Normalizes this rect so that width and height are non-negative.
Definition Rect.h:685
bool isEmpty() const
Returns true if width or height is zero.
Definition Rect.h:449
Floating-point rectangle.
Definition Rect.h:76
Point center() const
Returns the center point of this rect.
Definition Rect.h:335
Rect toIntersected(const Rect &rect) const
Returns the intersection of this rect and another, or an empty rect if they do not overlap.
Definition Rect.h:292
bool intersects(const Rect &r) const
Returns true if this rect overlaps with the given rect.
Definition Rect.h:325
RectI roundIn() const
Returns the largest integer rect contained within this rect.
Definition Rect.h:749
bool contains(const Rect &r) const
Returns true if the given rect is entirely inside this rect.
Definition Rect.h:315
static Rect fromLTRB(Float left, Float top, Float right, Float bottom)
Creates a rect from left, top, right, and bottom edges.
Definition Rect.h:118
RectI floor() const
Floors each component and returns a RectI.
Definition Rect.h:730
static Rect fromXYWH(Float x, Float y, Float w, Float h)
Creates a rect from x, y, width, and height.
Definition Rect.h:125
Rect & operator=(const RectI &r)
Assigns from a RectI by widening the coordinates.
Definition Rect.h:718
bool contains(const Point &p) const
Returns true if the given point is inside or on the edge of this rect.
Definition Rect.h:305
RectI roundOut() const
Returns the smallest enclosing integer rect.
Definition Rect.h:740
RectI ceil() const
Ceils each component and returns a RectI.
Definition Rect.h:735
RectI round() const
Rounds each component to the nearest integer and returns a RectI.
Definition Rect.h:725
Rect toNormalized() const
Returns a normalized copy of this rect.
Definition Rect.h:358
void normalize()
Normalizes this rect so that width and height are non-negative.
Definition Rect.h:342
bool isEmpty() const
Returns true if width or height is zero.
Definition Rect.h:111
Integer width and height.
Definition Size.h:279
Floating-point width and height.
Definition Size.h:69
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33