31 : origin(origin), size(size) {}
34 : origin(components[0], components[1]),
35 size(components[2], components[3]) {}
38 : origin(x, y), size(width, height) {}
44 return TRect(left, top, right - left, bottom - top);
48 return TRect(x, y, width, height);
60 auto left = points[0].x;
61 auto top = points[0].y;
62 auto right = points[0].x;
63 auto bottom = points[0].y;
64 if (points.size() > 1) {
65 for (
size_t i = 1; i < points.size(); i++) {
66 left = std::min(left, points[i].x);
67 top = std::min(top, points[i].y);
68 right = std::max(right, points[i].x);
69 bottom = std::max(bottom, points[i].y);
77 : origin(static_cast<
TPoint<
Type>>(other.origin)),
78 size(static_cast<
TSize<
Type>>(other.size)) {}
91 return TRect({origin.
x * scale, origin.
y * scale},
105 return p.
x >= origin.
x && p.
x < origin.
x + size.
width && p.
y >= origin.
y &&
118 return std::min(origin.
x, origin.
x + size.
width);
122 return std::min(origin.
y, origin.
y + size.
height);
126 return std::max(origin.
x, origin.
x + size.
width);
130 return std::max(origin.
y, origin.
y + size.
height);
134 const auto left = std::min(origin.
x, origin.
x + size.
width);
135 const auto top = std::min(origin.
y, origin.
y + size.
height);
136 const auto right = std::max(origin.
x, origin.
x + size.
width);
137 const auto bottom = std::max(origin.
y, origin.
y + size.
height);
138 return {left, top, right, bottom};
142 auto [left, top, right, bottom] =
GetLTRB();
150 for (
size_t i = 0; i < points.size(); i++) {
151 points[i] = transform * points[i];
167 std::min(this_ltrb[1], other_ltrb[1]),
168 std::max(this_ltrb[2], other_ltrb[2]),
169 std::max(this_ltrb[3], other_ltrb[3])
178 std::max(this_ltrb[1], other_ltrb[1]),
179 std::min(this_ltrb[2], other_ltrb[2]),
180 std::min(this_ltrb[3], other_ltrb[3])
182 if (intersection.size.IsEmpty()) {
189 return Interesection(o).has_value();
203 out <<
"(" << r.
origin <<
", " << r.
size <<
")";
constexpr TRect(TSize< Type > size)
constexpr TRect operator+(const TRect &r) const
constexpr bool IsEmpty() const
constexpr bool Contains(const TRect &o) const
constexpr TRect operator*(Type scale) const
static constexpr std::optional< TRect > MakePointBounds(const std::vector< TPoint< Type >> &points)
constexpr TRect operator-(const TRect &r) const
constexpr auto GetRight() const
constexpr bool Contains(const TPoint< Type > &p) const
constexpr TRect operator*(const TRect &r) const
constexpr TRect(const Type components[4])
constexpr TRect(const TRect< U > &other)
constexpr auto GetTop() const
constexpr bool IsZero() const
constexpr std::array< T, 4 > GetLTRB() const
constexpr bool IsEmpty() const
constexpr bool operator==(const TRect &r) const
constexpr bool IsZero() const
std::ostream & operator<<(std::ostream &out, const impeller::TRect< T > &r)
constexpr bool IntersectsWithRect(const TRect &o) const
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
constexpr auto GetBottom() const
static constexpr TRect MakeSize(const TSize< Type > &size)
A 4x4 matrix using column-major storage.
constexpr TRect Union(const TRect &o) const
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr auto GetLeft() const
constexpr std::optional< TRect< T > > Intersection(const TRect &o) const
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
constexpr TRect(Type x, Type y, Type width, Type height)
constexpr std::array< TPoint< T >, 4 > GetTransformedPoints(const Matrix &transform) const
constexpr TRect(TPoint< Type > origin, TSize< Type > size)
constexpr std::array< TPoint< T >, 4 > GetPoints() const