Library of Assembled Shared Sources
lass::prim::Aabb2D< T, MinMaxPolicy > Class Template Reference

your momma's axis aligned bounding box. More...

#include <aabb_2d.h>

Inheritance diagram for lass::prim::Aabb2D< T, MinMaxPolicy >:

Public Member Functions

 Aabb2D ()
 Construct an empty bounding box.
 
 Aabb2D (const TPoint &min, const TPoint &max)
 Construct bounding box, spanned by min and max.
 
 Aabb2D (const TPoint &point)
 Construct bounding box around a single point (min == max)
 
template<class MMP2>
 Aabb2D (const Aabb2D< T, MMP2 > &other)
 copy constructor.
 
const TPoint & min () const
 return corner with smallest component values
 
const TPoint & max () const
 Return corner with largest component values.
 
void setMin (const TPoint &min)
 set corner with smallest component values
 
void setMax (const TPoint &max)
 set corner with larges component values
 
template<class MMP2>
TSelfoperator= (const Aabb2D< T, MMP2 > &other)
 assign one bounding box to another.
 
TSelfoperator+= (const TPoint &point)
 Expand bounding box so it contains point.
 
template<class MMP2>
TSelfoperator+= (const Aabb2D< T, MMP2 > &other)
 Expand bounding box so it contains the other bounding box.
 
void grow (TParam iDistance)
 Expand bounding box by distance iDistance.
 
void scale (TParam iScale)
 Scale bounding box by scale iScale.
 
const TPointH center () const
 Return the center point of the bounding box.
 
const TVector size () const
 Return size of bounding box per axis, max - min.
 
const TValue perimeter () const
 Returns perimeter of bounding box.
 
const TValue area () const
 Returns area of bounding box.
 
Side classify (const TPoint &point) const
 Classify if a point is in or outside the bounding box, or on its surface.
 
bool contains (const TPoint &point) const
 Returns true if point is inside bounding box or on its surface.
 
template<class MMP2>
bool contains (const Aabb2D< T, MMP2 > &other) const
 Returns true if the AABB other is inside (or on its surface) this AABB.
 
template<class MMP2>
bool intersects (const Aabb2D< T, MMP2 > &other) const
 Check if two axis-aligned bounding boxes do intersect.
 
template<class MMP2>
bool collides (const Aabb2D< T, MMP2 > &other) const
 Check if two axis-aligned bounding boxes do dollide.
 
template<class RandomGenerator>
const TPoint random (RandomGenerator &random) const
 Return a random point so that bounding box contains it.
 
void clear ()
 set AABB to an empty box
 
bool isEmpty () const
 Return true if bounding box contains no points.
 
bool isValid () const
 internal check to see if AABB is valid.
 
template<typename MMP2>
void swap (Aabb2D< T, MMP2 > &other)
 swap two bounding boxes.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, class MMPa, class MMPb>
const Aabb2D< T, MMPa > operator+ (const Aabb2D< T, MMPa > &a, const Aabb2D< T, MMPb > &b)
 join two AABBs
 
template<typename T, class MMP>
const Aabb2D< T, MMP > operator+ (const Aabb2D< T, MMP > &a, const Point2D< T > &b)
 add a point to an AABB
 
template<typename T, class MMP>
const Aabb2D< T, MMP > operator+ (const Point2D< T > &a, const Aabb2D< T, MMP > &b)
 add a point to an AABB
 
template<typename T>
const Aabb2D< T > aabb (const Point2D< T > &point)
 create an aabb with a single point in it
 
template<typename T, class MMP>
distance (const Aabb2D< T, MMP > &a, const Point2D< T > &b)
 distance between AABB and point
 
template<typename T, class MMPa, class MMPb>
distance (const Aabb2D< T, MMPa > &a, const Aabb2D< T, MMPb > &b)
 distance between two AABBs
 
template<typename T, class MMPa, class MMPb, class MMPr>
Result intersect (const Aabb2D< T, MMPa > &a, const Aabb2D< T, MMPb > &b, Aabb2D< T, MMPr > &result)
 Calculate the intersection of two axis aligned bounding boxes.
 
template<typename T, class DegeneratePolicy>
Aabb2D< T > aabb (const SimplePolygon2D< T, DegeneratePolicy > &polygon)
 determine axis aligned bounding box of a 2D simple polygon
 

Detailed Description

template<typename T, class MinMaxPolicy = StrictMinMax>
class lass::prim::Aabb2D< T, MinMaxPolicy >

your momma's axis aligned bounding box.

Author
Bram de Greve [BdG]
Date
2003

An AABB (Axis Aligned Bounding Box) is a rectangular box of a given dimension (in this case a 2D rectangle), that is often used as a simple bounding volume of another primitive or data structure.

"A form of a bounding box where the box is aligned to the axis therefore only two points in space are needed to define it. AABB's are much faster to use, and take up less memory, but are very limited in the sense that they can only be aligned to the axis.", http://www.gamedev.net/dict/term.asp?TermID=525

The way an AABB handles its minima and maxima can be set by the MinMaxPolicy. On policy StrictPolicy will enforce you to use correct minima and maxima, and on any suspicious behaviour, it will throw an exception. The other policy AutoPolicy will try to correct misbehaviour without your notice. For more information on these policies, I refer to the documentation compagning these policies.

Definition at line 88 of file aabb_2d.h.

Member Function Documentation

◆ grow()

template<typename T, class MMP>
void lass::prim::Aabb2D< T, MMP >::grow ( TParam iDistance)

Expand bounding box by distance iDistance.

Negative values causing reversal of the bounding box will cause the box to shrink to the empty box.

Definition at line 219 of file aabb_2d.inl.

References clear(), and isValid().

◆ scale()

template<typename T, class MMP>
void lass::prim::Aabb2D< T, MMP >::scale ( TParam iScale)

Scale bounding box by scale iScale.

Fractions will shrink the bounding box. The origin of scaling is the center of the bounding box. Negative values of the scale have same effect as positive ones.

Definition at line 239 of file aabb_2d.inl.

References lass::num::abs(), isValid(), and size().

◆ center()

template<typename T, class MMP>
const Aabb2D< T, MMP >::TPointH lass::prim::Aabb2D< T, MMP >::center ( ) const

Return the center point of the bounding box.

We return a homogeneous point to avoid the division by two (that might not be supported by some types like integers)

Definition at line 255 of file aabb_2d.inl.

References isValid().

◆ classify()

template<typename T, class MMP>
Side lass::prim::Aabb2D< T, MMP >::classify ( const TPoint & point) const

Classify if a point is in or outside the bounding box, or on its surface.

Returns
sInside, sSurface, sOutside

Definition at line 313 of file aabb_2d.inl.

References isValid(), lass::prim::sInside, lass::prim::sOutside, and lass::prim::sSurface.

◆ contains() [1/2]

template<typename T, class MMP>
bool lass::prim::Aabb2D< T, MMP >::contains ( const TPoint & point) const

Returns true if point is inside bounding box or on its surface.

Is equivalent to this->classify(point) != sOutside, but might be faster.

Definition at line 338 of file aabb_2d.inl.

References isValid().

Referenced by random().

◆ contains() [2/2]

template<typename T, class MMP>
template<class MMP2>
bool lass::prim::Aabb2D< T, MMP >::contains ( const Aabb2D< T, MMP2 > & other) const

Returns true if the AABB other is inside (or on its surface) this AABB.

  • Is equivalent to this->contains(other.min()) && this->contains(other.max()).
  • if other is an empty AABB, it will always return true (an empty set is always a part of any other set).

Definition at line 354 of file aabb_2d.inl.

References Aabb2D(), isValid(), max(), and min().

◆ intersects()

template<typename T, class MMP>
template<class MMP2>
bool lass::prim::Aabb2D< T, MMP >::intersects ( const Aabb2D< T, MMP2 > & other) const

Check if two axis-aligned bounding boxes do intersect.

Returns
  • false intersection of the AABBs is empty.
  • true intersection of the AABBs is not empty.
FAQ: What's the difference between this->intersects(other) and this->collides(other) ?
When two AABB are touching each other (surface to surface), the intersection isn't empty. i.e. the intersection is the line of points that belong to both the surfaces of the AABBs. In that case, the intersection is a degenerated AABB though, one with area()==0. In collision detection however, you don't want this degenerated case of intersection to be considered as a collision. Two bodies may touch, but the must not have an overlap thas has a non-zero area. That's why we have two methods: intersects returns true on touching AABBs, collides will return false. Of course, in the non-degenerate cases, they behave the same.

Use the seperating axis test to test if two AABB's do intersect: GOMEZ M. (1999), Simple Intersection Tests For Games, Gamasutra, http://www.gamasutra.com, http://www.gamasutra.com/features/19991018/Gomez_3.htm

Definition at line 384 of file aabb_2d.inl.

References Aabb2D(), isValid(), max(), and min().

Referenced by intersect().

◆ collides()

template<typename T, class MMP>
template<class MMP2>
bool lass::prim::Aabb2D< T, MMP >::collides ( const Aabb2D< T, MMP2 > & other) const

Check if two axis-aligned bounding boxes do dollide.

Returns
  • true the AABBs do collide.
  • false they don't.
FAQ: What's the difference between this->intersects(other) and this->collides(other) ?
When two AABB are touching each other (surface to surface), the intersection isn't empty. i.e. the intersection is the line of points that belong to both the surfaces of the AABBs. In that case, the intersection is a degenerated AABB though, one with area()==0. In collision detection however, you don't want this degenerated case of intersection to be considered as a collision. Two bodies may touch, but the must not have an overlap thas has a non-zero area. That's why we have two methods: intersects returns true on touching AABBs, collides will return false. Of course, in the non-degenerate cases, they behave the same.

Use the seperating axis test to test if two AABB's do intersect: GOMEZ M. (1999), Simple Intersection Tests For Games, Gamasutra, http://www.gamasutra.com, http://www.gamasutra.com/features/19991018/Gomez_3.htm

Definition at line 415 of file aabb_2d.inl.

References Aabb2D(), isValid(), max(), and min().

◆ isEmpty()

template<typename T, class MMP>
bool lass::prim::Aabb2D< T, MMP >::isEmpty ( ) const

Return true if bounding box contains no points.

i.e. this->contains(Point3D<T>(x, y, z)) will return false for all possible values of x, y and z.

Definition at line 459 of file aabb_2d.inl.

References isValid().

Referenced by Aabb2D(), area(), clear(), distance(), distance(), perimeter(), setMax(), size(), and lass::prim::Transformation3D< U >::transform().

◆ isValid()

template<typename T, class MMP>
bool lass::prim::Aabb2D< T, MMP >::isValid ( ) const

internal check to see if AABB is valid.

There are two valid states for the AABB:

  • max_.x < min_.x which means the box is empty
  • max_.x >= min_.x && max_.y >= min_.y which means the box is not empty. That gives us an invalid state as well:
  • max_.x >= min_.x && max_.y < min_.y. This state would cause isEmpty() to yield false, while there's still nothing in it (there's no single point for which contains(p) would return true.

When the regular minmax policies are used (StrictMinMax and AutoMinMax), there's no way any AABB would become invalid, and this test counts as an invariant to the box. However, when using the UncheckedMinMax policy, you're on your own.

Definition at line 481 of file aabb_2d.inl.

Referenced by Aabb2D(), Aabb2D(), Aabb2D(), center(), classify(), clear(), collides(), contains(), contains(), grow(), intersect(), intersects(), isEmpty(), operator+=(), operator+=(), random(), scale(), setMax(), and swap().

Friends And Related Symbol Documentation

◆ distance() [1/2]

template<typename T, class MMP>
T distance ( const Aabb2D< T, MMP > & a,
const Point2D< T > & b )
related

distance between AABB and point

Parameters
aAABB
bpoint
Returns
absolute distance between point and AABB. If point is inside AABB, distance is 0.
Precondition
a should not be empty. Undefined behaviour if it is empty.

Definition at line 561 of file aabb_2d.inl.

◆ distance() [2/2]

template<typename T, class MMPa, class MMPb>
T distance ( const Aabb2D< T, MMPa > & a,
const Aabb2D< T, MMPb > & b )
related

distance between two AABBs

Parameters
aAABB
bAABB
Returns
absolute distance. If one AABB is completely inside the other, distance is 0.
Precondition
a and b should not be empty. Undefined behaviour if they are.

Definition at line 578 of file aabb_2d.inl.

◆ intersect()

template<typename T, class MMPa, class MMPb, class MMPr>
Result intersect ( const Aabb2D< T, MMPa > & a,
const Aabb2D< T, MMPb > & b,
Aabb2D< T, MMPr > & result )
related

Calculate the intersection of two axis aligned bounding boxes.

Parameters
athe first AABB :)
bthe second AABB
resultthe intersection of a and b. In contrary to other intersection functions, this output argument will always be assigned, even if there's no result. By no result we mean: the intersection is empty. For most other intersection functions, we can't assign a meaning full value if there's no intersection, so we don't. However, in this case we can assign an empty AABB. And that's exactly what we do. So, the output argument is always valid, even if the return value suggests otherwise (in fact, you don't have to bother the return value this time)
Returns
  • rNone intersection of the AABBs is empty. result is an empty AABB.
  • rOne intersection of the AABBs is not empty. result contains intersection.

Definition at line 605 of file aabb_2d.inl.


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