2.10.0
Freundlich's C++ toolkit
Classes | Typedefs | Functions
fcppt.math.dim

Description

A class representing static n-dimensional dimensions.

Motivation

Conceptually, a dimension is very similar to an fcppt::math::vector::object. However, it is often useful to distinguish the two on the type level. For example, there are operations that apply to vectors (like the dot product) that make no sense in the context of a dimension. Conversely, there are operations like "take the area of the dimension" that make no sense for vectors. Also, the lower-dimensional getters for vector (x(),y(),z(),w()) have different names than the lower-dimensional getters for dim (w(),h(),d()).

Converting from and to vectors

To convert a dimension to a vector, use fcppt::math::dim::to_vector:

typedef
int,
3
>
dim3;
typedef
int,
3
>
vector3;
void
f()
{
dim3 const d(
1,
2,
3
);
vector3 const v(
d
)
);
std::cout << v << '\n';
}

Conversely, use fcppt::math::vector::to_dim to convert a vector to a dim:

void
g()
{
vector3 const v(
1,
2,
3
);
dim3 const d(
v
)
);
std::cout << d << '\n';
}

Header files

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

Classes

struct  fcppt::math::dim::has_dim< Dim, Size >
 Metafunction to check the dimension of a static dim. More...
 
struct  fcppt::math::dim::is_dim< T >
 Metafunction to test if a type is a dim type. More...
 
class  fcppt::math::dim::object< T, N, S >
 A class representing a static n-dimensional dimension. More...
 

Typedefs

template<typename T , fcppt::math::size_type N>
using fcppt::math::dim::static_ = fcppt::math::dim::object< T, N, fcppt::math::detail::static_storage< T, N > >
 Typedef helper for static dimsSee the introduction to fcppt::math::vector::object for more information on static dims (and on this class). More...
 

Functions

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_UNARY_TYPE(T, -), N > fcppt::math::dim::operator- (fcppt::math::dim::object< T, N, S > const &_left)
 Negates a dim. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L,+, R), N > fcppt::math::dim::operator+ (fcppt::math::dim::object< L, N, S1 > const &_left, fcppt::math::dim::object< R, N, S2 > const &_right)
 Adds a dim to a dim. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, -, R), N > fcppt::math::dim::operator- (fcppt::math::dim::object< L, N, S1 > const &_left, fcppt::math::dim::object< R, N, S2 > const &_right)
 Subtracts a dim from a dim. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N > fcppt::math::dim::operator* (fcppt::math::dim::object< L, N, S1 > const &_left, fcppt::math::dim::object< R, N, S2 > const &_right)
 Multiplies a dim by a dim. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::optional::object< fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L,/, R), N >> fcppt::math::dim::operator/ (fcppt::math::dim::object< L, N, S1 > const &_left, fcppt::math::dim::object< R, N, S2 > const &_right)
 Divides a dim by a dim. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N > fcppt::math::dim::operator* (fcppt::math::dim::object< L, N, S > const &_left, R const &_right)
 Multiplies a dim by a scalar on the right. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N > fcppt::math::dim::operator* (L const &_left, fcppt::math::dim::object< R, N, S > const &_right)
 Multiplies a dim by a scalar on the left. More...
 
template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::optional::object< fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L,/, R), N >> fcppt::math::dim::operator/ (fcppt::math::dim::object< L, N, S > const &_left, R const &_right)
 Divides a dim by a scalar. More...
 
template<fcppt::math::size_type Index, typename Dim >
fcppt::container::to_reference_type< std::remove_reference_t< Dim >> fcppt::math::dim::at (Dim &_value)
 Access an element using a compile-time constant. More...
 
template<typename T1 , typename T2 , fcppt::math::size_type N, typename S1 , typename S2 , typename Function >
fcppt::math::dim::static_< std::result_of_t< Function(T1, T2) >, N > fcppt::math::dim::binary_map (fcppt::math::dim::object< T1, N, S1 > const &_left, fcppt::math::dim::object< T2, N, S2 > const &_right, Function const &_function)
 Maps over two dims. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator== (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims for equality. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator!= (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims for disequality. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator< (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims lexicographically. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator> (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims lexicographically. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator<= (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims lexicographically. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator>= (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2)
 Compares two dims lexicographically. More...
 
template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::componentwise_equal (fcppt::math::dim::object< T, N, S1 > const &_v1, fcppt::math::dim::object< T, N, S2 > const &_v2, T const _epsilon)
 Compares two dims for equality using an epsilon. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::contents (fcppt::math::dim::object< T, N, S > const &_dim)
 Returns the area/volume of the dimension. More...
 
template<typename Dim >
Dim fcppt::math::dim::fill (fcppt::type_traits::value_type< Dim > const &_value)
 Constructs a static dim with all components set to a given value. More...
 
template<typename Dim , typename Function >
Dim fcppt::math::dim::init (Function const &_function)
 Initializes a dim. More...
 
template<typename T , fcppt::math::size_type N, typename S , typename Ch , typename Traits >
std::basic_istream< Ch, Traits > & fcppt::math::dim::operator>> (std::basic_istream< Ch, Traits > &_stream, fcppt::math::dim::object< T, N, S > &_dim)
 Reads a dim from s, expecting it in the format. More...
 
template<typename T , fcppt::math::size_type N, typename S >
bool fcppt::math::dim::is_quadratic (fcppt::math::dim::object< T, N, S > const &_dim)
 Checks if all elements of the dim are the same. More...
 
template<typename T , fcppt::math::size_type N, typename S , typename Function >
fcppt::math::dim::static_< std::result_of_t< Function(T) >, N > fcppt::math::dim::map (fcppt::math::dim::object< T, N, S > const &_value, Function const &_function)
 Maps over the elements of a dim. More...
 
template<typename Dest , typename T , fcppt::math::size_type N, typename S >
Dest fcppt::math::dim::narrow_cast (fcppt::math::dim::object< T, N, S > const &_src)
 Shortens a dim to a smaller dimension. More...
 
template<typename Dim >
fcppt::math::dim::static_< fcppt::type_traits::value_type< Dim >, Dim::static_size::value > fcppt::math::dim::null ()
 Returns the null dim. More...
 
template<typename T , fcppt::math::size_type N, typename S , typename Ch , typename Traits >
std::basic_ostream< Ch, Traits > & fcppt::math::dim::operator<< (std::basic_ostream< Ch, Traits > &_stream, fcppt::math::dim::object< T, N, S > const &_dim)
 Outputs a dim to s, in the format. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< T, N+1u > fcppt::math::dim::push_back (fcppt::math::dim::object< T, N, S > const &_dim, T const &_value)
 Pushes an element to the back of a dim. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::optional::object< fcppt::math::dim::static_< T, N >> fcppt::math::dim::sequence (fcppt::math::dim::object< fcppt::optional::object< T >, N, S > const &_value)
 Sequence for a dim. More...
 
template<typename Dest , typename Conv , typename T , fcppt::math::size_type N, typename S >
Dest fcppt::math::dim::structure_cast (fcppt::math::dim::object< T, N, S > const &_src)
 Converts a dim into a different dim of the same dimension. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< std::make_signed_t< T >, N > fcppt::math::dim::to_signed (fcppt::math::dim::object< T, N, S > const &_src)
 Converts a dim into a corresponding signed dim. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< std::make_unsigned_t< T >, N > fcppt::math::dim::to_unsigned (fcppt::math::dim::object< T, N, S > const &_src)
 Converts a dim into a corresponding unsigned dim. More...
 
template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::vector::static_< T, N > fcppt::math::dim::to_vector (fcppt::math::dim::object< T, N, S > const &_src)
 Converts a dim into a corresponding vector. More...
 

Typedef Documentation

◆ static_

template<typename T , fcppt::math::size_type N>
using fcppt::math::dim::static_ = typedef fcppt::math::dim::object< T, N, fcppt::math::detail::static_storage< T, N > >

Typedef helper for static dimsSee the introduction to fcppt::math::vector::object for more information on static dims (and on this class).

Function Documentation

◆ at()

template<fcppt::math::size_type Index, typename Dim >
fcppt::container::to_reference_type< std::remove_reference_t< Dim >> fcppt::math::dim::at ( Dim &  _value)
inline

Access an element using a compile-time constant.

Template Parameters
DimMust be an fcppt::math::dim::object.

◆ binary_map()

template<typename T1 , typename T2 , fcppt::math::size_type N, typename S1 , typename S2 , typename Function >
fcppt::math::dim::static_< std::result_of_t< Function( T1, T2 ) >, N> fcppt::math::dim::binary_map ( fcppt::math::dim::object< T1, N, S1 > const &  _left,
fcppt::math::dim::object< T2, N, S2 > const &  _right,
Function const &  _function 
)
inline

Maps over two dims.

◆ componentwise_equal()

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

Compares two dims for equality using an epsilon.

◆ contents()

template<typename T , fcppt::math::size_type N, typename S >
T fcppt::math::dim::contents ( fcppt::math::dim::object< T, N, S > const &  _dim)

Returns the area/volume of the dimension.

This is equal to the product of all components of the dimension.

◆ fill()

template<typename Dim >
Dim fcppt::math::dim::fill ( fcppt::type_traits::value_type< Dim > const &  _value)

Constructs a static dim with all components set to a given value.

Template Parameters
DimMust be a dim
Parameters
_valueThe value to fill the dim with

◆ init()

template<typename Dim , typename Function >
Dim fcppt::math::dim::init ( Function const &  _function)
inline

Initializes a dim.

Calls _function for every index of the dim.

Template Parameters
DimMust be a dim
FunctionMust be a function of type Dim::value_type (Dim::size_type)

◆ is_quadratic()

template<typename T , fcppt::math::size_type N, typename S >
bool fcppt::math::dim::is_quadratic ( fcppt::math::dim::object< T, N, S > const &  _dim)

Checks if all elements of the dim are the same.

Parameters
_dimThe dimension to check

◆ map()

template<typename T , fcppt::math::size_type N, typename S , typename Function >
fcppt::math::dim::static_< std::result_of_t< Function( T ) >, N> fcppt::math::dim::map ( fcppt::math::dim::object< T, N, S > const &  _value,
Function const &  _function 
)
inline

Maps over the elements of a dim.

◆ narrow_cast()

template<typename Dest , typename T , fcppt::math::size_type N, typename S >
Dest fcppt::math::dim::narrow_cast ( fcppt::math::dim::object< T, N, S > const &  _src)
inline

Shortens a dim to a smaller dimension.

◆ null()

template<typename Dim >
fcppt::math::dim::static_< fcppt::type_traits::value_type< Dim >, Dim::static_size::value> fcppt::math::dim::null ( )

Returns the null dim.

◆ operator!=()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator!= ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims for disequality.

◆ operator*() [1/3]

template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N> fcppt::math::dim::operator* ( fcppt::math::dim::object< L, N, S1 > const &  _left,
fcppt::math::dim::object< R, N, S2 > const &  _right 
)
inline

Multiplies a dim by a dim.

◆ operator*() [2/3]

template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N> fcppt::math::dim::operator* ( fcppt::math::dim::object< L, N, S > const &  _left,
R const &  _right 
)
inline

Multiplies a dim by a scalar on the right.

◆ operator*() [3/3]

template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, *, R), N> fcppt::math::dim::operator* ( L const &  _left,
fcppt::math::dim::object< R, N, S > const &  _right 
)
inline

Multiplies a dim by a scalar on the left.

◆ operator+()

template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, +, R), N> fcppt::math::dim::operator+ ( fcppt::math::dim::object< L, N, S1 > const &  _left,
fcppt::math::dim::object< R, N, S2 > const &  _right 
)
inline

Adds a dim to a dim.

◆ operator-() [1/2]

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_UNARY_TYPE(T, -), N> fcppt::math::dim::operator- ( fcppt::math::dim::object< T, N, S > const &  _left)
inline

Negates a dim.

◆ operator-() [2/2]

template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, -, R), N> fcppt::math::dim::operator- ( fcppt::math::dim::object< L, N, S1 > const &  _left,
fcppt::math::dim::object< R, N, S2 > const &  _right 
)
inline

Subtracts a dim from a dim.

◆ operator/() [1/2]

template<typename L , typename R , fcppt::math::size_type N, typename S1 , typename S2 >
fcppt::optional::object< fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, /, R), N >> fcppt::math::dim::operator/ ( fcppt::math::dim::object< L, N, S1 > const &  _left,
fcppt::math::dim::object< R, N, S2 > const &  _right 
)
inline

Divides a dim by a dim.

◆ operator/() [2/2]

template<typename L , typename R , fcppt::math::size_type N, typename S >
fcppt::optional::object< fcppt::math::dim::static_< FCPPT_MATH_DETAIL_BINARY_TYPE(L, /, R), N >> fcppt::math::dim::operator/ ( fcppt::math::dim::object< L, N, S > const &  _left,
R const &  _right 
)
inline

Divides a dim by a scalar.

◆ operator<()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator< ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims lexicographically.

◆ operator<<()

template<typename T , fcppt::math::size_type N, typename S , typename Ch , typename Traits >
std::basic_ostream< Ch, Traits>& fcppt::math::dim::operator<< ( std::basic_ostream< Ch, Traits > &  _stream,
fcppt::math::dim::object< T, N, S > const &  _dim 
)
inline

Outputs a dim to s, in the format.

(a_1,a_2,...)

where a_i are the dim's components.

◆ operator<=()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator<= ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims lexicographically.

◆ operator==()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator== ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims for equality.

◆ operator>()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator> ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims lexicographically.

◆ operator>=()

template<typename T , fcppt::math::size_type N, typename S1 , typename S2 >
bool fcppt::math::dim::operator>= ( fcppt::math::dim::object< T, N, S1 > const &  _v1,
fcppt::math::dim::object< T, N, S2 > const &  _v2 
)
inline

Compares two dims lexicographically.

◆ operator>>()

template<typename T , fcppt::math::size_type N, typename S , typename Ch , typename Traits >
std::basic_istream< Ch, Traits>& fcppt::math::dim::operator>> ( std::basic_istream< Ch, Traits > &  _stream,
fcppt::math::dim::object< T, N, S > &  _dim 
)
inline

Reads a dim from s, expecting it in the format.

(a_1,a_2,...)

where a_i are the components

◆ push_back()

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< T, N + 1u> fcppt::math::dim::push_back ( fcppt::math::dim::object< T, N, S > const &  _dim,
T const &  _value 
)
inline

Pushes an element to the back of a dim.

◆ sequence()

template<typename T , fcppt::math::size_type N, typename S >
fcppt::optional::object< fcppt::math::dim::static_< T, N >> fcppt::math::dim::sequence ( fcppt::math::dim::object< fcppt::optional::object< T >, N, S > const &  _value)
inline

Sequence for a dim.

Uses fcppt::optional::sequence.

◆ structure_cast()

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

Converts a dim into a different dim of the same dimension.

Template Parameters
DestThe destination dim type (not its value type!)
Convthe converter to use for each element
NThe source dim's dimension
TThe source dim's value_type
SThe source dim's storage type
Parameters
_srcThe dim to cast

See the introduction to fcppt::math::vector::object for more information on this function (and dim/vector in general).

◆ to_signed()

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< std::make_signed_t< T >, N> fcppt::math::dim::to_signed ( fcppt::math::dim::object< T, N, S > const &  _src)
inline

Converts a dim into a corresponding signed dim.

◆ to_unsigned()

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::dim::static_< std::make_unsigned_t< T >, N> fcppt::math::dim::to_unsigned ( fcppt::math::dim::object< T, N, S > const &  _src)
inline

Converts a dim into a corresponding unsigned dim.

◆ to_vector()

template<typename T , fcppt::math::size_type N, typename S >
fcppt::math::vector::static_< T, N> fcppt::math::dim::to_vector ( fcppt::math::dim::object< T, N, S > const &  _src)
inline

Converts a dim into a corresponding vector.