vmath  vmath-0.12
Aabb3< T > Class Template Reference

Axes-aligned bounding-box (aka AABB) class. More...

#include <vmath.h>

Public Member Functions

 Aabb3 ()
 Constructs invalid axes-aligned bounding-box. More...
 
template<typename SrcT >
 Aabb3 (const Vector3< SrcT > &point)
 Constructs axes-aligned bound-box containing one point point. More...
 
template<typename SrcT >
 Aabb3 (SrcT x0, SrcT y0, SrcT z0, SrcT x1, SrcT y1, SrcT z1)
 Constructs axes-aligned bounding-box form two corner points (x0, y0, z0) and (x1, y1, z1) More...
 
template<typename SrcT >
 Aabb3 (SrcT x, SrcT y, SrcT z)
 Constructs axes-aligned bounding-box containing point (x, y, z) More...
 
template<typename SrcT >
 Aabb3 (const Aabb3< SrcT > &src)
 Creates copy of axis-aligned bounding-box. More...
 
template<typename SrcT >
Aabb3< T > & operator= (const Aabb3< SrcT > &rhs)
 Assign operator. More...
 
bool valid () const
 Checks if bounding-box is valid. More...
 
void invalidate ()
 Makes this bounding-box invalid. More...
 
template<typename SrcT >
void extend (const Vector3< SrcT > &point)
 Extends this bounding-box by a point point. More...
 
template<typename SrcT >
void extend (const Aabb3< SrcT > &box)
 Extends this bounding-box by a box box. More...
 
template<typename SrcT >
Aabb3< T > extended (const Vector3< SrcT > &point) const
 Gets a copy of this bounding-box extend by a point point. More...
 
template<typename SrcT >
Aabb3< T > extended (const Aabb3< SrcT > &box) const
 Gets a copy of this bounding-box extnended by box box. More...
 
template<typename SrcT >
bool intersects (const Vector3< SrcT > &point) const
 Tests if the point point is within this bounding-box. More...
 
template<typename SrcT >
bool intersects (const Aabb3< SrcT > &box) const
 Tests if other bounding-box box intersects (even partially) with this bouding-box. More...
 
template<typename SrcT >
Aabb3< T > intersection (const Aabb3< SrcT > &other) const
 Gets result of intersection of this bounding-box with other bounding-box. More...
 
Vector3< T > center () const
 Gets center point of bounding-box. More...
 
Vector3< T > extent () const
 Gets extent of bounding-box. More...
 
Vector3< T > size () const
 Gets diagonal size of bounding-box. More...
 
Vector3< T > point (size_t i) const
 Gets all 8 corner-points of bounding box. More...
 
Aabb3< T > transformed (const Matrix4< T > &t) const
 Gets transformed bounding-box by transform t. More...
 
template<typename RhsT >
bool operator== (const Aabb3< RhsT > &rhs) const
 Tests if rhs is equal to this bounding-box. More...
 
template<typename RhsT >
bool operator!= (const Aabb3< RhsT > &rhs) const
 Tests if rhs is not equal to this bounding-box. More...
 
Aabb3< T > operator* (const Matrix4< T > &rhs) const
 Gets transformed bounding-box by transform rhs. More...
 
Aabb3< T > & operator*= (const Matrix4< T > &rhs)
 Apply transform rhs to this bounding-box. More...
 
template<typename SrcT >
Aabb3< T > & operator<< (const Vector3< SrcT > &rhs)
 Extends this bounding-box by point rhs. More...
 
template<typename SrcT >
Aabb3< T > & operator<< (const Aabb3< SrcT > &rhs)
 Extends this bounding-box by box rhs. More...
 
template<typename RhsT >
Aabb3< T > operator| (const Aabb3< RhsT > &rhs) const
 Union of this and rhs bounding-boxes. More...
 
template<typename RhsT >
Aabb3< T > operator& (const Aabb3< RhsT > &rhs) const
 Intersection of this and rhs bounding-boxed. More...
 

Public Attributes

Vector3< T > min
 Position of Min corner of bounding box. More...
 
Vector3< T > max
 Position of Max corner of bounding box. More...
 

Friends

std::ostream & operator<< (std::ostream &lhs, const Aabb3< T > &rhs)
 Outputs string representation of bounding-box rhs to output stream lhs. More...
 

Detailed Description

template<typename T>
class Aabb3< T >

Axes-aligned bounding-box (aka AABB) class.

This class provides functionality for:

  • creating AABB from point, or other AABB,
  • testing if point of other AABB intersects with,
  • getting result of intersection with other AABB,
  • transforming AABB with 4x4 matrix.

There are also overloaded couple of operators to shorten common operation. For instance you can use operator<< on AABB to extend it with passed point or other AABB.

Aabb3f aabb;
aabb << Vector3f(1, 1, 2) << Aabb3f(-3,-3,-3, 2, 2, 2);

Constructor & Destructor Documentation

template<typename T>
Aabb3< T >::Aabb3 ( )
inline

Constructs invalid axes-aligned bounding-box.

See also
valid() for explanation of invalid bounding-box usage.
template<typename T>
template<typename SrcT >
Aabb3< T >::Aabb3 ( const Vector3< SrcT > &  point)
inline

Constructs axes-aligned bound-box containing one point point.

Parameters
point
template<typename T>
template<typename SrcT >
Aabb3< T >::Aabb3 ( SrcT  x0,
SrcT  y0,
SrcT  z0,
SrcT  x1,
SrcT  y1,
SrcT  z1 
)
inline

Constructs axes-aligned bounding-box form two corner points (x0, y0, z0) and (x1, y1, z1)

Parameters
x0X-coordinate of first point
y0Y-coordinate of first point
z0Z-coordinate of first point
x1X-coordinate of second point
y1Y-coordinate of second point
z1Z-coordinate of second point
template<typename T>
template<typename SrcT >
Aabb3< T >::Aabb3 ( SrcT  x,
SrcT  y,
SrcT  z 
)
inline

Constructs axes-aligned bounding-box containing point (x, y, z)

Parameters
xX-coordinate of point
yY-coordinate of point
zZ-coordinate of point
template<typename T>
template<typename SrcT >
Aabb3< T >::Aabb3 ( const Aabb3< SrcT > &  src)
inline

Creates copy of axis-aligned bounding-box.

Parameters
srcSource bounding-box

Member Function Documentation

template<typename T>
Vector3<T> Aabb3< T >::center ( ) const
inline

Gets center point of bounding-box.

Returns
A center point of bounding-box.
template<typename T>
template<typename SrcT >
void Aabb3< T >::extend ( const Vector3< SrcT > &  point)
inline

Extends this bounding-box by a point point.

Parameters
pointA point to extend bounding-box by.
template<typename T>
template<typename SrcT >
void Aabb3< T >::extend ( const Aabb3< SrcT > &  box)
inline

Extends this bounding-box by a box box.

Parameters
boxA box to extend this bounding-box by.
template<typename T>
template<typename SrcT >
Aabb3<T> Aabb3< T >::extended ( const Vector3< SrcT > &  point) const
inline

Gets a copy of this bounding-box extend by a point point.

Parameters
pointA point to extend the box by
Returns
Copy of extended bounding-box
template<typename T>
template<typename SrcT >
Aabb3<T> Aabb3< T >::extended ( const Aabb3< SrcT > &  box) const
inline

Gets a copy of this bounding-box extnended by box box.

Parameters
boxA box to extend the copy be.
Returns
Copy of extended bounding-box
template<typename T>
Vector3<T> Aabb3< T >::extent ( ) const
inline

Gets extent of bounding-box.

Returns
Extent of bounding-box.
template<typename T>
template<typename SrcT >
Aabb3<T> Aabb3< T >::intersection ( const Aabb3< SrcT > &  other) const
inline

Gets result of intersection of this bounding-box with other bounding-box.

In case the boxes don't intersect, the returned bounding-box is invalid.

Parameters
otherBox to be tested
Returns
Result of intersection.
See also
valid() method for more information on invalid bounding-boxes.
template<typename T>
template<typename SrcT >
bool Aabb3< T >::intersects ( const Vector3< SrcT > &  point) const
inline

Tests if the point point is within this bounding-box.

Parameters
pointA point to be tested
Returns
True if point point lies within bounding-box, otherwise false.
template<typename T>
template<typename SrcT >
bool Aabb3< T >::intersects ( const Aabb3< SrcT > &  box) const
inline

Tests if other bounding-box box intersects (even partially) with this bouding-box.

Parameters
boxA box to be tested for intersection.
Returns
True if there's intersection between boxes, otherwise false.
template<typename T>
void Aabb3< T >::invalidate ( )
inline

Makes this bounding-box invalid.

So calling valid() gets false.

See also
valid() method for more info on usage of invalid bounding-boxes.
template<typename T>
template<typename RhsT >
bool Aabb3< T >::operator!= ( const Aabb3< RhsT > &  rhs) const
inline

Tests if rhs is not equal to this bounding-box.

Parameters
rhsRight-hand side
Returns
True if rhs and this bounding-boxes are not equal, otherwise false
template<typename T>
template<typename RhsT >
Aabb3<T> Aabb3< T >::operator& ( const Aabb3< RhsT > &  rhs) const
inline

Intersection of this and rhs bounding-boxed.

Parameters
rhsRight-hand side
Returns
Resulting bouding-box representing the intersection.
template<typename T>
Aabb3<T> Aabb3< T >::operator* ( const Matrix4< T > &  rhs) const
inline

Gets transformed bounding-box by transform rhs.

Parameters
rhsMatrix 4x4 representing the transform
Returns
Transformed bounding-box
template<typename T>
Aabb3<T>& Aabb3< T >::operator*= ( const Matrix4< T > &  rhs)
inline

Apply transform rhs to this bounding-box.

Parameters
rhsA transform to be applied
Returns
Reference to this
template<typename T>
template<typename SrcT >
Aabb3<T>& Aabb3< T >::operator<< ( const Vector3< SrcT > &  rhs)
inline

Extends this bounding-box by point rhs.

Parameters
rhsA point to extend this bounding-box by
Returns
Reference to this
template<typename T>
template<typename SrcT >
Aabb3<T>& Aabb3< T >::operator<< ( const Aabb3< SrcT > &  rhs)
inline

Extends this bounding-box by box rhs.

Parameters
rhsA box to extend this bounding-box by
Returns
Reference to this
template<typename T>
template<typename SrcT >
Aabb3<T>& Aabb3< T >::operator= ( const Aabb3< SrcT > &  rhs)
inline

Assign operator.

Parameters
rhssource bounding-box
Returns
refenrence to this
template<typename T>
template<typename RhsT >
bool Aabb3< T >::operator== ( const Aabb3< RhsT > &  rhs) const
inline

Tests if rhs is equal to this bounding-box.

Parameters
rhsRight-hand side
Returns
True if rhs and this bounding-boxes are equal, otherwise false
template<typename T>
template<typename RhsT >
Aabb3<T> Aabb3< T >::operator| ( const Aabb3< RhsT > &  rhs) const
inline

Union of this and rhs bounding-boxes.

Parameters
rhsRight-hand side of union
Returns
A resulting bounding-box representing union
template<typename T>
Vector3<T> Aabb3< T >::point ( size_t  i) const
inline

Gets all 8 corner-points of bounding box.

Parameters
iAn index of bounding-box corner point. Valid values are 0 .. 7.
Returns
A position of i-th corner-point.
Note
The order of points is as follows (where + denotes max-point and - min-point):
  1. (+ + +)
  2. (- + +)
  3. (+ - +)
  4. (- - +)
  5. (+ + -)
  6. (- + -)
  7. (+ - -)
  8. (- - -)
template<typename T>
Vector3<T> Aabb3< T >::size ( ) const
inline

Gets diagonal size of bounding-box.

Returns
Sizes for particular dimensions.
template<typename T>
Aabb3<T> Aabb3< T >::transformed ( const Matrix4< T > &  t) const
inline

Gets transformed bounding-box by transform t.

Parameters
tA transform matrix
Returns
Transformed bounding-box
template<typename T>
bool Aabb3< T >::valid ( ) const
inline

Checks if bounding-box is valid.

Valid bounding-box has non-negative size. If an invalid bounding-box is extended by point or another bounding-box, the target bounding box becomes valid and contains solely the source point or bounding-box respectively.

Returns
True if box is valid, otherwise false

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  lhs,
const Aabb3< T > &  rhs 
)
friend

Outputs string representation of bounding-box rhs to output stream lhs.

Parameters
lhsOutput stream to write to
rhsBounding-box to write to output stream.
Returns
Reference to output stream lhs

Member Data Documentation

template<typename T>
Vector3<T> Aabb3< T >::max

Position of Max corner of bounding box.

template<typename T>
Vector3<T> Aabb3< T >::min

Position of Min corner of bounding box.


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