39#ifndef DOXYGEN_SHOULD_SKIP_THIS
103 return Rect<T>(position, position + size);
126 return Rect<T>(center - size /
T(2), center + size /
T(2));
164 return min.x >= max.x || min.y >= max.y;
173 return min + (max - min) / 2;
183 return min.x <= point.x && point.x < max.x && min.y <= point.y && point.y < max.y;
193 return min.x <= other.min.x && other.max.x <= max.x && min.y <= other.min.y && other.max.y <= max.y;
203 return min.x < other.max.x && other.min.x < max.x && min.y < other.max.y && other.min.y < max.y;
214 if (!intersects(other)) {
218 result = getIntersection(other);
231 res.
min.
x = std::max(min.x, other.min.x);
232 res.
min.
y = std::max(min.y, other.min.y);
233 res.
max.
x = std::min(max.x, other.max.x);
234 res.
max.
y = std::min(max.y, other.max.y);
246 auto xMin = std::max(min.x, other.min.x);
247 auto xMax = std::min(max.x, other.max.x);
253 auto yMin = std::max(min.y, other.min.y);
254 auto yMax = std::min(max.y, other.max.y);
260 return (xMax - xMin) * (yMax - yMin);
270 auto xMin = std::max(min.x, other.min.x);
271 auto xMax = std::min(max.x, other.max.x);
277 auto yMin = std::max(min.y, other.min.y);
278 auto yMax = std::min(max.y, other.max.y);
284 return (xMax - xMin) + (yMax - yMin);
292 constexpr void extend(
const T (&point)[2])
noexcept {
293 min.x = std::min(min.x, point[0]);
294 min.y = std::min(min.y, point[1]);
295 max.x = std::max(max.x, point[0]);
296 max.y = std::max(max.y, point[1]);
305 min.x = std::min(min.x, point.x);
306 min.y = std::min(min.y, point.y);
307 max.x = std::max(max.x, point.x);
308 max.y = std::max(max.y, point.y);
317 min.x = std::min(min.x, other.min.x);
318 min.y = std::min(min.y, other.min.y);
319 max.x = std::max(max.x, other.max.x);
320 max.y = std::max(max.y, other.max.y);
340 return (max.x - min.x) * (max.y - min.y);
349 return (max.x - min.x) + (max.y - min.y);
358 return std::min(max.x - min.x, max.y - min.y);
369 return Rect(min - value, max + value);
380 return Rect(min + value, max - value);
387 if (min.x > max.x) { std::swap(min.x, max.x); }
388 if (min.y > max.y) { std::swap(min.y, max.y); }
402 return { (this->min.x + this->max.x) /
T(2), this->min.y };
404 return { this->max.x, this->min.y };
406 return { this->min.x, (this->min.y + this->max.y) /
T(2) };
408 return this->getCenter();
410 return { this->max.x, (this->min.y + this->max.y) /
T(2) };
412 return { this->min.x, this->max.y };
414 return { (this->min.x + this->max.x) /
T(2), this->max.y };
464 return this->max.x - this->min.x;
473 return this->max.y - this->min.y;
531 extern template struct GF_CORE_API
Rect<int>;
560 return !(lhs == rhs);
597 template<
typename Archive,
typename T>
603#ifndef DOXYGEN_SHOULD_SKIP_THIS
constexpr Rect< T > computeBoxQuarter(const Rect< T > &other, Quarter quarter)
Divide a rectangle in quarters.
Definition: Rect.h:572
constexpr ZeroType Zero
Constant to represent "zero".
Definition: Types.h:93
Quarter
A quarter in a square.
Definition: Quarter.h:33
@ UpperRight
Upper-right quarter.
Definition: Quarter.h:35
@ LowerLeft
Lower-left quarter.
Definition: Quarter.h:37
@ UpperLeft
Upper-left quarter.
Definition: Quarter.h:34
@ LowerRight
Lower-right quarter.
Definition: Quarter.h:36
Anchor
An anchor of a box.
Definition: Anchor.h:38
@ BottomRight
Bottom-right.
@ CenterRight
Center-right.
@ BottomCenter
Bottom-center.
The namespace for gf classes.
Utility class for manipulating 2D axis aligned rectangles.
Definition: Rect.h:72
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner.
Definition: Rect.h:427
constexpr Rect shrink(T value) const noexcept
Shrink the rectangle.
Definition: Rect.h:379
constexpr void extend(Vector< T, 2 > point) noexcept
Extend the rectangle with a point.
Definition: Rect.h:304
constexpr Vector< T, 2 > getCenter() const noexcept
Get the center of the rectangle.
Definition: Rect.h:172
constexpr Vector< T, 2 > getTopRight() const noexcept
Get the top right corner.
Definition: Rect.h:436
constexpr T getIntersectionVolume(const Rect &other) const noexcept
Get the volume of the intersection.
Definition: Rect.h:245
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator.
Definition: Rect.h:545
static constexpr Rect< T > fromSize(Vector< T, 2 > size) noexcept
Create a rectangle from a size.
Definition: Rect.h:114
constexpr bool intersects(const Rect &other, Rect &result) const noexcept
Check if two rectangles interset and get the intersetion rectangle.
Definition: Rect.h:213
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:102
Archive & operator|(Archive &ar, Rect< T > &rect)
Serialize a rectangle.
Definition: Rect.h:598
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator.
Definition: Rect.h:559
constexpr bool contains(Vector< T, 2 > point) const noexcept
Check if a point is inside the rectangle.
Definition: Rect.h:182
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner.
Definition: Rect.h:454
constexpr Vector< T, 2 > getPositionFromAnchor(Anchor anchor) const noexcept
Get a position from the rectangle and an anchor.
Definition: Rect.h:397
Vector< T, 2 > max
The maximum point of the rectangle.
Definition: Rect.h:477
constexpr Rect() noexcept
Default constructor.
Definition: Rect.h:78
constexpr T getVolume() const noexcept
Get the volume of the rectangle.
Definition: Rect.h:339
constexpr Rect getIntersection(const Rect &other) const noexcept
Compute the intersection of two rectangles.
Definition: Rect.h:228
constexpr T getMinimumEdge() const noexcept
Get the minimum edge of the rectangle.
Definition: Rect.h:357
constexpr bool intersects(const Rect &other) const noexcept
Check if two rectangles interset.
Definition: Rect.h:202
constexpr T getIntersectionExtentLength(const Rect &other) const noexcept
Get the extent length of the intersection.
Definition: Rect.h:269
constexpr void extend(const T(&point)[2]) noexcept
Extend the rectangle with a point (as array)
Definition: Rect.h:292
constexpr void normalize() noexcept
Ensures that min coordinates are less than max coordinates.
Definition: Rect.h:386
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:91
constexpr T getExtentLength() const noexcept
Get the extent length of the rectangle.
Definition: Rect.h:348
constexpr T getHeight() const noexcept
Get the height of the rectangle.
Definition: Rect.h:472
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:125
constexpr bool contains(const Rect &other) const noexcept
Check if a rectangle is totally inside the rectangle.
Definition: Rect.h:192
constexpr Rect grow(T value) const noexcept
Grow the rectangle.
Definition: Rect.h:368
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner.
Definition: Rect.h:445
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty.
Definition: Rect.h:163
constexpr Rect getExtended(const Rect &other) const noexcept
Get the rectangle extended by another rectangle.
Definition: Rect.h:328
Vector< T, 2 > min
The minimum point of the rectangle.
Definition: Rect.h:476
constexpr T getWidth() const noexcept
Get the width of the rectangle.
Definition: Rect.h:463
static constexpr Rect< T > empty() noexcept
Create an empty rectangle.
Definition: Rect.h:134
constexpr Vector< T, 2 > getPosition() const noexcept
Get the position of the rectangle.
Definition: Rect.h:145
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle.
Definition: Rect.h:154
constexpr void extend(const Rect &other) noexcept
Extend the rectangle with a rectangle.
Definition: Rect.h:316
A 2D vector.
Definition: Vector.h:316
T height
Second coordinate in the size representation.
Definition: Vector.h:528
T width
First coordinate in the size representation.
Definition: Vector.h:517
T y
Second coordinate in the (x,y) representation.
Definition: Vector.h:525
T x
First coordinate in the (x,y) representation.
Definition: Vector.h:514