36 #include "VectorOps.h"    39 #ifndef DOXYGEN_SHOULD_SKIP_THIS   118       return Rect<T>(position, position + size);
   129       return Rect<T>(center - size / 
T(2), center + size / 
T(2));
   167       return min.x >= max.x || min.y >= max.y;
   176       return min + (max - min) / 2;
   186       return min.x <= point.x && point.x < max.x && min.y <= point.y && point.y < max.y;
   196       return min.x <= other.min.x && other.max.x <= max.x && min.y <= other.min.y && other.max.y <= max.y;
   206       return min.x < other.max.x && other.min.x < max.x && min.y < other.max.y && other.min.y < max.y;
   217       if (!intersects(other)) {
   221       result = getIntersection(other);
   234       res.
min.
x = std::max(min.x, other.min.x);
   235       res.
min.
y = std::max(min.y, other.min.y);
   236       res.
max.
x = std::min(max.x, other.max.x);
   237       res.
max.
y = std::min(max.y, other.max.y);
   249       auto xMin = std::max(min.x, other.min.x);
   250       auto xMax = std::min(max.x, other.max.x);
   256       auto yMin = std::max(min.y, other.min.y);
   257       auto yMax = std::min(max.y, other.max.y);
   263       return (xMax - xMin) * (yMax - yMin);
   273       auto xMin = std::max(min.x, other.min.x);
   274       auto xMax = std::min(max.x, other.max.x);
   280       auto yMin = std::max(min.y, other.min.y);
   281       auto yMax = std::min(max.y, other.max.y);
   287       return (xMax - xMin) + (yMax - yMin);
   295     constexpr 
void extend(
const T (&point)[2]) noexcept {
   296       min.x = std::min(min.x, point[0]);
   297       min.y = std::min(min.y, point[1]);
   298       max.x = std::max(max.x, point[0]);
   299       max.y = std::max(max.y, point[1]);
   308       min.x = std::min(min.x, point.x);
   309       min.y = std::min(min.y, point.y);
   310       max.x = std::max(max.x, point.x);
   311       max.y = std::max(max.y, point.y);
   320       min.x = std::min(min.x, other.min.x);
   321       min.y = std::min(min.y, other.min.y);
   322       max.x = std::max(max.x, other.max.x);
   323       max.y = std::max(max.y, other.max.y);
   343       return (max.x - min.x) * (max.y - min.y);
   352       return (max.x - min.x) + (max.y - min.y);
   361       return std::min(max.x - min.x, max.y - min.y);
   372       return Rect(min - value, max + value);
   383       return Rect(min + value, max - value);
   390       if (min.x > max.x) { std::swap(min.x, max.x); }
   391       if (min.y > max.y) { std::swap(min.y, max.y); }
   405           return { (this->min.x + this->max.x) / 
T(2), this->min.y };
   407           return { this->max.x, this->min.y };
   409           return { this->min.x, (this->min.y + this->max.y) / 
T(2) };
   411           return this->getCenter();
   413           return { this->max.x, (this->min.y + this->max.y) / 
T(2) };
   415           return { this->min.x, this->max.y };
   417           return { (this->min.x + this->max.x) / 
T(2), this->max.y };
   467       return this->max.x - this->min.x;
   476       return this->max.y - this->min.y;
   534   extern template struct GF_CORE_API 
Rect<int>;
   563     return !(lhs == rhs);
   600   template<
typename Archive, 
typename T>
   602     return ar | rect.
min.x | rect.
min.y | rect.
max.x | rect.
max.y;
   606 #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:185
constexpr T getIntersectionExtentLength(const Rect &other) const noexcept
Get the extent length of the intersection. 
Definition: Rect.h:272
constexpr Rect< T > computeBoxQuarter(const Rect< T > &other, Quarter quarter)
Divide a rectangle in quarters. 
Definition: Rect.h:575
constexpr Vector< T, 2 > getBottomLeft() const noexcept
Get the bottom left corner. 
Definition: Rect.h:448
Vector< T, 2 > max
The maximum point of the rectangle. 
Definition: Rect.h:480
bool operator!=(const Rect< T > &lhs, const Rect< T > &rhs)
Inequality operator. 
Definition: Rect.h:562
constexpr bool isEmpty() const noexcept
Check if the rectangle is empty. 
Definition: Rect.h:166
constexpr T getExtentLength() const noexcept
Get the extent length of the rectangle. 
Definition: Rect.h:351
constexpr Vector< T, 2 > getPositionFromAnchor(Anchor anchor) const noexcept
Get a position from the rectangle and an anchor. 
Definition: Rect.h:400
Vector< T, 2 > min
The minimum point of the rectangle. 
Definition: Rect.h:479
constexpr bool intersects(const Rect &other) const noexcept
Check if two rectangles interset. 
Definition: Rect.h:205
constexpr Rect shrink(T value) const noexcept
Shrink the rectangle. 
Definition: Rect.h:382
constexpr Rect getExtended(const Rect &other) const noexcept
Get the rectangle extended by another rectangle. 
Definition: Rect.h:331
Upper-right quarter. 
Definition: Quarter.h:35
Archive & operator|(Archive &ar, Rect< T > &rect)
Serialize a rectangle. 
Definition: Rect.h:601
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:148
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:295
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:439
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:175
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:137
constexpr void extend(Vector< T, 2 > point) noexcept
Extend the rectangle with a point. 
Definition: Rect.h:307
constexpr T getMinimumEdge() const noexcept
Get the minimum edge of the rectangle. 
Definition: Rect.h:360
constexpr void extend(const Rect &other) noexcept
Extend the rectangle with a rectangle. 
Definition: Rect.h:319
constexpr bool intersects(const Rect &other, Rect &result) const noexcept
Check if two rectangles interset and get the intersetion rectangle. 
Definition: Rect.h:216
Upper-left quarter. 
Definition: Quarter.h:34
constexpr void normalize() noexcept
Ensures that min coordinates are less than max coordinates. 
Definition: Rect.h:389
A 2D vector. 
Definition: Vector.h:316
constexpr T getWidth() const noexcept
Get the width of the rectangle. 
Definition: Rect.h:466
constexpr T getVolume() const noexcept
Get the volume of the rectangle. 
Definition: Rect.h:342
constexpr Rect() noexcept
Default constructor. 
Definition: Rect.h:93
constexpr Vector< T, 2 > getTopLeft() const noexcept
Get the top left corner. 
Definition: Rect.h:430
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:128
constexpr Rect getIntersection(const Rect &other) const noexcept
Compute the intersection of two rectangles. 
Definition: Rect.h:231
constexpr Vector< T, 2 > getBottomRight() const noexcept
Get the bottom right corner. 
Definition: Rect.h:457
Anchor
An anchor of a box. 
Definition: Anchor.h:38
constexpr Rect grow(T value) const noexcept
Grow the rectangle. 
Definition: Rect.h:371
constexpr T getIntersectionVolume(const Rect &other) const noexcept
Get the volume of the intersection. 
Definition: Rect.h:248
constexpr Vector< T, 2 > getSize() const noexcept
Get the size of the rectangle. 
Definition: Rect.h:157
bool operator==(const Rect< T > &lhs, const Rect< T > &rhs)
Equality operator. 
Definition: Rect.h:548
constexpr T getHeight() const noexcept
Get the height of the rectangle. 
Definition: Rect.h:475
constexpr bool contains(const Rect &other) const noexcept
Check if a rectangle is totally inside the rectangle. 
Definition: Rect.h:195
Lower-left quarter. 
Definition: Quarter.h:37