Visual Computing Library
|
A class representing a box in N-dimensional space. More...
#include <vclib/space/core/box.h>
Public Types | |
using | PointType = PointT |
The type of point used to represent the corners of the box. | |
Public Member Functions | |
Box () | |
The Empty constructor of a box, initializes a null box. | |
Box (const PointT &p) | |
Initializes the box with the given point. The box is a valid empty box (meaning that the minimum and the maximum points are equal). | |
Box (const PointT &min, const PointT &max) | |
Initializes the box with the given minimum and maximum points. | |
PointT & | min () |
Returns a reference to the minimum point of the box. | |
const PointT & | min () const |
Returns a const reference to the minimum point of the box. | |
PointT & | max () |
Returns a reference to the maximum point of the box. | |
const PointT & | max () const |
Returns a const reference to the maximum point of the box. | |
template<typename Scalar > | |
auto | cast () const |
bool | isNull () const |
Checks whether the box is null or not. | |
bool | isEmpty () const |
Checks whether the box is empty or not. | |
bool | isInside (const PointT &p) const |
Checks whether a given point is inside the box or not, bounds included. | |
bool | isInsideStrict (const PointT &p) const |
Checks whether a given point is inside the box or not, bounds excluded. | |
bool | isInsideOpenBox (const PointT &p) const |
Checks if a point is inside the open box (max bound excluded); e.g. p in [min, max). | |
bool | overlap (const Box< PointT > &b) const |
Check if two boxes overlap. | |
bool | collide (const Box< PointT > &b) const |
Same as Box::overlap. | |
bool | intersects (const Box< PointT > &b) const |
Same as Box::overlap. | |
auto | diagonal () const |
Calculates the diagonal length of the box. | |
auto | squaredDiagonal () const |
Calculates the squared length of the diagonal of the box. | |
PointT | center () const |
Calculates the center point of the box. | |
PointT | size () const |
Computes the size of the box. | |
auto | volume () const |
Computes the volume of the box. | |
auto | dim (uint i) const |
Get the length of the box along a given dimension. | |
auto | minDim () const |
Calculates the minimum dimension of the box, which is defined as the smallest difference between the maximum and minimum coordinates along any dimension. | |
auto | maxDim () const |
Computes the maximum dimension of the box, which is defined as the greater difference between the maximum and minimum coordinates along any dimension. | |
Box< PointT > | intersection (const Box< PointT > &b) const |
Computes and returns the intersection between the current box and the given box b. | |
void | setNull () |
Sets the Box to null. A box is considered null if at least one min component is greater than the corresponding max component. | |
void | add (const PointT &p) |
Adds the given point to the current box, expanding this box in order to contain also the values of the added point. | |
template<typename Scalar > | |
void | add (const PointT &p, Scalar radius) |
Adds the given point to the current box, expanding this box by a radius around the point, so that it will contain all points within the radius. | |
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 values. | |
void | translate (const PointT &p) |
Translates the box by summing the values of p. | |
void | serialize (std::ostream &os) const |
Serializes the box to the given output stream. | |
void | deserialize (std::istream &is) |
Deserializes the box from the given input stream. | |
bool | operator== (const Box< PointT > &b) const |
Compares the current box to another box for equality. | |
bool | operator!= (const Box< PointT > &b) const |
Compares the current box to another box for inequality. | |
Static Public Attributes | |
static const uint | DIM = PointT::DIM |
The dimensionality of the box. | |
Private Attributes | |
PointT | mMin |
PointT | mMax |
A class representing a box in N-dimensional space.
The Box
class represents an axis-aligned box in N-dimensional space, defined by its minimum and maximum corners. It provides functions for performing various operations on boxes, such as checking if a point is inside the box, computing the box's diagonal, and adding other boxes to the current box. The class is parameterized by a PointConcept
, which must provide the DIM
constant and the []
operator for accessing the point coordinates.
PointT | A type that satisfies the PointConcept requirements. |
|
inline |
The Empty constructor of a box, initializes a null box.
Initializes the box with the given point. The box is a valid empty box (meaning that the minimum and the maximum points are equal).
p | The point to initialize the box with. |
|
inline |
Initializes the box with the given minimum and maximum points.
If min > max for any dimension of the points, the box will be invalid.
[in] | min | The minimum point of the box. |
[in] | max | The maximum point of the box. |
Adds the given box to the current box, expanding this box in order that will contain also the b values.
If this box was null, the current box will have the same values of b.
[in] | b | The box to add to the current box. |
Adds the given point to the current box, expanding this box in order to contain also the values of the added point.
If this box was null, both the minimum and maximum points of the box will be set to the given point.
[in] | p | The point to add to the current box. |
|
inline |
Adds the given point to the current box, expanding this box by a radius around the point, so that it will contain all points within the radius.
If this box was null, it will be initialized with the minimum and maximum points obtained by subtracting and adding the radius to the given point.
Scalar | The data type of the radius. |
[in] | p | The point to add to the current box. |
[in] | radius | The radius around the point. |
|
inline |
Calculates the center point of the box.
|
inline |
Same as Box::overlap.
[in] | b | the box to check the collision with. |
Deserializes the box from the given input stream.
[in] | is | The input stream. |
Calculates the diagonal length of the box.
Get the length of the box along a given dimension.
[in] | i | the index of the dimension to get the length of. |
|
inline |
Computes and returns the intersection between the current box and the given box b.
[in] | b | The box to intersect with the current box |
|
inline |
Same as Box::overlap.
[in] | b | the box to check the collision with. |
Checks whether the box is empty or not.
A box is considered empty if the minimum point and the maximum point are equal.
Checks whether a given point is inside the box or not, bounds included.
A point is considered inside the box if its coordinates are greater or equal to the corresponding minimum point and less or equal to the corresponding maximum point for each dimension.
[in] | p | The point to be checked. |
|
inline |
Checks if a point is inside the open box (max bound excluded); e.g. p in [min, max).
[in] | p | the point to check if is inside the current box. |
|
inline |
Checks whether a given point is inside the box or not, bounds excluded.
A point is considered inside the box if its coordinates are greater than the corresponding minimum point and less than the corresponding maximum point for each dimension.
[in] | p | The point to be checked. |
Checks whether the box is null or not.
A box is considered null if at least one minimum component is greater than the corresponding maximum component.
|
inline |
Returns a reference to the maximum point of the box.
Returns a const reference to the maximum point of the box.
Computes the maximum dimension of the box, which is defined as the greater difference between the maximum and minimum coordinates along any dimension.
|
inline |
Returns a reference to the minimum point of the box.
Returns a const reference to the minimum point of the box.
Calculates the minimum dimension of the box, which is defined as the smallest difference between the maximum and minimum coordinates along any dimension.
|
inline |
Compares the current box to another box for inequality.
[in] | b | The box to compare to. |
|
inline |
Compares the current box to another box for equality.
[in] | b | The box to compare to. |
|
inline |
Check if two boxes overlap.
[in] | b | the box to check the collision with. |
Serializes the box to the given output stream.
[in] | os | The output stream. |
Sets the Box to null. A box is considered null if at least one min component is greater than the corresponding max component.
This member function sets all the min values to the max representable Scalar and the max values to lowest representable Scalar.
|
inline |
Computes the size of the box.
Calculates the squared length of the diagonal of the box.
Translates the box by summing the values of p.
[in] | p | The point to translate the box by |
Computes the volume of the box.