32 #include "Portability.h" 34 #include "VectorOps.h" 37 #ifndef DOXYGEN_SHOULD_SKIP_THIS 47 template<
typename T, std::
size_t N>
52 constexpr
Box() noexcept
54 for (std::size_t i = 0; i <
N; ++i) {
55 min[i] = std::numeric_limits<T>::max();
56 max[i] = std::numeric_limits<T>::lowest();
62 for (std::size_t i = 0; i <
N; ++i) {
63 std::tie(min[i], max[i]) = std::minmax(p0[i], p1[i]);
67 constexpr
Box(
const T (&p0)[
N],
const T (&p1)[N]) noexcept {
68 for (std::size_t i = 0; i <
N; ++i) {
69 std::tie(min[i], max[i]) = std::minmax(p0[i], p1[i]);
85 for (std::size_t i = 0; i <
N; ++i) {
86 if (min[i] >= max[i]) {
95 return (min + max) / 2;
99 for (std::size_t i = 0; i <
N; ++i) {
100 if (!(min[i] <= point[i] && point[i] <= max[i])) {
109 for (std::size_t i = 0; i <
N; ++i) {
110 if (!(min[i] <= other.
min[i] && other.max[i] <= max[i])) {
119 for (std::size_t i = 0; i <
N; ++i) {
120 if (!(min[i] < other.
max[i] && other.min[i] < max[i])) {
131 for (std::size_t i = 0; i <
N; ++i) {
132 res.
min[i] = std::max(min[i], other.
min[i]);
133 res.
max[i] = std::min(max[i], other.
max[i]);
142 for (std::size_t i = 0; i <
N; ++i) {
143 auto axisMin = std::max(min[i], other.
min[i]);
144 auto axisMax = std::min(max[i], other.
max[i]);
146 if (axisMin >= axisMax) {
150 res *= (axisMax - axisMin);
159 for (std::size_t i = 0; i <
N; ++i) {
160 auto axisMin = std::max(min[i], other.
min[i]);
161 auto axisMax = std::min(max[i], other.
max[i]);
163 if (axisMin >= axisMax) {
167 res += (axisMax - axisMin);
173 constexpr
void extend(
const T (&point)[N]) noexcept {
174 for (std::size_t i = 0; i <
N; ++i) {
177 std::tie(min[i], max[i]) = std::minmax({ axisMin, axisMax, point[i] });
182 for (std::size_t i = 0; i <
N; ++i) {
185 std::tie(min[i], max[i]) = std::minmax({ axisMin, axisMax, point[i] });
190 for (std::size_t i = 0; i <
N; ++i) {
191 min[i] = std::min(min[i], other.
min[i]);
192 max[i] = std::max(max[i], other.
max[i]);
205 for (std::size_t i = 0; i <
N; ++i) {
206 volume *= (max[i] - min[i]);
215 for (std::size_t i = 0; i <
N; ++i) {
216 distance += (max[i] - min[i]);
223 T minimum = max[0] - min[0];
225 for (std::size_t i = 1; i <
N; ++i) {
226 minimum = std::min(minimum, max[i] - min[i]);
236 for (std::size_t i = 0; i <
N; ++i) {
237 if (min[i] > max[i]) {
238 std::swap(min[i], max[i]);
267 case Quadrant::UpperLeft:
269 case Quadrant::UpperRight:
271 case Quadrant::LowerRight:
273 case Quadrant::LowerLeft:
280 template<
typename T, std::
size_t N>
308 #ifndef DOXYGEN_SHOULD_SKIP_THIS constexpr Box< T, N > getExtended(const Box< T, N > &other) const noexcept
Definition: Box.h:196
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
Definition: Box.h:118
constexpr Box(const T(&p0)[N], const T(&p1)[N]) noexcept
Definition: Box.h:67
constexpr T getMinimumEdge() const noexcept
Definition: Box.h:222
constexpr bool contains(const Box< T, N > &other) const noexcept
Definition: Box.h:108
constexpr bool operator==(const Box< T, N > &lhs, const Box< T, N > &rhs)
Definition: Box.h:282
constexpr void extend(Vector< T, N > point) noexcept
Definition: Box.h:181
constexpr Box(Vector< T, N > p0, Vector< T, N > p1) noexcept
Definition: Box.h:60
Vector< T, N > min
Definition: Box.h:49
constexpr Vector< T, N > getCenter() const noexcept
Definition: Box.h:94
constexpr bool isEmpty() const noexcept
Definition: Box.h:84
T getIntersectionVolume(const Box< T, N > &other) const noexcept
Definition: Box.h:139
T width
First coordinate in the size representation.
Definition: Vector.h:512
constexpr T getExtentDistance() const noexcept
Definition: Box.h:212
constexpr void normalize() noexcept
Ensures that min coordinates are less than max coordinates.
Definition: Box.h:235
constexpr Box() noexcept
Definition: Box.h:52
T height
Second coordinate in the size representation.
Definition: Vector.h:523
constexpr Vector< T, N > getSize() const noexcept
Definition: Box.h:80
constexpr T getVolume() const noexcept
Definition: Box.h:202
The namespace for gf classes.
Definition: Action.h:35
constexpr void extend(const T(&point)[N]) noexcept
Definition: Box.h:173
T getIntersectionExtentDistance(const Box< T, N > &other) const noexcept
Definition: Box.h:156
constexpr Vector< T, N > min(Vector< T, N > lhs, Vector< T, N > rhs)
Component-wise minimum.
Definition: VectorOps.h:448
constexpr void extend(const Box< T, N > &other) noexcept
Definition: Box.h:189
Vector< T, N > max
Definition: Box.h:50
A 2D vector.
Definition: Vector.h:316
Box< T, 2 > computeBoxQuadrant(const Box< T, 2 > &box, Quadrant quadrant)
Definition: Box.h:263
Quadrant
Definition: Box.h:254
constexpr bool contains(Vector< T, N > point) const noexcept
Definition: Box.h:98
A multi-dimensional box.
Definition: Box.h:48
General purpose math vector.
Definition: Vector.h:61
Box< T, N > getIntersection(const Box< T, N > &other) const noexcept
Definition: Box.h:128
constexpr Box(Vector< T, N > p) noexcept
Definition: Box.h:73