23#ifndef VCL_SPACE_CORE_BOX_H
24#define VCL_SPACE_CORE_BOX_H
44template<Po
intConcept Po
intT>
59 static const uint
DIM = PointT::DIM;
73 Box(
const PointT& p) : mMin(p), mMax(p) {}
90 PointT&
min() {
return mMin; }
97 const PointT&
min()
const {
return mMin; }
104 PointT&
max() {
return mMax; }
111 const PointT&
max()
const {
return mMax; }
113 template<
typename Scalar>
116 if constexpr (std::is_same_v<typename PointT::ScalarType, Scalar>) {
135 for (uint
i = 0;
i < PointT::DIM; ++
i) {
136 if (mMin[
i] > mMax[
i])
165 for (uint
i = 0;
i < PointT::DIM; ++
i) {
166 if (
p[
i] < mMin[
i] ||
p[
i] > mMax[
i])
185 for (uint
i = 0;
i < PointT::DIM; ++
i) {
186 if (
p[
i] <= mMin[
i] ||
p[
i] >= mMax[
i])
201 for (uint
i = 0;
i < PointT::DIM; ++
i) {
202 if (
p[
i] < mMin[
i] ||
p[
i] >= mMax[
i])
217 for (uint
i = 0;
i < PointT::DIM; ++
i) {
218 if (
b.mMin[
i] >= mMax[
i] ||
b.mMax[
i] <= mMin[
i])
259 PointT
center()
const {
return (mMax + mMin) / 2; }
267 PointT
size()
const {
return mMax - mMin; }
277 auto vol = mMax[0] - mMin[0];
279 for (uint
i = 1;
i < PointT::DIM; ++
i) {
280 vol *= mMax[
i] - mMin[
i];
295 return mMax[
i] - mMin[
i];
307 auto m = mMax[0] - mMin[0];
308 for (uint
i = 1;
i < PointT::DIM; ++
i) {
309 if (mMax[
i] - mMin[
i] <
m)
310 m = mMax[
i] - mMin[
i];
324 auto m = mMax[0] - mMin[0];
325 for (uint
i = 1;
i < PointT::DIM; ++
i) {
326 if (mMax[
i] - mMin[
i] >
m)
327 m = mMax[
i] - mMin[
i];
342 for (uint
i = 0;
i < PointT::DIM; ++
i) {
343 if (mMin[
i] <
b.mMin[
i]) {
347 if (mMax[
i] >
b.mMax[
i]) {
371 std::numeric_limits<typename PointT::ScalarType>::max());
373 std::numeric_limits<typename PointT::ScalarType>::lowest());
411 template<
typename Scalar>
412 void add(
const PointT&
p, Scalar radius)
418 *
this =
Box(
p - radius,
p + radius);
490 return mMin ==
b.mMin && mMax ==
b.mMax;
505using Box2 = Box<Point2<S>>;
507using Box2i = Box<Point2i>;
508using Box2f = Box<Point2f>;
509using Box2d = Box<Point2d>;
512using Box3 = Box<Point3<S>>;
514using Box3i = Box<Point3i>;
515using Box3f = Box<Point3f>;
516using Box3d = Box<Point3d>;
532 std::remove_cvref_t<T>,
533 Box<typename RemoveRef<T>::PointType>>;
A class representing a box in N-dimensional space.
Definition box.h:46
auto diagonal() const
Calculates the diagonal length of the box.
Definition box.h:246
const PointT & max() const
Returns a const reference to the maximum point of the box.
Definition box.h:111
PointT PointType
The type of point used to represent the corners of the box.
Definition box.h:54
Box(const PointT &p)
Initializes the box with the given point. The box is a valid empty box (meaning that the minimum and ...
Definition box.h:73
const PointT & min() const
Returns a const reference to the minimum point of the box.
Definition box.h:97
auto squaredDiagonal() const
Calculates the squared length of the diagonal of the box.
Definition box.h:252
bool intersects(const Box< PointT > &b) const
Same as Box::overlap.
Definition box.h:239
Box(const PointT &min, const PointT &max)
Initializes the box with the given minimum and maximum points.
Definition box.h:83
bool isInsideStrict(const PointT &p) const
Checks whether a given point is inside the box or not, bounds excluded.
Definition box.h:183
void deserialize(std::istream &is)
Deserializes the box from the given input stream.
Definition box.h:476
void translate(const PointT &p)
Translates the box by summing the values of p.
Definition box.h:456
PointT & max()
Returns a reference to the maximum point of the box.
Definition box.h:104
bool isInsideOpenBox(const PointT &p) const
Checks if a point is inside the open box (max bound excluded); e.g. p in [min, max).
Definition box.h:199
PointT & min()
Returns a reference to the minimum point of the box.
Definition box.h:90
void add(const PointT &p, Scalar radius)
Adds the given point to the current box, expanding this box by a radius around the point,...
Definition box.h:412
void add(const Box< PointT > &b)
Adds the given box to the current box, expanding this box in order that will contain also the b value...
Definition box.h:436
bool overlap(const Box< PointT > &b) const
Check if two boxes overlap.
Definition box.h:214
void add(const PointT &p)
Adds the given point to the current box, expanding this box in order to contain also the values of th...
Definition box.h:385
bool operator!=(const Box< PointT > &b) const
Compares the current box to another box for inequality.
Definition box.h:499
Box()
The Empty constructor of a box, initializes a null box.
Definition box.h:65
static const uint DIM
The dimensionality of the box.
Definition box.h:59
auto minDim() const
Calculates the minimum dimension of the box, which is defined as the smallest difference between the ...
Definition box.h:305
bool isInside(const PointT &p) const
Checks whether a given point is inside the box or not, bounds included.
Definition box.h:163
bool collide(const Box< PointT > &b) const
Same as Box::overlap.
Definition box.h:231
PointT center() const
Calculates the center point of the box.
Definition box.h:259
Box< PointT > intersection(const Box< PointT > &b) const
Computes and returns the intersection between the current box and the given box b.
Definition box.h:339
auto maxDim() const
Computes the maximum dimension of the box, which is defined as the greater difference between the max...
Definition box.h:322
bool isEmpty() const
Checks whether the box is empty or not.
Definition box.h:150
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
auto dim(uint i) const
Get the length of the box along a given dimension.
Definition box.h:292
auto volume() const
Computes the volume of the box.
Definition box.h:274
PointT size() const
Computes the size of the box.
Definition box.h:267
bool operator==(const Box< PointT > &b) const
Compares the current box to another box for equality.
Definition box.h:488
bool isNull() const
Checks whether the box is null or not.
Definition box.h:133
void setNull()
Sets the Box to null. A box is considered null if at least one min component is greater than the corr...
Definition box.h:368
A concept representing a 2D Box.
Definition box.h:546
A concept representing a 3D Box.
Definition box.h:559
A concept representing a Box.
Definition box.h:531
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:81
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:40