4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
fcppt.math.box

Description

A class representing axis-aligned rectangles, boxes, hypercubes, ...

Overview

A box is defined by two n-dimensional points. For example, a rectangle has a dimension of 2. The two points give a minimum bound and a non-inclusive maximum bound. More precisely, let a box be given by p = (x_1,...,x_n) and q = (y_1,...,y_n). A point r = (z_1,...,z_n) is inside the box if for all 1 <= i <= n it holds that x_i <= z_i < y_i. This representation makes it easy to specify empty boxes: For example, a rectangle defined by (1,2), (1,2) is empty.

Constructors and getters

A box can be constructed in two ways:

There are getters and setters for both representations as well:

std::cout << box.pos() << ", " << box.max() << '\n';
std::cout << box.pos() << ", " << box.size() << '\n';

Header files

Header file Description
object_fwd.hpp Contains fcppt::math::box::object's declaration.
object_decl.hpp Contains fcppt::math::box::object's definition.
object_impl.hpp Contains the definition of fcppt::math::box::object's member functions.
object.hpp Includes object_fwd.hpp, object_decl.hpp and object_impl.hpp.
comparison.hpp Contains all comparison operators.
output.hpp Contains operator<<.

Classes

struct  fcppt::math::box::has_dim< Box, Dim >
 Metafunction to check the dimension of a box. More...
 
struct  fcppt::math::box::is_box< T >
 Metafunction to test if a type is a box type. More...
 
class  fcppt::math::box::object< T, N >
 A class representing axis aligned boxes, cubes, hypercubes, ... More...
 

Typedefs

template<typename T >
using fcppt::math::box::rect = fcppt::math::box::object<T, 2>
 Typedefs a two dimensional box (a rect)
 

Functions

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N >::vector fcppt::math::box::center (fcppt::math::box::object< T, N > const &_box)
 Returns the center of the box.
 
template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::operator== (fcppt::math::box::object< T, N > const &_a, fcppt::math::box::object< T, N > const &_b)
 Compare two boxes componentwise using value_type's operator==
 
template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::operator!= (fcppt::math::box::object< T, N > const &_a, fcppt::math::box::object< T, N > const &_b)
 Compare two boxes componentwise using value_type's operator!=
 
template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::componentwise_equal (fcppt::math::box::object< T, N > const &_v1, fcppt::math::box::object< T, N > const &_v2, T const _epsilon)
 Compare two boxes component-wise using an epsilon.
 
template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::contains (fcppt::math::box::object< T, N > const &_outer, fcppt::math::box::object< T, N > const &_inner)
 Test if one box is completely inside another box.
 
template<typename T , typename S , fcppt::math::size_type N>
bool fcppt::math::box::contains_point (fcppt::math::box::object< T, N > const &_box, fcppt::math::vector::object< T, N, S > const &_point)
 Test if a box contains a point.
 
template<typename T , fcppt::math::size_type N>
fcppt::array::object< fcppt::math::vector::static_< T, N >, fcppt::math::power_of_2< std::size_t >(N)> fcppt::math::box::corner_points (fcppt::math::box::object< T, N > const &_box)
 Returns the 2^N corner points (vertices) of the given box.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::vector::static_< T, N > fcppt::math::box::distance (fcppt::math::box::object< T, N > const &_box1, fcppt::math::box::object< T, N > const &_box2)
 Calculates the interval distance between all box dimensions.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::extend_bounding_box (fcppt::math::box::object< T, N > const _box, typename fcppt::math::box::object< T, N >::vector const _pos)
 Extend a box to fit a point in it.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::extend_bounding_box (fcppt::math::box::object< T, N > const &_box1, fcppt::math::box::object< T, N > const &_box2)
 Take the bounding box of two boxes.
 
template<typename Box , typename Function >
Box fcppt::math::box::init_dim (Function const &_function)
 Initializes a box from pairs of positions and sizes.
 
template<typename Box , typename Function >
Box fcppt::math::box::init_max (Function const &_function)
 Initializes a box from pairs of min and max positions.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::intersection (fcppt::math::box::object< T, N > const &_a, fcppt::math::box::object< T, N > const &_b)
 Calculates the intersection of two boxes (which is, again, a box)
 
template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::intersects (fcppt::math::box::object< T, N > const &_a, fcppt::math::box::object< T, N > const &_b)
 Tests if two boxes intersect.
 
template<fcppt::math::size_type Index, typename T , fcppt::math::size_type N>
fcppt::tuple::object< T, T > fcppt::math::box::interval (fcppt::math::box::object< T, N > const &_box)
 Creates an interval from a box.
 
template<typename Box >
Box fcppt::math::box::null ()
 Returns the null box.
 
template<typename T , fcppt::math::size_type N, typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::math::box::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::math::box::object< T, N > const &_box)
 Outputs a box to a basic_ostream.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::shrink (fcppt::math::box::object< T, N > const &_box, typename fcppt::math::box::object< T, N >::vector const &_absolute_values)
 Shrink a box towards its center using an absolute value.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::stretch_absolute (fcppt::math::box::object< T, N > const &_box, typename fcppt::math::box::object< T, N >::vector const &_absolute_values)
 Stretch a box around its center using an absolute value.
 
template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::stretch_relative (fcppt::math::box::object< T, N > const &_box, typename fcppt::math::box::object< T, N >::vector const &_factors)
 Stretch a box around its center by a given factor.
 
template<typename Dest , typename Conv , typename T , fcppt::math::size_type N>
Dest fcppt::math::box::structure_cast (fcppt::math::box::object< T, N > const &_src)
 Converts a box into a different box of the same dimension using Conv.
 

Typedef Documentation

◆ rect

template<typename T >
using fcppt::math::box::rect = fcppt::math::box::object<T, 2>

Typedefs a two dimensional box (a rect)

Template Parameters
TThe box's value_type

Function Documentation

◆ center()

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N >::vector fcppt::math::box::center ( fcppt::math::box::object< T, N > const & _box)

Returns the center of the box.

Template Parameters
NThe box's dimension
TThe box's value_type

Note that this might not calculate the box's "real" center, since the calculation is performed using T, which might be integral.

◆ componentwise_equal()

template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::componentwise_equal ( fcppt::math::box::object< T, N > const & _v1,
fcppt::math::box::object< T, N > const & _v2,
T const _epsilon )
inline

Compare two boxes component-wise using an epsilon.

Componentwise in this context means: Compare the positions and the sizes component-wise. For each component of the position and the size, check if the components differ by more than the specified epsilon. If so, return false.

◆ contains()

template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::contains ( fcppt::math::box::object< T, N > const & _outer,
fcppt::math::box::object< T, N > const & _inner )
inline

Test if one box is completely inside another box.

Parameters
_outerThe outer (larger) box
_innerThe inner (smaller) box

◆ contains_point()

template<typename T , typename S , fcppt::math::size_type N>
bool fcppt::math::box::contains_point ( fcppt::math::box::object< T, N > const & _box,
fcppt::math::vector::object< T, N, S > const & _point )
inline

Test if a box contains a point.

◆ corner_points()

template<typename T , fcppt::math::size_type N>
fcppt::array::object< fcppt::math::vector::static_< T, N >, fcppt::math::power_of_2< std::size_t >(N)> fcppt::math::box::corner_points ( fcppt::math::box::object< T, N > const & _box)

Returns the 2^N corner points (vertices) of the given box.

◆ distance()

template<typename T , fcppt::math::size_type N>
fcppt::math::vector::static_< T, N > fcppt::math::box::distance ( fcppt::math::box::object< T, N > const & _box1,
fcppt::math::box::object< T, N > const & _box2 )

Calculates the interval distance between all box dimensions.

◆ extend_bounding_box() [1/2]

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::extend_bounding_box ( fcppt::math::box::object< T, N > const & _box1,
fcppt::math::box::object< T, N > const & _box2 )

Take the bounding box of two boxes.

◆ extend_bounding_box() [2/2]

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::extend_bounding_box ( fcppt::math::box::object< T, N > const _box,
typename fcppt::math::box::object< T, N >::vector const _pos )

Extend a box to fit a point in it.

The result will either be the same box (if the point is contained in the box) or a box that's just big enough to hold the given point.

◆ init_dim()

template<typename Box , typename Function >
Box fcppt::math::box::init_dim ( Function const & _function)
inline

Initializes a box from pairs of positions and sizes.

Initializes an object of type Box by calling _function for every index. The result _function must be a tuple where the first element is the position and the second element is the size.

Template Parameters
BoxMust be a box
FunctionA (polymorphic) function of type fcppt::tuple::object<Box::value_type, Box::value_type> (Index)

◆ init_max()

template<typename Box , typename Function >
Box fcppt::math::box::init_max ( Function const & _function)
inline

Initializes a box from pairs of min and max positions.

Initializes an object of type Box by calling _function for every index. The result _function must be a fcppt::tuple::object where the first element is the min position and the second element is the max position.

Template Parameters
BoxMust be a box
FunctionA (polymorphic) function of type fcppt::tuple::object<Box::value_type,Box::value_type> (Index)

◆ intersection()

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::intersection ( fcppt::math::box::object< T, N > const & _a,
fcppt::math::box::object< T, N > const & _b )

Calculates the intersection of two boxes (which is, again, a box)

If there is no intersection, the null box will be returned.

◆ intersects()

template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::intersects ( fcppt::math::box::object< T, N > const & _a,
fcppt::math::box::object< T, N > const & _b )
inline

Tests if two boxes intersect.

◆ interval()

template<fcppt::math::size_type Index, typename T , fcppt::math::size_type N>
fcppt::tuple::object< T, T > fcppt::math::box::interval ( fcppt::math::box::object< T, N > const & _box)
inline

Creates an interval from a box.

◆ null()

template<typename Box >
Box fcppt::math::box::null ( )
inline

Returns the null box.

◆ operator!=()

template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::operator!= ( fcppt::math::box::object< T, N > const & _a,
fcppt::math::box::object< T, N > const & _b )
inline

Compare two boxes componentwise using value_type's operator!=

◆ operator<<()

template<typename T , fcppt::math::size_type N, typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::math::box::operator<< ( std::basic_ostream< Ch, Traits > & _stream,
fcppt::math::box::object< T, N > const & _box )

Outputs a box to a basic_ostream.

Template Parameters
NThe box's dimension
TThe box's value_type

The format will be

(position,size)

◆ operator==()

template<typename T , fcppt::math::size_type N>
bool fcppt::math::box::operator== ( fcppt::math::box::object< T, N > const & _a,
fcppt::math::box::object< T, N > const & _b )
inline

Compare two boxes componentwise using value_type's operator==

◆ shrink()

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::shrink ( fcppt::math::box::object< T, N > const & _box,
typename fcppt::math::box::object< T, N >::vector const & _absolute_values )

Shrink a box towards its center using an absolute value.

◆ stretch_absolute()

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::stretch_absolute ( fcppt::math::box::object< T, N > const & _box,
typename fcppt::math::box::object< T, N >::vector const & _absolute_values )

Stretch a box around its center using an absolute value.

◆ stretch_relative()

template<typename T , fcppt::math::size_type N>
fcppt::math::box::object< T, N > fcppt::math::box::stretch_relative ( fcppt::math::box::object< T, N > const & _box,
typename fcppt::math::box::object< T, N >::vector const & _factors )

Stretch a box around its center by a given factor.

◆ structure_cast()

template<typename Dest , typename Conv , typename T , fcppt::math::size_type N>
Dest fcppt::math::box::structure_cast ( fcppt::math::box::object< T, N > const & _src)

Converts a box into a different box of the same dimension using Conv.

Template Parameters
TThe original box's value_type
DestThe destination box's value_type
NThe box's dimension