Mathter
A configurable 3D math library for game developers.
Classes | Public Member Functions | List of all members
mathter::Vector< T, Dim, Packed > Class Template Reference

Represents a vector in N-dimensional space. More...

#include <Definitions.hpp>

+ Inheritance diagram for mathter::Vector< T, Dim, Packed >:

Public Member Functions

constexpr int Dimension () const
 Returns the number of dimensions of the vector. More...
 
 Vector ()=default
 Constructs the vector. Does NOT zero-initialize elements. More...
 
 Vector (const Vector &)=default
 
Vectoroperator= (const Vector &)=default
 
 Vector (T all)
 Sets all elements to the same value. More...
 
template<class U >
 Vector (const U *data)
 Constructs the vector from an array of elements. More...
 
template<class T2 , bool Packed2, class = typename std::enable_if<(Dim >= 2>
 Vector (const Vector< T2, Dim - 1, Packed2 > &rhs)
 Creates a homogeneous vector by appending a 1. More...
 
template<class T2 , bool Packed2>
 Vector (const Vector< T2, Dim+1, Packed2 > &rhs)
 Truncates last coordinate of homogenous vector to create non-homogeneous. More...
 
template<class H1 , class H2 , class... Scalars, typename std::enable_if< traits::All< traits::IsScalar, H1, H2, Scalars... >::value &&traits::SumDimensions< H1, H2, Scalars... >::value==Dim, int >::type = 0>
 Vector (H1 h1, H2 h2, Scalars... scalars)
 Initializes the vector to the given scalar elements. More...
 
template<class H1 , class... Mixed, typename std::enable_if< traits::Any< traits::IsVectorOrSwizzle, H1, Mixed... >::value &&traits::SumDimensions< H1, Mixed... >::value==Dim, int >::type = 0>
 Vector (const H1 &h1, const Mixed &... mixed)
 Initializes the vector by concatenating given scalar and vector arguments. More...
 
template<class... Scalars, typename std::enable_if<((sizeof...(Scalars) > 1>
VectorSet (Scalars... scalars)
 Sets the vector's elements to the given scalars. More...
 
template<class... Mixed, typename std::enable_if<(sizeof...(Mixed) > 0>
VectorSet (const Mixed &... mixed)
 Sets the vector's elements by concatenating given scalar and vector arguments. More...
 
operator[] (int idx) const
 Returns the nth element of the vector. More...
 
T & operator[] (int idx)
 Returns the nth element of the vector. More...
 
operator() (int idx) const
 Returns the nth element of the vector. More...
 
T & operator() (int idx)
 Returns the nth element of the vector. More...
 
const T * cbegin () const
 Returns an iterator to the first element. More...
 
const T * begin () const
 Returns an iterator to the first element. More...
 
T * begin ()
 Returns an iterator to the first element. More...
 
const T * cend () const
 Returns an iterator to the end of the vector (works like STL). More...
 
const T * end () const
 Returns an iterator to the end of the vector (works like STL). More...
 
T * end ()
 Returns an iterator to the end of the vector (works like STL). More...
 
const T * Data () const
 Returns a pointer to the underlying array of elements. More...
 
T * Data ()
 Returns a pointer to the underlying array of elements. More...
 

Detailed Description

template<class T, int Dim, bool Packed = false>
class mathter::Vector< T, Dim, Packed >

Represents a vector in N-dimensional space.

Template Parameters
TThe scalar type on which the vector is based. You can use builtin floating point or integer types. User-defined types and std::complex may also work, but are not yet officially supported.
DimThe dimension of the vector-space. Must be a positive integer. Dynamically sized vectors are not supported yet, but you'll have to use mathter::DYNAMIC to define dynamically sized vectors.
PackedSet to true to tightly pack vector elements and avoid padding of the vector struct. Disables SIMD optimizations.

There is not much extraordinary to vectors, they work as you would expect.

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<class T, int Dim, bool Packed = false>
mathter::Vector< T, Dim, Packed >::Vector ( )
default

Constructs the vector. Does NOT zero-initialize elements.

◆ Vector() [2/8]

template<class T, int Dim, bool Packed = false>
mathter::Vector< T, Dim, Packed >::Vector ( const Vector< T, Dim, Packed > &  )
default

◆ Vector() [3/8]

template<class T, int Dim, bool Packed = false>
mathter::Vector< T, Dim, Packed >::Vector ( all)
inlineexplicit

Sets all elements to the same value.

◆ Vector() [4/8]

template<class T, int Dim, bool Packed = false>
template<class U >
mathter::Vector< T, Dim, Packed >::Vector ( const U *  data)
inlineexplicit

Constructs the vector from an array of elements.

The number of elements must be the same as the vector's dimension.

◆ Vector() [5/8]

template<class T, int Dim, bool Packed = false>
template<class T2 , bool Packed2, class = typename std::enable_if<(Dim >= 2>
mathter::Vector< T, Dim, Packed >::Vector ( const Vector< T2, Dim - 1, Packed2 > &  rhs)
inlineexplicit

Creates a homogeneous vector by appending a 1.

◆ Vector() [6/8]

template<class T, int Dim, bool Packed = false>
template<class T2 , bool Packed2>
mathter::Vector< T, Dim, Packed >::Vector ( const Vector< T2, Dim+1, Packed2 > &  rhs)
inlineexplicit

Truncates last coordinate of homogenous vector to create non-homogeneous.

◆ Vector() [7/8]

template<class T, int Dim, bool Packed = false>
template<class H1 , class H2 , class... Scalars, typename std::enable_if< traits::All< traits::IsScalar, H1, H2, Scalars... >::value &&traits::SumDimensions< H1, H2, Scalars... >::value==Dim, int >::type = 0>
mathter::Vector< T, Dim, Packed >::Vector ( H1  h1,
H2  h2,
Scalars...  scalars 
)
inline

Initializes the vector to the given scalar elements.

Number of arguments must equal vector dimension. Types of arguments may differ from vector's underlying type, in which case explicit cast is performed.

◆ Vector() [8/8]

template<class T, int Dim, bool Packed = false>
template<class H1 , class... Mixed, typename std::enable_if< traits::Any< traits::IsVectorOrSwizzle, H1, Mixed... >::value &&traits::SumDimensions< H1, Mixed... >::value==Dim, int >::type = 0>
mathter::Vector< T, Dim, Packed >::Vector ( const H1 &  h1,
const Mixed &...  mixed 
)
inline

Initializes the vector by concatenating given scalar and vector arguments.

Sum of the dimension of arguments must equal vector dimension. Types of arguments may differ from vector's underlying type, in which case explicit cast is performed.

Member Function Documentation

◆ begin() [1/2]

template<class T, int Dim, bool Packed = false>
const T* mathter::Vector< T, Dim, Packed >::begin ( ) const
inline

Returns an iterator to the first element.

◆ begin() [2/2]

template<class T, int Dim, bool Packed = false>
T* mathter::Vector< T, Dim, Packed >::begin ( )
inline

Returns an iterator to the first element.

◆ cbegin()

template<class T, int Dim, bool Packed = false>
const T* mathter::Vector< T, Dim, Packed >::cbegin ( ) const
inline

Returns an iterator to the first element.

◆ cend()

template<class T, int Dim, bool Packed = false>
const T* mathter::Vector< T, Dim, Packed >::cend ( ) const
inline

Returns an iterator to the end of the vector (works like STL).

◆ Data() [1/2]

template<class T, int Dim, bool Packed = false>
const T* mathter::Vector< T, Dim, Packed >::Data ( ) const
inline

Returns a pointer to the underlying array of elements.

◆ Data() [2/2]

template<class T, int Dim, bool Packed = false>
T* mathter::Vector< T, Dim, Packed >::Data ( )
inline

Returns a pointer to the underlying array of elements.

◆ Dimension()

template<class T, int Dim, bool Packed = false>
constexpr int mathter::Vector< T, Dim, Packed >::Dimension ( ) const
inline

Returns the number of dimensions of the vector.

◆ end() [1/2]

template<class T, int Dim, bool Packed = false>
const T* mathter::Vector< T, Dim, Packed >::end ( ) const
inline

Returns an iterator to the end of the vector (works like STL).

◆ end() [2/2]

template<class T, int Dim, bool Packed = false>
T* mathter::Vector< T, Dim, Packed >::end ( )
inline

Returns an iterator to the end of the vector (works like STL).

◆ operator()() [1/2]

template<class T, int Dim, bool Packed = false>
T mathter::Vector< T, Dim, Packed >::operator() ( int  idx) const
inline

Returns the nth element of the vector.

◆ operator()() [2/2]

template<class T, int Dim, bool Packed = false>
T& mathter::Vector< T, Dim, Packed >::operator() ( int  idx)
inline

Returns the nth element of the vector.

◆ operator=()

template<class T, int Dim, bool Packed = false>
Vector& mathter::Vector< T, Dim, Packed >::operator= ( const Vector< T, Dim, Packed > &  )
default

◆ operator[]() [1/2]

template<class T, int Dim, bool Packed = false>
T mathter::Vector< T, Dim, Packed >::operator[] ( int  idx) const
inline

Returns the nth element of the vector.

◆ operator[]() [2/2]

template<class T, int Dim, bool Packed = false>
T& mathter::Vector< T, Dim, Packed >::operator[] ( int  idx)
inline

Returns the nth element of the vector.

◆ Set() [1/2]

template<class T, int Dim, bool Packed = false>
template<class... Scalars, typename std::enable_if<((sizeof...(Scalars) > 1>
Vector& mathter::Vector< T, Dim, Packed >::Set ( Scalars...  scalars)
inline

Sets the vector's elements to the given scalars.

Number of arguments must equal vector dimension. Types of arguments may differ from vector's underlying type, in which case explicit cast is performed.

◆ Set() [2/2]

template<class T, int Dim, bool Packed = false>
template<class... Mixed, typename std::enable_if<(sizeof...(Mixed) > 0>
Vector& mathter::Vector< T, Dim, Packed >::Set ( const Mixed &...  mixed)
inline

Sets the vector's elements by concatenating given scalar and vector arguments.

Sum of the dimension of arguments must equal vector dimension. Types of arguments may differ from vector's underlying type, in which case explicit cast is performed.


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