PlayRho  2.0.0
An interactive physics engine & library.
playrho::detail::AABB< N > Struct Template Reference

N-dimensional Axis Aligned Bounding Box. More...

#include <playrho/detail/AABB.hpp>

Inheritance diagram for playrho::detail::AABB< N >:
[legend]

Public Types

using Location = Vector< Length, N >
 Alias for the location type.
 

Public Member Functions

constexpr AABB ()=default
 Default constructor. More...
 
constexpr AABB (const Location a, const Location b) noexcept
 Initializing constructor for two points. More...
 
constexpr AABB (const Location p) noexcept
 Initializing constructor for a single point. More...
 
template<typename... Tail>
constexpr AABB (std::enable_if_t< sizeof...(Tail)+1==N, LengthInterval > head, Tail... tail) noexcept
 Initializing constructor. More...
 

Public Attributes

LengthInterval ranges [N]
 Holds the value range of each dimension from 0 to N-1.
 

Related Functions

(Note that these are not member functions.)

template<std::size_t N>
constexpr bool Contains (const AABB< N > &a, const AABB< N > &b) noexcept
 Checks whether the first AABB fully contains the second AABB. More...
 
template<std::size_t N>
constexpr AABB< N > & Fatten (AABB< N > &var, const NonNegative< Length > amount) noexcept
 Fattens an AABB by the given amount.
 
template<std::size_t N>
constexpr Vector< Length, N > GetCenter (const AABB< N > &aabb) noexcept
 Gets the center of the AABB.
 
template<std::size_t N>
constexpr Vector< Length, N > GetDimensions (const AABB< N > &aabb) noexcept
 Gets dimensions of the given AABB.
 
template<std::size_t N>
constexpr AABB< N > GetDisplacedAABB (AABB< N > aabb, const Vector< Length, N > displacement)
 Gets the AABB that the result of displacing the given AABB by the given displacement amount.
 
template<std::size_t N>
constexpr AABB< N > GetEnclosingAABB (AABB< N > a, const AABB< N > &b)
 Gets the AABB that minimally encloses the given AABBs.
 
template<std::size_t N>
constexpr Vector< Length, N > GetExtents (const AABB< N > &aabb) noexcept
 Gets the extents of the AABB (half-widths).
 
template<std::size_t N>
constexpr AABB< N > GetFattenedAABB (AABB< N > aabb, const Length amount)
 Gets the fattened AABB result.
 
template<std::size_t N>
constexpr Vector< Length, N > GetLowerBound (const AABB< N > &aabb) noexcept
 Gets the lower bound.
 
template<std::size_t N>
constexpr AABB< N > GetMovedAABB (AABB< N > aabb, const Vector< Length, N > value) noexcept
 Gets the result of moving the given AABB by the given value.
 
constexpr Length GetPerimeter (const AABB &aabb) noexcept
 Gets the perimeter length of the 2-dimensional AABB. More...
 
template<std::size_t N>
constexpr Vector< Length, N > GetUpperBound (const AABB< N > &aabb) noexcept
 Gets the upper bound.
 
template<std::size_t N>
constexpr AABB< N > & Include (AABB< N > &var, const AABB< N > &val) noexcept
 Includes the second AABB into the first one. More...
 
template<std::size_t N>
constexpr AABB< N > & Include (AABB< N > &var, const Vector< Length, N > &value) noexcept
 Includes the given location into the given AABB.
 
template<std::size_t N>
constexpr bool operator!= (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Gets whether the two AABB objects are not equal. More...
 
template<std::size_t N>
bool operator< (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Less-than operator.
 
template<std::size_t N>
bool operator<= (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Less-than or equal-to operator.
 
template<std::size_t N>
constexpr bool operator== (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Gets whether the two AABB objects are equal. More...
 
template<std::size_t N>
bool operator> (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Greater-than operator.
 
template<std::size_t N>
bool operator>= (const AABB< N > &lhs, const AABB< N > &rhs) noexcept
 Greater-than or equal-to operator.
 
template<std::size_t N>
constexpr bool TestOverlap (const AABB< N > &a, const AABB< N > &b) noexcept
 Tests for overlap between two axis aligned bounding boxes. More...
 

Detailed Description

template<std::size_t N>
struct playrho::detail::AABB< N >

N-dimensional Axis Aligned Bounding Box.

This is a concrete value class template for an N-dimensional axis aligned bounding box (AABB) which is a type of bounding volume.

Note
This class satisfies at least the following named requirement: all the basic named requirements, EqualityComparable, and Swappable.
This class is composed of — as in contains and owns — N LengthInterval variables.
Non-defaulted methods of this class are marked noexcept and expect that the Length type doesn't throw.
See also
https://en.wikipedia.org/wiki/Bounding_volume
https://en.cppreference.com/w/cpp/named_req

Constructor & Destructor Documentation

◆ AABB() [1/4]

template<std::size_t N>
constexpr playrho::detail::AABB< N >::AABB ( )
constexprdefault

Default constructor.

Constructs an "unset" AABB.

Note
If an unset AABB is added to another AABB, the result will be the other AABB.

◆ AABB() [2/4]

template<std::size_t N>
template<typename... Tail>
constexpr playrho::detail::AABB< N >::AABB ( std::enable_if_t< sizeof...(Tail)+1==N, LengthInterval >  head,
Tail...  tail 
)
inlineconstexprnoexcept

Initializing constructor.

Initializing constructor supporting construction by the same number of elements as this AABB template type is defined for.

Note
For example this enables a 2-dimensional AABB to be constructed as:
const auto aabb = AABB<2>{LengthInterval{1_m, 4_m}, LengthInterval{-3_m, 3_m}};

◆ AABB() [3/4]

template<std::size_t N>
constexpr playrho::detail::AABB< N >::AABB ( const Location  p)
inlineexplicitconstexprnoexcept

Initializing constructor for a single point.

Parameters
pPoint location to initialize this AABB with.
Postcondition
rangeX will have its min and max values both set to the given point's X value.
rangeY will have its min and max values both set to the given point's Y value.

◆ AABB() [4/4]

template<std::size_t N>
constexpr playrho::detail::AABB< N >::AABB ( const Location  a,
const Location  b 
)
inlineconstexprnoexcept

Initializing constructor for two points.

Parameters
aPoint location "A" to initialize this AABB with.
bPoint location "B" to initialize this AABB with.

Friends And Related Function Documentation

◆ Contains()

template<std::size_t N>
constexpr bool Contains ( const AABB< N > &  a,
const AABB< N > &  b 
)
related

Checks whether the first AABB fully contains the second AABB.

Whether the first AABB contains the entirety of the second AABB where containment is defined as being equal-to or within an AABB.

Note
The "unset" AABB is contained by all valid AABBs including the "unset" AABB itself.
Parameters
aAABB to test whether it contains the second AABB.
bAABB to test whether it's contained by the first AABB.

◆ GetPerimeter()

template<std::size_t N>
constexpr Length GetPerimeter ( const AABB< N > &  aabb)
related

Gets the perimeter length of the 2-dimensional AABB.

Precondition
The sizes of each of the AABB's ranges are representable.
Returns
Twice the sum of the width and height.
See also
https://en.wikipedia.org/wiki/Perimeter

◆ Include()

template<std::size_t N>
constexpr AABB< N > & Include ( AABB< N > &  var,
const AABB< N > &  val 
)
related

Includes the second AABB into the first one.

Note
If an unset AABB is added to the first AABB, the result will be the first AABB.
If the first AABB is unset and another AABB is added to it, the result will be the other AABB.

◆ operator!=()

template<std::size_t N>
constexpr bool operator!= ( const AABB< N > &  lhs,
const AABB< N > &  rhs 
)
related

Gets whether the two AABB objects are not equal.

Returns
true if the two values are not equal, false otherwise.

◆ operator==()

template<std::size_t N>
constexpr bool operator== ( const AABB< N > &  lhs,
const AABB< N > &  rhs 
)
related

Gets whether the two AABB objects are equal.

Returns
true if the two values are equal, false otherwise.

◆ TestOverlap()

template<std::size_t N>
constexpr bool TestOverlap ( const AABB< N > &  a,
const AABB< N > &  b 
)
related

Tests for overlap between two axis aligned bounding boxes.

Note
This function's complexity is constant.

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