Gamedev Framework (gf)  0.14.0
A C++14 framework for 2D games
Public Member Functions | Public Attributes | Related Functions | List of all members
gf::Box< T, N > Struct Template Reference

A multi-dimensional box. More...

#include <gf/Box.h>

Public Member Functions

constexpr Box () noexcept
 Default constructor. More...
 
constexpr Box (Vector< T, N > p0, Vector< T, N > p1) noexcept
 Constructor with two points. More...
 
constexpr Box (const T(&p0)[N], const T(&p1)[N]) noexcept
 Constructor with two points (as arrays) More...
 
constexpr Box (Vector< T, N > p) noexcept
 Constructor with one point. More...
 
constexpr Vector< T, NgetPosition () const noexcept
 Get the position of the box. More...
 
constexpr Vector< T, NgetSize () const noexcept
 Get the size of the box. More...
 
constexpr bool isEmpty () const noexcept
 Check if the box is empty. More...
 
constexpr Vector< T, NgetCenter () const noexcept
 Get the center of the box. More...
 
constexpr bool contains (Vector< T, N > point) const noexcept
 Check if a point is inside the box. More...
 
constexpr bool contains (const Box< T, N > &other) const noexcept
 Check if a box is totally inside the box. More...
 
constexpr bool intersects (const Box< T, N > &other) const noexcept
 Check if two boxes interset. More...
 
constexpr bool intersects (const Box< T, N > &other, Box< T, N > &result) const noexcept
 Check if two boxes interset and get the intersetion box. More...
 
constexpr Box< T, NgetIntersection (const Box< T, N > &other) const noexcept
 Compute the intersection of two boxes. More...
 
constexpr T getIntersectionVolume (const Box< T, N > &other) const noexcept
 Get the volume of the intersection. More...
 
constexpr T getIntersectionExtentLength (const Box< T, N > &other) const noexcept
 Get the extent length of the intersection. More...
 
constexpr void extend (const T(&point)[N]) noexcept
 Extend the box with a point (as array) More...
 
constexpr void extend (Vector< T, N > point) noexcept
 Extend the box with a point. More...
 
constexpr void extend (const Box< T, N > &other) noexcept
 Extend the box with a box. More...
 
constexpr Box< T, NgetExtended (const Box< T, N > &other) const noexcept
 Get the box extended by another box. More...
 
constexpr T getVolume () const noexcept
 Get the volume of the box. More...
 
constexpr T getExtentLength () const noexcept
 Get the extent length of the box. More...
 
constexpr T getMinimumEdge () const noexcept
 Get the minimum edge of the box. More...
 
constexpr Box< T, 2 > grow (T value) const noexcept
 Grow the box. More...
 
constexpr Box< T, 2 > shrink (T value) const noexcept
 Shrink the box. More...
 
constexpr void normalize () noexcept
 Ensures that min coordinates are less than max coordinates. More...
 

Public Attributes

Vector< T, Nmin
 The minimum point of the box. More...
 
Vector< T, Nmax
 The maximum point of the box. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T , std::size_t N>
constexpr bool operator== (const Box< T, N > &lhs, const Box< T, N > &rhs)
 Equality operator. More...
 

Detailed Description

template<typename T, std::size_t N>
struct gf::Box< T, N >

A multi-dimensional box.

A box is defined by its minimum coordinates (included) and its maximum coordinates (excluded).

See also
gf::Rect

Constructor & Destructor Documentation

◆ Box() [1/4]

template<typename T, std::size_t N>
constexpr gf::Box< T, N >::Box ( )
inlinenoexcept

Default constructor.

◆ Box() [2/4]

template<typename T, std::size_t N>
constexpr gf::Box< T, N >::Box ( Vector< T, N p0,
Vector< T, N p1 
)
inlinenoexcept

Constructor with two points.

Parameters
p0The first point in the box
p1The second point in the box

◆ Box() [3/4]

template<typename T, std::size_t N>
constexpr gf::Box< T, N >::Box ( const T(&)  p0[N],
const T(&)  p1[N] 
)
inlinenoexcept

Constructor with two points (as arrays)

Parameters
p0The first point in the box
p1The second point in the box

◆ Box() [4/4]

template<typename T, std::size_t N>
constexpr gf::Box< T, N >::Box ( Vector< T, N p)
inlineexplicitnoexcept

Constructor with one point.

Parameters
pThe point in the box

Member Function Documentation

◆ contains() [1/2]

template<typename T, std::size_t N>
constexpr bool gf::Box< T, N >::contains ( Vector< T, N point) const
inlinenoexcept

Check if a point is inside the box.

Parameters
pointThe point to test
Returns
True if the point is inside the box

◆ contains() [2/2]

template<typename T, std::size_t N>
constexpr bool gf::Box< T, N >::contains ( const Box< T, N > &  other) const
inlinenoexcept

Check if a box is totally inside the box.

Parameters
otherAnother box to test
Returns
True if the tested box is inside the current box

◆ extend() [1/3]

template<typename T, std::size_t N>
constexpr void gf::Box< T, N >::extend ( const T(&)  point[N])
inlinenoexcept

Extend the box with a point (as array)

Parameters
pointThe point of extension

◆ extend() [2/3]

template<typename T, std::size_t N>
constexpr void gf::Box< T, N >::extend ( Vector< T, N point)
inlinenoexcept

Extend the box with a point.

Parameters
pointThe point of extension

◆ extend() [3/3]

template<typename T, std::size_t N>
constexpr void gf::Box< T, N >::extend ( const Box< T, N > &  other)
inlinenoexcept

Extend the box with a box.

Parameters
otherThe box of extension

◆ getCenter()

template<typename T, std::size_t N>
constexpr Vector<T, N> gf::Box< T, N >::getCenter ( ) const
inlinenoexcept

Get the center of the box.

Returns
The center of the box

◆ getExtended()

template<typename T, std::size_t N>
constexpr Box<T, N> gf::Box< T, N >::getExtended ( const Box< T, N > &  other) const
inlinenoexcept

Get the box extended by another box.

Parameters
otherThe box of extension

◆ getExtentLength()

template<typename T, std::size_t N>
constexpr T gf::Box< T, N >::getExtentLength ( ) const
inlinenoexcept

Get the extent length of the box.

Returns
The extent length of the box

◆ getIntersection()

template<typename T, std::size_t N>
constexpr Box<T, N> gf::Box< T, N >::getIntersection ( const Box< T, N > &  other) const
inlinenoexcept

Compute the intersection of two boxes.

Parameters
otherAnother box to test
Returns
The result of the intersection

◆ getIntersectionExtentLength()

template<typename T, std::size_t N>
constexpr T gf::Box< T, N >::getIntersectionExtentLength ( const Box< T, N > &  other) const
inlinenoexcept

Get the extent length of the intersection.

Parameters
otherAnother box to test
Returns
The extent length of the intersection or 0 in case there is no intersection

◆ getIntersectionVolume()

template<typename T, std::size_t N>
constexpr T gf::Box< T, N >::getIntersectionVolume ( const Box< T, N > &  other) const
inlinenoexcept

Get the volume of the intersection.

Parameters
otherAnother box to test
Returns
The volume of the intersection or 0 in case there is no intersection

◆ getMinimumEdge()

template<typename T, std::size_t N>
constexpr T gf::Box< T, N >::getMinimumEdge ( ) const
inlinenoexcept

Get the minimum edge of the box.

Returns
The length of the minimum edge of the box

◆ getPosition()

template<typename T, std::size_t N>
constexpr Vector<T, N> gf::Box< T, N >::getPosition ( ) const
inlinenoexcept

Get the position of the box.

This is the same as min.

Returns
The position of the box

◆ getSize()

template<typename T, std::size_t N>
constexpr Vector<T, N> gf::Box< T, N >::getSize ( ) const
inlinenoexcept

Get the size of the box.

Returns
The size of the box

◆ getVolume()

template<typename T, std::size_t N>
constexpr T gf::Box< T, N >::getVolume ( ) const
inlinenoexcept

Get the volume of the box.

Returns
The volume of the box

◆ grow()

template<typename T, std::size_t N>
constexpr Box<T, 2> gf::Box< T, N >::grow ( T  value) const
inlinenoexcept

Grow the box.

Parameters
valueThe amount to grow
Returns
A new extended box
See also
shrink()

◆ intersects() [1/2]

template<typename T, std::size_t N>
constexpr bool gf::Box< T, N >::intersects ( const Box< T, N > &  other) const
inlinenoexcept

Check if two boxes interset.

Parameters
otherAnother box to test
Returns
True if the two boxes interset

◆ intersects() [2/2]

template<typename T, std::size_t N>
constexpr bool gf::Box< T, N >::intersects ( const Box< T, N > &  other,
Box< T, N > &  result 
) const
inlinenoexcept

Check if two boxes interset and get the intersetion box.

Parameters
otherAnother box to test
resultA reference to put the result of the intersection (in case there is any)
Returns
True if the two boxes interset

◆ isEmpty()

template<typename T, std::size_t N>
constexpr bool gf::Box< T, N >::isEmpty ( ) const
inlinenoexcept

Check if the box is empty.

Returns
True if the box is empty

◆ normalize()

template<typename T, std::size_t N>
constexpr void gf::Box< T, N >::normalize ( )
inlinenoexcept

Ensures that min coordinates are less than max coordinates.

◆ shrink()

template<typename T, std::size_t N>
constexpr Box<T, 2> gf::Box< T, N >::shrink ( T  value) const
inlinenoexcept

Shrink the box.

Parameters
valueThe amount to shrink
Returns
A new shrinked box
See also
grow()

Friends And Related Function Documentation

◆ operator==()

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

Equality operator.

Member Data Documentation

◆ max

template<typename T, std::size_t N>
Vector<T, N> gf::Box< T, N >::max

The maximum point of the box.

◆ min

template<typename T, std::size_t N>
Vector<T, N> gf::Box< T, N >::min

The minimum point of the box.