SPH
Public Member Functions | Static Public Member Functions | Friends | List of all members
Box Class Reference

Helper object defining three-dimensional interval (box). More...

#include <Box.h>

Public Member Functions

INLINE Box ()=default
 Constructs empty box with negative dimensions. More...
 
INLINE Box (const Vector &minBound, const Vector &maxBound)
 Constructs a box given its 'corners'. More...
 
INLINE void extend (const Vector &v)
 Enlarges the box to contain the vector. More...
 
INLINE void extend (const Box &other)
 Enlarges the box to contain another box. More...
 
INLINE bool contains (const Vector &v) const
 Checks if the vector lies inside the box. More...
 
INLINE Vector clamp (const Vector &v) const
 Clamps all components of the vector to fit within the box. More...
 
INLINE const Vectorlower () const
 Returns lower bounds of the box. More...
 
INLINE Vectorlower ()
 Returns lower bounds of the box. More...
 
INLINE const Vectorupper () const
 Returns upper bounds of the box. More...
 
INLINE Vectorupper ()
 Returns upper bounds of the box. More...
 
INLINE Vector size () const
 Returns box dimensions. More...
 
INLINE Vector center () const
 Returns the center of the box. More...
 
INLINE Float volume () const
 Returns the volume of the box. More...
 
INLINE bool operator== (const Box &other) const
 Compares two boxes, return true if box lower and upper bounds are equal. More...
 
INLINE bool operator!= (const Box &other) const
 Checks for inequality of boxes. More...
 
INLINE Box translate (const Vector &offset) const
 Returns a box with specified offset. More...
 
INLINE Pair< Boxsplit (const Size dim, const Float x) const
 Splits the box along given coordinate. More...
 
INLINE Box intersect (const Box &other) const
 Computes the intersection of this box with another one. More...
 
template<typename TFunctor >
void iterate (const Vector &step, TFunctor &&functor) const
 Execute functor for all possible values of vector (with constant stepping) More...
 
template<typename TFunctor >
void iterateWithIndices (const Vector &step, TFunctor &&functor) const
 Execute functor for all possible values of vector (with constant stepping), passing auxiliary indices together with the vector. More...
 

Static Public Member Functions

static Box EMPTY ()
 Syntactic sugar, returns a default-constructed (empty) box. More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const Box &box)
 Prints the bounds of the box into the stream. More...
 

Detailed Description

Helper object defining three-dimensional interval (box).

Degenerated box (one or more dimensions equal to zero) is a valid state of the object.

Definition at line 17 of file Box.h.

Constructor & Destructor Documentation

◆ Box() [1/2]

INLINE Box::Box ( )
default

Constructs empty box with negative dimensions.

The box in this state will throw assert if member function are called. Function extend is an exception, it will simply move both lower and upper bound of the box to the position of new point, resulting in box of zero dimensions. Another exception is method contains, that simply returns false for all points.

◆ Box() [2/2]

INLINE Box::Box ( const Vector minBound,
const Vector maxBound 
)
inline

Constructs a box given its 'corners'.

Components of minBound must be lower or equal to components of maxBound, checked by assert.

Definition at line 34 of file Box.h.

Member Function Documentation

◆ center()

INLINE Vector Box::center ( ) const
inline

Returns the center of the box.

Definition at line 112 of file Box.h.

◆ clamp()

INLINE Vector Box::clamp ( const Vector v) const
inline

Clamps all components of the vector to fit within the box.

Definition at line 76 of file Box.h.

◆ contains()

INLINE bool Box::contains ( const Vector v) const
inline

Checks if the vector lies inside the box.

If the vector lies on the boundary, it is assumed to within the box and the function returns true.

Definition at line 66 of file Box.h.

◆ EMPTY()

static Box Box::EMPTY ( )
inlinestatic

Syntactic sugar, returns a default-constructed (empty) box.

Definition at line 41 of file Box.h.

◆ extend() [1/2]

INLINE void Box::extend ( const Box other)
inline

Enlarges the box to contain another box.

The other box can be invalid, this box is then unaffected, no assert is issued. If an empty (invalid) box is extended with other empty box, it is still empty.

Definition at line 58 of file Box.h.

◆ extend() [2/2]

INLINE void Box::extend ( const Vector v)
inline

Enlarges the box to contain the vector.

If the box already contains given vectors, it is left unchanged. If the box was previously empty, it now contains the given point

Definition at line 49 of file Box.h.

◆ intersect()

INLINE Box Box::intersect ( const Box other) const
inline

Computes the intersection of this box with another one.

Definition at line 155 of file Box.h.

◆ iterate()

template<typename TFunctor >
void Box::iterate ( const Vector step,
TFunctor &&  functor 
) const
inline

Execute functor for all possible values of vector (with constant stepping)

Definition at line 168 of file Box.h.

◆ iterateWithIndices()

template<typename TFunctor >
void Box::iterateWithIndices ( const Vector step,
TFunctor &&  functor 
) const
inline

Execute functor for all possible values of vector (with constant stepping), passing auxiliary indices together with the vector.

Definition at line 182 of file Box.h.

◆ lower() [1/2]

INLINE Vector& Box::lower ( )
inline

Returns lower bounds of the box.

Definition at line 88 of file Box.h.

◆ lower() [2/2]

INLINE const Vector& Box::lower ( ) const
inline

Returns lower bounds of the box.

Definition at line 82 of file Box.h.

◆ operator!=()

INLINE bool Box::operator!= ( const Box other) const
inline

Checks for inequality of boxes.

Definition at line 129 of file Box.h.

◆ operator==()

INLINE bool Box::operator== ( const Box other) const
inline

Compares two boxes, return true if box lower and upper bounds are equal.

Definition at line 124 of file Box.h.

◆ size()

INLINE Vector Box::size ( ) const
inline

Returns box dimensions.

Definition at line 106 of file Box.h.

◆ split()

INLINE Pair<Box> Box::split ( const Size  dim,
const Float  x 
) const
inline

Splits the box along given coordinate.

The splitting plane must pass through the box.

Parameters
dimDimension, can be X, Y or Z.
xCoordinate in given dimension used for the split
Returns
Two boxes created by the split.

Definition at line 144 of file Box.h.

◆ translate()

INLINE Box Box::translate ( const Vector offset) const
inline

Returns a box with specified offset.

Definition at line 134 of file Box.h.

◆ upper() [1/2]

INLINE Vector& Box::upper ( )
inline

Returns upper bounds of the box.

Definition at line 100 of file Box.h.

◆ upper() [2/2]

INLINE const Vector& Box::upper ( ) const
inline

Returns upper bounds of the box.

Definition at line 94 of file Box.h.

◆ volume()

INLINE Float Box::volume ( ) const
inline

Returns the volume of the box.

Definition at line 118 of file Box.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const Box box 
)
friend

Prints the bounds of the box into the stream.

The box can be empty, in which case EMPTY is written instead of the bounds.

Definition at line 200 of file Box.h.


The documentation for this class was generated from the following file: