Jet  v1.3.3
Public Types | Public Member Functions | List of all members
jet::Vector< T, N > Class Template Referencefinal

Generic statically-sized N-D vector class. More...

#include <jet/vector.h>

Inheritance diagram for jet::Vector< T, N >:
jet::VectorExpression< T, Vector< T, N > >

Public Types

typedef std::array< T, N > ContainerType
 

Public Member Functions

 Vector ()
 Constructs a vector with zeros. More...
 
template<typename... Params>
 Vector (Params... params)
 Constructs vector instance with parameters. More...
 
void set (const T &s)
 Sets all elements to s. More...
 
template<typename U >
 Vector (const std::initializer_list< U > &lst)
 Constructs vector instance with initializer list. More...
 
template<typename E >
 Vector (const VectorExpression< T, E > &other)
 Constructs vector with expression template. More...
 
 Vector (const Vector &other)
 Copy constructor. More...
 
template<typename U >
void set (const std::initializer_list< U > &lst)
 Set vector instance with initializer list. More...
 
template<typename E >
void set (const VectorExpression< T, E > &other)
 Sets vector with expression template. More...
 
void swap (Vector &other)
 Swaps the content of the vector with other vector. More...
 
void setZero ()
 Sets all elements to zero. More...
 
void normalize ()
 Normalizes this vector. More...
 
constexpr size_t size () const
 Returns the size of the vector. More...
 
T * data ()
 Returns the raw pointer to the vector data. More...
 
const T *const data () const
 Returns the const raw pointer to the vector data. More...
 
ContainerType::iterator begin ()
 Returns the begin iterator of the vector. More...
 
ContainerType::const_iterator begin () const
 Returns the begin const iterator of the vector. More...
 
ContainerType::iterator end ()
 Returns the end iterator of the vector. More...
 
ContainerType::const_iterator end () const
 Returns the end const iterator of the vector. More...
 
ArrayAccessor1< T > accessor ()
 Returns the array accessor. More...
 
ConstArrayAccessor1< T > constAccessor () const
 Returns the const array accessor. More...
 
at (size_t i) const
 Returns const reference to the i -th element of the vector. More...
 
T & at (size_t i)
 Returns reference to the i -th element of the vector. More...
 
sum () const
 Returns the sum of all the elements. More...
 
avg () const
 Returns the average of all the elements. More...
 
min () const
 Returns the minimum element. More...
 
max () const
 Returns the maximum element. More...
 
absmin () const
 Returns the absolute minimum element. More...
 
absmax () const
 Returns the absolute maximum element. More...
 
size_t dominantAxis () const
 Returns the index of the dominant axis. More...
 
size_t subminantAxis () const
 Returns the index of the subminant axis. More...
 
VectorScalarDiv< T, Vectornormalized () const
 Returns normalized vector. More...
 
length () const
 Returns the length of the vector. More...
 
lengthSquared () const
 Returns the squared length of the vector. More...
 
template<typename E >
distanceTo (const E &other) const
 Returns the distance to the other vector. More...
 
template<typename E >
distanceSquaredTo (const E &other) const
 Returns the squared distance to the other vector. More...
 
template<typename U >
VectorTypeCast< U, Vector< T, N >, T > castTo () const
 Returns a vector with different value type. More...
 
template<typename E >
bool isEqual (const E &other) const
 Returns true if other is the same as this vector. More...
 
template<typename E >
bool isSimilar (const E &other, T epsilon=std::numeric_limits< T >::epsilon()) const
 Returns true if other is similar to this vector. More...
 
template<typename E >
VectorAdd< T, Vector, E > add (const E &v) const
 Computes this + v. More...
 
VectorScalarAdd< T, Vectoradd (const T &s) const
 Computes this + (s, s, ... , s). More...
 
template<typename E >
VectorSub< T, Vector, E > sub (const E &v) const
 Computes this - v. More...
 
VectorScalarSub< T, Vectorsub (const T &s) const
 Computes this - (s, s, ... , s). More...
 
template<typename E >
VectorMul< T, Vector, E > mul (const E &v) const
 Computes this * v. More...
 
VectorScalarMul< T, Vectormul (const T &s) const
 Computes this * (s, s, ... , s). More...
 
template<typename E >
VectorDiv< T, Vector, E > div (const E &v) const
 Computes this / v. More...
 
VectorScalarDiv< T, Vectordiv (const T &s) const
 Computes this / (s, s, ... , s). More...
 
template<typename E >
dot (const E &v) const
 Computes dot product. More...
 
VectorScalarRSub< T, Vectorrsub (const T &s) const
 Computes (s, s, ... , s) - this. More...
 
template<typename E >
VectorSub< T, Vector, E > rsub (const E &v) const
 Computes v - this. More...
 
VectorScalarRDiv< T, Vectorrdiv (const T &s) const
 Computes (s, s, ... , s) / this. More...
 
template<typename E >
VectorDiv< T, Vector, E > rdiv (const E &v) const
 Computes v / this. More...
 
void iadd (const T &s)
 Computes this += (s, s, ... , s). More...
 
template<typename E >
void iadd (const E &v)
 Computes this += v. More...
 
void isub (const T &s)
 Computes this -= (s, s, ... , s). More...
 
template<typename E >
void isub (const E &v)
 Computes this -= v. More...
 
void imul (const T &s)
 Computes this *= (s, s, ... , s). More...
 
template<typename E >
void imul (const E &v)
 Computes this *= v. More...
 
void idiv (const T &s)
 Computes this /= (s, s, ... , s). More...
 
template<typename E >
void idiv (const E &v)
 Computes this /= v. More...
 
template<typename Callback >
void forEach (Callback func) const
 Iterates the vector and invoke given func for each element. More...
 
template<typename Callback >
void forEachIndex (Callback func) const
 Iterates the vector and invoke given func for each index. More...
 
const T & operator[] (size_t i) const
 Returns the const reference to the i -th element. More...
 
T & operator[] (size_t)
 Returns the reference to the i -th element. More...
 
template<typename U >
Vectoroperator= (const std::initializer_list< U > &lst)
 Set vector instance with initializer list. More...
 
template<typename E >
Vectoroperator= (const VectorExpression< T, E > &other)
 Sets vector with expression template. More...
 
Vectoroperator+= (const T &s)
 Computes this += (s, s, ... , s) More...
 
template<typename E >
Vectoroperator+= (const E &v)
 Computes this += v. More...
 
Vectoroperator-= (const T &s)
 Computes this -= (s, s, ... , s) More...
 
template<typename E >
Vectoroperator-= (const E &v)
 Computes this -= v. More...
 
Vectoroperator*= (const T &s)
 Computes this *= (s, s, ... , s) More...
 
template<typename E >
Vectoroperator*= (const E &v)
 Computes this *= v. More...
 
Vectoroperator/= (const T &s)
 Computes this /= (s, s, ... , s) More...
 
template<typename E >
Vectoroperator/= (const E &v)
 Computes this /= v. More...
 
template<typename E >
bool operator== (const E &v) const
 Returns true if other is the same as this vector. More...
 
template<typename E >
bool operator!= (const E &v) const
 Returns true if other is the not same as this vector. More...
 
- Public Member Functions inherited from jet::VectorExpression< T, Vector< T, N > >
size_t size () const
 Size of the vector. More...
 
const Vector< T, N > & operator() () const
 Returns actual implementation (the subclass). More...
 

Detailed Description

template<typename T, size_t N>
class jet::Vector< T, N >

Generic statically-sized N-D vector class.

This class defines N-D vector data where its size is determined statically at compile time.

Template Parameters
T- Number type.
N- Dimension.

Member Typedef Documentation

◆ ContainerType

template<typename T , size_t N>
typedef std::array<T, N> jet::Vector< T, N >::ContainerType

Constructor & Destructor Documentation

◆ Vector() [1/5]

template<typename T , size_t N>
jet::Vector< T, N >::Vector ( )

Constructs a vector with zeros.

◆ Vector() [2/5]

template<typename T , size_t N>
template<typename... Params>
jet::Vector< T, N >::Vector ( Params...  params)
explicit

Constructs vector instance with parameters.

◆ Vector() [3/5]

template<typename T , size_t N>
template<typename U >
jet::Vector< T, N >::Vector ( const std::initializer_list< U > &  lst)

Constructs vector instance with initializer list.

◆ Vector() [4/5]

template<typename T , size_t N>
template<typename E >
jet::Vector< T, N >::Vector ( const VectorExpression< T, E > &  other)

Constructs vector with expression template.

◆ Vector() [5/5]

template<typename T , size_t N>
jet::Vector< T, N >::Vector ( const Vector< T, N > &  other)

Copy constructor.

Member Function Documentation

◆ absmax()

template<typename T , size_t N>
T jet::Vector< T, N >::absmax ( ) const

Returns the absolute maximum element.

◆ absmin()

template<typename T , size_t N>
T jet::Vector< T, N >::absmin ( ) const

Returns the absolute minimum element.

◆ accessor()

template<typename T , size_t N>
ArrayAccessor1<T> jet::Vector< T, N >::accessor ( )

Returns the array accessor.

◆ add() [1/2]

template<typename T , size_t N>
template<typename E >
VectorAdd<T, Vector, E> jet::Vector< T, N >::add ( const E &  v) const

Computes this + v.

◆ add() [2/2]

template<typename T , size_t N>
VectorScalarAdd<T, Vector> jet::Vector< T, N >::add ( const T &  s) const

Computes this + (s, s, ... , s).

◆ at() [1/2]

template<typename T , size_t N>
T& jet::Vector< T, N >::at ( size_t  i)

Returns reference to the i -th element of the vector.

◆ at() [2/2]

template<typename T , size_t N>
T jet::Vector< T, N >::at ( size_t  i) const

Returns const reference to the i -th element of the vector.

◆ avg()

template<typename T , size_t N>
T jet::Vector< T, N >::avg ( ) const

Returns the average of all the elements.

◆ begin() [1/2]

template<typename T , size_t N>
ContainerType::iterator jet::Vector< T, N >::begin ( )

Returns the begin iterator of the vector.

◆ begin() [2/2]

template<typename T , size_t N>
ContainerType::const_iterator jet::Vector< T, N >::begin ( ) const

Returns the begin const iterator of the vector.

◆ castTo()

template<typename T , size_t N>
template<typename U >
VectorTypeCast<U, Vector<T, N>, T> jet::Vector< T, N >::castTo ( ) const

Returns a vector with different value type.

◆ constAccessor()

template<typename T , size_t N>
ConstArrayAccessor1<T> jet::Vector< T, N >::constAccessor ( ) const

Returns the const array accessor.

◆ data() [1/2]

template<typename T , size_t N>
T* jet::Vector< T, N >::data ( )

Returns the raw pointer to the vector data.

◆ data() [2/2]

template<typename T , size_t N>
const T* const jet::Vector< T, N >::data ( ) const

Returns the const raw pointer to the vector data.

◆ distanceSquaredTo()

template<typename T , size_t N>
template<typename E >
T jet::Vector< T, N >::distanceSquaredTo ( const E &  other) const

Returns the squared distance to the other vector.

◆ distanceTo()

template<typename T , size_t N>
template<typename E >
T jet::Vector< T, N >::distanceTo ( const E &  other) const

Returns the distance to the other vector.

◆ div() [1/2]

template<typename T , size_t N>
template<typename E >
VectorDiv<T, Vector, E> jet::Vector< T, N >::div ( const E &  v) const

Computes this / v.

◆ div() [2/2]

template<typename T , size_t N>
VectorScalarDiv<T, Vector> jet::Vector< T, N >::div ( const T &  s) const

Computes this / (s, s, ... , s).

◆ dominantAxis()

template<typename T , size_t N>
size_t jet::Vector< T, N >::dominantAxis ( ) const

Returns the index of the dominant axis.

◆ dot()

template<typename T , size_t N>
template<typename E >
T jet::Vector< T, N >::dot ( const E &  v) const

Computes dot product.

◆ end() [1/2]

template<typename T , size_t N>
ContainerType::iterator jet::Vector< T, N >::end ( )

Returns the end iterator of the vector.

◆ end() [2/2]

template<typename T , size_t N>
ContainerType::const_iterator jet::Vector< T, N >::end ( ) const

Returns the end const iterator of the vector.

◆ forEach()

template<typename T , size_t N>
template<typename Callback >
void jet::Vector< T, N >::forEach ( Callback  func) const

Iterates the vector and invoke given func for each element.

This function iterates the vector elements and invoke the callback function func. The callback function takes array's element as its input. The order of execution will be 0 to N-1 where N is the size of the vector. Below is the sample usage:

Vector<float, 2> vec(10, 4.f);
vec.forEach([](float elem) {
printf("%d\n", elem);
});

◆ forEachIndex()

template<typename T , size_t N>
template<typename Callback >
void jet::Vector< T, N >::forEachIndex ( Callback  func) const

Iterates the vector and invoke given func for each index.

This function iterates the vector elements and invoke the callback function func. The callback function takes one parameter which is the index of the vector. The order of execution will be 0 to N-1 where N is the size of the array. Below is the sample usage:

Vector<float, 2> vec(10, 4.f);
vec.forEachIndex([&](size_t i) {
vec[i] = 4.f * i + 1.5f;
});

◆ iadd() [1/2]

template<typename T , size_t N>
template<typename E >
void jet::Vector< T, N >::iadd ( const E &  v)

Computes this += v.

◆ iadd() [2/2]

template<typename T , size_t N>
void jet::Vector< T, N >::iadd ( const T &  s)

Computes this += (s, s, ... , s).

◆ idiv() [1/2]

template<typename T , size_t N>
template<typename E >
void jet::Vector< T, N >::idiv ( const E &  v)

Computes this /= v.

◆ idiv() [2/2]

template<typename T , size_t N>
void jet::Vector< T, N >::idiv ( const T &  s)

Computes this /= (s, s, ... , s).

◆ imul() [1/2]

template<typename T , size_t N>
template<typename E >
void jet::Vector< T, N >::imul ( const E &  v)

Computes this *= v.

◆ imul() [2/2]

template<typename T , size_t N>
void jet::Vector< T, N >::imul ( const T &  s)

Computes this *= (s, s, ... , s).

◆ isEqual()

template<typename T , size_t N>
template<typename E >
bool jet::Vector< T, N >::isEqual ( const E &  other) const

Returns true if other is the same as this vector.

◆ isSimilar()

template<typename T , size_t N>
template<typename E >
bool jet::Vector< T, N >::isSimilar ( const E &  other,
epsilon = std::numeric_limits< T >::epsilon() 
) const

Returns true if other is similar to this vector.

◆ isub() [1/2]

template<typename T , size_t N>
template<typename E >
void jet::Vector< T, N >::isub ( const E &  v)

Computes this -= v.

◆ isub() [2/2]

template<typename T , size_t N>
void jet::Vector< T, N >::isub ( const T &  s)

Computes this -= (s, s, ... , s).

◆ length()

template<typename T , size_t N>
T jet::Vector< T, N >::length ( ) const

Returns the length of the vector.

◆ lengthSquared()

template<typename T , size_t N>
T jet::Vector< T, N >::lengthSquared ( ) const

Returns the squared length of the vector.

◆ max()

template<typename T , size_t N>
T jet::Vector< T, N >::max ( ) const

Returns the maximum element.

◆ min()

template<typename T , size_t N>
T jet::Vector< T, N >::min ( ) const

Returns the minimum element.

◆ mul() [1/2]

template<typename T , size_t N>
template<typename E >
VectorMul<T, Vector, E> jet::Vector< T, N >::mul ( const E &  v) const

Computes this * v.

◆ mul() [2/2]

template<typename T , size_t N>
VectorScalarMul<T, Vector> jet::Vector< T, N >::mul ( const T &  s) const

Computes this * (s, s, ... , s).

◆ normalize()

template<typename T , size_t N>
void jet::Vector< T, N >::normalize ( )

Normalizes this vector.

◆ normalized()

template<typename T , size_t N>
VectorScalarDiv<T, Vector> jet::Vector< T, N >::normalized ( ) const

Returns normalized vector.

◆ operator!=()

template<typename T , size_t N>
template<typename E >
bool jet::Vector< T, N >::operator!= ( const E &  v) const

Returns true if other is the not same as this vector.

◆ operator*=() [1/2]

template<typename T , size_t N>
template<typename E >
Vector& jet::Vector< T, N >::operator*= ( const E &  v)

Computes this *= v.

◆ operator*=() [2/2]

template<typename T , size_t N>
Vector& jet::Vector< T, N >::operator*= ( const T &  s)

Computes this *= (s, s, ... , s)

◆ operator+=() [1/2]

template<typename T , size_t N>
template<typename E >
Vector& jet::Vector< T, N >::operator+= ( const E &  v)

Computes this += v.

◆ operator+=() [2/2]

template<typename T , size_t N>
Vector& jet::Vector< T, N >::operator+= ( const T &  s)

Computes this += (s, s, ... , s)

◆ operator-=() [1/2]

template<typename T , size_t N>
template<typename E >
Vector& jet::Vector< T, N >::operator-= ( const E &  v)

Computes this -= v.

◆ operator-=() [2/2]

template<typename T , size_t N>
Vector& jet::Vector< T, N >::operator-= ( const T &  s)

Computes this -= (s, s, ... , s)

◆ operator/=() [1/2]

template<typename T , size_t N>
template<typename E >
Vector& jet::Vector< T, N >::operator/= ( const E &  v)

Computes this /= v.

◆ operator/=() [2/2]

template<typename T , size_t N>
Vector& jet::Vector< T, N >::operator/= ( const T &  s)

Computes this /= (s, s, ... , s)

◆ operator=() [1/2]

template<typename T , size_t N>
template<typename U >
Vector& jet::Vector< T, N >::operator= ( const std::initializer_list< U > &  lst)

Set vector instance with initializer list.

◆ operator=() [2/2]

template<typename T , size_t N>
template<typename E >
Vector& jet::Vector< T, N >::operator= ( const VectorExpression< T, E > &  other)

Sets vector with expression template.

◆ operator==()

template<typename T , size_t N>
template<typename E >
bool jet::Vector< T, N >::operator== ( const E &  v) const

Returns true if other is the same as this vector.

◆ operator[]() [1/2]

template<typename T , size_t N>
const T& jet::Vector< T, N >::operator[] ( size_t  i) const

Returns the const reference to the i -th element.

◆ operator[]() [2/2]

template<typename T , size_t N>
T& jet::Vector< T, N >::operator[] ( size_t  )

Returns the reference to the i -th element.

◆ rdiv() [1/2]

template<typename T , size_t N>
template<typename E >
VectorDiv<T, Vector, E> jet::Vector< T, N >::rdiv ( const E &  v) const

Computes v / this.

◆ rdiv() [2/2]

template<typename T , size_t N>
VectorScalarRDiv<T, Vector> jet::Vector< T, N >::rdiv ( const T &  s) const

Computes (s, s, ... , s) / this.

◆ rsub() [1/2]

template<typename T , size_t N>
template<typename E >
VectorSub<T, Vector, E> jet::Vector< T, N >::rsub ( const E &  v) const

Computes v - this.

◆ rsub() [2/2]

template<typename T , size_t N>
VectorScalarRSub<T, Vector> jet::Vector< T, N >::rsub ( const T &  s) const

Computes (s, s, ... , s) - this.

◆ set() [1/3]

template<typename T , size_t N>
template<typename U >
void jet::Vector< T, N >::set ( const std::initializer_list< U > &  lst)

Set vector instance with initializer list.

◆ set() [2/3]

template<typename T , size_t N>
void jet::Vector< T, N >::set ( const T &  s)

Sets all elements to s.

◆ set() [3/3]

template<typename T , size_t N>
template<typename E >
void jet::Vector< T, N >::set ( const VectorExpression< T, E > &  other)

Sets vector with expression template.

◆ setZero()

template<typename T , size_t N>
void jet::Vector< T, N >::setZero ( )

Sets all elements to zero.

◆ size()

template<typename T , size_t N>
constexpr size_t jet::Vector< T, N >::size ( ) const
constexpr

Returns the size of the vector.

◆ sub() [1/2]

template<typename T , size_t N>
template<typename E >
VectorSub<T, Vector, E> jet::Vector< T, N >::sub ( const E &  v) const

Computes this - v.

◆ sub() [2/2]

template<typename T , size_t N>
VectorScalarSub<T, Vector> jet::Vector< T, N >::sub ( const T &  s) const

Computes this - (s, s, ... , s).

◆ subminantAxis()

template<typename T , size_t N>
size_t jet::Vector< T, N >::subminantAxis ( ) const

Returns the index of the subminant axis.

◆ sum()

template<typename T , size_t N>
T jet::Vector< T, N >::sum ( ) const

Returns the sum of all the elements.

◆ swap()

template<typename T , size_t N>
void jet::Vector< T, N >::swap ( Vector< T, N > &  other)

Swaps the content of the vector with other vector.


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