32 #include "Portability.h" 35 #include "VectorOps.h" 38 #ifndef DOXYGEN_SHOULD_SKIP_THIS 51 template<
typename T, std::
size_t N>
59 constexpr
Box() noexcept
61 for (std::size_t i = 0; i <
N; ++i) {
62 min[i] = std::numeric_limits<T>::max();
63 max[i] = std::numeric_limits<T>::lowest();
77 for (std::size_t i = 0; i <
N; ++i) {
94 constexpr
Box(
const T (&p0)[
N],
const T (&p1)[N]) noexcept
98 for (std::size_t i = 0; i <
N; ++i) {
147 for (std::size_t i = 0; i <
N; ++i) {
148 if (min[i] >= max[i]) {
162 return min + (max - min) / 2;
172 for (std::size_t i = 0; i <
N; ++i) {
173 if (!(min[i] <= point[i] && point[i] < max[i])) {
188 for (std::size_t i = 0; i <
N; ++i) {
189 if (!(min[i] <= other.
min[i] && other.max[i] <= max[i])) {
204 for (std::size_t i = 0; i <
N; ++i) {
205 if (!(min[i] < other.
max[i] && other.min[i] < max[i])) {
221 if (!intersects(other)) {
225 result = getIntersection(other);
238 for (std::size_t i = 0; i <
N; ++i) {
239 res.
min[i] = std::max(min[i], other.
min[i]);
240 res.
max[i] = std::min(max[i], other.
max[i]);
255 for (std::size_t i = 0; i <
N; ++i) {
256 auto axisMin = std::max(min[i], other.
min[i]);
257 auto axisMax = std::min(max[i], other.
max[i]);
259 if (axisMin >= axisMax) {
263 res *= (axisMax - axisMin);
278 for (std::size_t i = 0; i <
N; ++i) {
279 auto axisMin = std::max(min[i], other.
min[i]);
280 auto axisMax = std::min(max[i], other.
max[i]);
282 if (axisMin >= axisMax) {
286 res += (axisMax - axisMin);
297 constexpr
void extend(
const T (&point)[N]) noexcept {
298 for (std::size_t i = 0; i <
N; ++i) {
301 std::tie(min[i], max[i]) = std::minmax({ axisMin, axisMax, point[i] });
311 for (std::size_t i = 0; i <
N; ++i) {
314 std::tie(min[i], max[i]) = std::minmax({ axisMin, axisMax, point[i] });
324 for (std::size_t i = 0; i <
N; ++i) {
325 min[i] = std::min(min[i], other.
min[i]);
326 max[i] = std::max(max[i], other.
max[i]);
349 for (std::size_t i = 0; i <
N; ++i) {
350 volume *= (max[i] - min[i]);
364 for (std::size_t i = 0; i <
N; ++i) {
365 distance += (max[i] - min[i]);
377 T minimum = max[0] - min[0];
379 for (std::size_t i = 1; i <
N; ++i) {
380 minimum = std::min(minimum, max[i] - min[i]);
394 return Box<T, 2>(min - value, max + value);
405 return Box<T, 2>(min + value, max - value);
412 for (std::size_t i = 0; i <
N; ++i) {
413 if (min[i] > max[i]) {
414 std::swap(min[i], max[i]);
487 template<
typename T, std::
size_t N>
494 #ifndef DOXYGEN_SHOULD_SKIP_THIS constexpr Box< T, N > getExtended(const Box< T, N > &other) const noexcept
Get the box extended by another box.
Definition: Box.h:335
constexpr Vector< T, N > max(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise maximum.
Definition: VectorOps.h:464
constexpr bool intersects(const Box< T, N > &other) const noexcept
Check if two boxes interset.
Definition: Box.h:203
Upper-right quarter.
Definition: Quarter.h:35
constexpr Box(const T(&p0)[N], const T(&p1)[N]) noexcept
Constructor with two points (as arrays)
Definition: Box.h:94
constexpr bool intersects(const Box< T, N > &other, Box< T, N > &result) const noexcept
Check if two boxes interset and get the intersetion box.
Definition: Box.h:220
constexpr T getMinimumEdge() const noexcept
Get the minimum edge of the box.
Definition: Box.h:376
constexpr bool contains(const Box< T, N > &other) const noexcept
Check if a box is totally inside the box.
Definition: Box.h:187
constexpr Box< T, N > getIntersection(const Box< T, N > &other) const noexcept
Compute the intersection of two boxes.
Definition: Box.h:235
constexpr void extend(Vector< T, N > point) noexcept
Extend the box with a point.
Definition: Box.h:310
constexpr Box(Vector< T, N > p0, Vector< T, N > p1) noexcept
Constructor with two points.
Definition: Box.h:73
Vector< T, N > min
The minimum point of the box.
Definition: Box.h:53
constexpr Box< T, 2 > computeBoxQuarter(const Box< T, 2 > &box, Quarter quarter)
Divide a box in quarters.
Definition: Box.h:466
constexpr Vector< T, N > getCenter() const noexcept
Get the center of the box.
Definition: Box.h:161
Lower-right quarter.
Definition: Quarter.h:36
constexpr bool isEmpty() const noexcept
Check if the box is empty.
Definition: Box.h:146
Upper-left quarter.
Definition: Quarter.h:34
T width
First coordinate in the size representation.
Definition: Vector.h:510
constexpr void normalize() noexcept
Ensures that min coordinates are less than max coordinates.
Definition: Box.h:411
constexpr Box< T, 2 > grow(T value) const noexcept
Grow the box.
Definition: Box.h:393
constexpr Box() noexcept
Default constructor.
Definition: Box.h:59
T height
Second coordinate in the size representation.
Definition: Vector.h:521
constexpr Vector< T, N > getSize() const noexcept
Get the size of the box.
Definition: Box.h:137
constexpr T getVolume() const noexcept
Get the volume of the box.
Definition: Box.h:346
The namespace for gf classes.
Definition: Action.h:35
constexpr void extend(const T(&point)[N]) noexcept
Extend the box with a point (as array)
Definition: Box.h:297
constexpr Vector< T, N > min(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise minimum.
Definition: VectorOps.h:448
Lower-left quarter.
Definition: Quarter.h:37
constexpr bool operator==(const Box< T, N > &lhs, const Box< T, N > &rhs)
Equality operator.
Definition: Box.h:489
constexpr void extend(const Box< T, N > &other) noexcept
Extend the box with a box.
Definition: Box.h:323
Vector< T, N > max
The maximum point of the box.
Definition: Box.h:54
Quarter
A quarter in a square.
Definition: Quarter.h:33
A 2D vector.
Definition: Vector.h:316
constexpr Vector< T, N > getPosition() const noexcept
Get the position of the box.
Definition: Box.h:128
constexpr T getExtentLength() const noexcept
Get the extent length of the box.
Definition: Box.h:361
constexpr T getIntersectionVolume(const Box< T, N > &other) const noexcept
Get the volume of the intersection.
Definition: Box.h:252
constexpr bool contains(Vector< T, N > point) const noexcept
Check if a point is inside the box.
Definition: Box.h:171
A multi-dimensional box.
Definition: Box.h:52
General purpose math vector.
Definition: Vector.h:61
constexpr T getIntersectionExtentLength(const Box< T, N > &other) const noexcept
Get the extent length of the intersection.
Definition: Box.h:275
constexpr Box< T, 2 > shrink(T value) const noexcept
Shrink the box.
Definition: Box.h:404
constexpr Box(Vector< T, N > p) noexcept
Constructor with one point.
Definition: Box.h:114