36 #include "VectorOps.h" 39 #ifndef DOXYGEN_SHOULD_SKIP_THIS 118 return Rect<T>(position, position + size);
141 return Rect<T>(center - size /
T(2), center + size /
T(2));
179 return min.x >= max.x || min.y >= max.y;
188 return min + (max - min) / 2;
198 return min.x <= point.x && point.x < max.x && min.y <= point.y && point.y < max.y;
208 return min.x <= other.min.x && other.max.x <= max.x && min.y <= other.min.y && other.max.y <= max.y;
218 return min.x < other.max.x && other.min.x < max.x && min.y < other.max.y && other.min.y < max.y;
229 if (!intersects(other)) {
233 result = getIntersection(other);
246 res.
min.
x = std::max(min.x, other.min.x);
247 res.
min.
y = std::max(min.y, other.min.y);
248 res.
max.
x = std::min(max.x, other.max.x);
249 res.
max.
y = std::min(max.y, other.max.y);
261 auto xMin = std::max(min.x, other.min.x);
262 auto xMax = std::min(max.x, other.max.x);
268 auto yMin = std::max(min.y, other.min.y);
269 auto yMax = std::min(max.y, other.max.y);
275 return (xMax - xMin) * (yMax - yMin);
285 auto xMin = std::max(min.x, other.min.x);
286 auto xMax = std::min(max.x, other.max.x);
292 auto yMin = std::max(min.y, other.min.y);
293 auto yMax = std::min(max.y, other.max.y);
299 return (xMax - xMin) + (yMax - yMin);
307 constexpr
void extend(
const T (&point)[2]) noexcept {
308 min.x = std::min(min.x, point[0]);
309 min.y = std::min(min.y, point[1]);
310 max.x = std::max(max.x, point[0]);
311 max.y = std::max(max.y, point[1]);
320 min.x = std::min(min.x, point.x);
321 min.y = std::min(min.y, point.y);
322 max.x = std::max(max.x, point.x);
323 max.y = std::max(max.y, point.y);
332 min.x = std::min(min.x, other.min.x);
333 min.y = std::min(min.y, other.min.y);
334 max.x = std::max(max.x, other.max.x);
335 max.y = std::max(max.y, other.max.y);
355 return (max.x - min.x) * (max.y - min.y);
364 return (max.x - min.x) + (max.y - min.y);
373 return std::min(max.x - min.x, max.y - min.y);
384 return Rect(min - value, max + value);
395 return Rect(min + value, max - value);
402 if (min.x > max.x) { std::swap(min.x, max.x); }
403 if (min.y > max.y) { std::swap(min.y, max.y); }
417 return { (this->min.x + this->max.x) /
T(2), this->min.y };
419 return { this->max.x, this->min.y };
421 return { this->min.x, (this->min.y + this->max.y) /
T(2) };
423 return this->getCenter();
425 return { this->max.x, (this->min.y + this->max.y) /
T(2) };
427 return { this->min.x, this->max.y };
429 return { (this->min.x + this->max.x) /
T(2), this->max.y };
479 return this->max.x - this->min.x;
488 return this->max.y - this->min.y;
546 extern template struct GF_CORE_API
Rect<int>;
575 return !(lhs == rhs);
612 template<
typename Archive,
typename T>
614 return ar | rect.
min.x | rect.
min.y | rect.
max.x | rect.
max.y;
618 #ifndef DOXYGEN_SHOULD_SKIP_THIS T x
First coordinate in the (x,y) representation.
Definition: Vector.h:514
constexpr bool contains(Vector< T, 2 > point) const noexcept
Check if a point is inside the rectangle.
Definition: Rect.h:197
constexpr T getIntersectionExtentLength(const Rect &other) const noexcept
Get the extent length of the intersection.
Definition: Rect.h:284
constexpr Rect< T > computeBoxQuarter(const Rect< T > &other, Quarter quarter)
Divide a rectangle in quarters.
Definition: Rect.h:587
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner.
Definition: Rect.h:460
Vector< T, 2 > max
The maximum point of the rectangle.
Definition: Rect.h:492
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator.
Definition: Rect.h:574
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty.
Definition: Rect.h:178
static constexpr Rect< T > fromSize(Vector< T, 2 > size) noexcept
Create a rectangle from a size.
Definition: Rect.h:129
constexpr T getExtentLength() const noexcept
Get the extent length of the rectangle.
Definition: Rect.h:363
constexpr Vector< T, 2 > getPositionFromAnchor(Anchor anchor) const noexcept
Get a position from the rectangle and an anchor.
Definition: Rect.h:412
Vector< T, 2 > min
The minimum point of the rectangle.
Definition: Rect.h:491
constexpr bool intersects(const Rect &other) const noexcept
Check if two rectangles interset.
Definition: Rect.h:217
constexpr Rect shrink(T value) const noexcept
Shrink the rectangle.
Definition: Rect.h:394
constexpr Rect getExtended(const Rect &other) const noexcept
Get the rectangle extended by another rectangle.
Definition: Rect.h:343
Upper-right quarter.
Definition: Quarter.h:35
Archive & operator|(Archive &ar, Rect< T > &rect)
Serialize a rectangle.
Definition: Rect.h:613
Lower-right quarter.
Definition: Quarter.h:36
static constexpr Rect< T > fromMinMax(Vector< T, 2 > min, Vector< T, 2 > max) noexcept
Create a rectangle from a min point and a max point.
Definition: Rect.h:106
T y
Second coordinate in the (x,y) representation.
Definition: Vector.h:525
constexpr Vector< T, 2 > getPosition() const noexcept
Get the position of the rectangle.
Definition: Rect.h:160
T width
First coordinate in the size representation.
Definition: Vector.h:517
constexpr void extend(const T(&point)[2]) noexcept
Extend the rectangle with a point (as array)
Definition: Rect.h:307
T height
Second coordinate in the size representation.
Definition: Vector.h:528
constexpr Vector< T, 2 > getTopRight() const noexcept
Get the top right corner.
Definition: Rect.h:451
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:87
The namespace for gf classes.
Definition: Action.h:35
constexpr Vector< T, 2 > getCenter() const noexcept
Get the center of the rectangle.
Definition: Rect.h:187
static constexpr Rect< T > fromPositionSize(Vector< T, 2 > position, Vector< T, 2 > size) noexcept
Create a rectangle from a position (top-left) and a size.
Definition: Rect.h:117
Quarter
A quarter in a square.
Definition: Quarter.h:33
static constexpr Rect< T > empty() noexcept
Create an empty rectangle.
Definition: Rect.h:149
constexpr void extend(Vector< T, 2 > point) noexcept
Extend the rectangle with a point.
Definition: Rect.h:319
constexpr T getMinimumEdge() const noexcept
Get the minimum edge of the rectangle.
Definition: Rect.h:372
constexpr void extend(const Rect &other) noexcept
Extend the rectangle with a rectangle.
Definition: Rect.h:331
constexpr bool intersects(const Rect &other, Rect &result) const noexcept
Check if two rectangles interset and get the intersetion rectangle.
Definition: Rect.h:228
Upper-left quarter.
Definition: Quarter.h:34
constexpr void normalize() noexcept
Ensures that min coordinates are less than max coordinates.
Definition: Rect.h:401
A 2D vector.
Definition: Vector.h:316
constexpr T getWidth() const noexcept
Get the width of the rectangle.
Definition: Rect.h:478
constexpr T getVolume() const noexcept
Get the volume of the rectangle.
Definition: Rect.h:354
constexpr Rect() noexcept
Default constructor.
Definition: Rect.h:93
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner.
Definition: Rect.h:442
static constexpr Rect< T > fromCenterSize(Vector< T, 2 > center, Vector< T, 2 > size) noexcept
Create a rectangle from a center and a size.
Definition: Rect.h:140
constexpr Rect getIntersection(const Rect &other) const noexcept
Compute the intersection of two rectangles.
Definition: Rect.h:243
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner.
Definition: Rect.h:469
Anchor
An anchor of a box.
Definition: Anchor.h:38
constexpr Rect grow(T value) const noexcept
Grow the rectangle.
Definition: Rect.h:383
constexpr T getIntersectionVolume(const Rect &other) const noexcept
Get the volume of the intersection.
Definition: Rect.h:260
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle.
Definition: Rect.h:169
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator.
Definition: Rect.h:560
constexpr T getHeight() const noexcept
Get the height of the rectangle.
Definition: Rect.h:487
constexpr bool contains(const Rect &other) const noexcept
Check if a rectangle is totally inside the rectangle.
Definition: Rect.h:207
Lower-left quarter.
Definition: Quarter.h:37