Jet
v1.3.3
|
General purpose dynamically-sizedN-D vector class. More...
#include <jet/vector_n.h>
Public Types | |
typedef std::vector< T > | ContainerType |
Public Member Functions | |
VectorN () | |
Constructs empty vector. More... | |
VectorN (size_t n, const T &val=0) | |
Constructs default vector (val, val, ... , val). More... | |
template<typename U > | |
VectorN (const std::initializer_list< U > &lst) | |
Constructs vector with given initializer list. More... | |
template<typename E > | |
VectorN (const VectorExpression< T, E > &other) | |
Constructs vector with expression template. More... | |
VectorN (const VectorN &other) | |
Copy constructor. More... | |
VectorN (VectorN &&other) | |
Move constructor. More... | |
void | resize (size_t n, const T &val=0) |
Resizes to n dimensional vector with initial value val . More... | |
void | clear () |
Clears the vector and make it zero-dimensional. More... | |
void | set (const T &s) |
Sets all elements to s . More... | |
template<typename U > | |
void | set (const std::initializer_list< U > &lst) |
Sets all elements with given initializer list. More... | |
template<typename E > | |
void | set (const VectorExpression< T, E > &other) |
Sets vector with expression template. More... | |
void | append (const T &val) |
Adds an element. More... | |
void | swap (VectorN &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... | |
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... | |
T | 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... | |
T | sum () const |
Returns the sum of all the elements. More... | |
T | avg () const |
Returns the average of all the elements. More... | |
T | min () const |
Returns the minimum element. More... | |
T | max () const |
Returns the maximum element. More... | |
T | absmin () const |
Returns the absolute minimum element. More... | |
T | 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, VectorN > | normalized () const |
Returns normalized vector. More... | |
T | length () const |
Returns the length of the vector. More... | |
T | lengthSquared () const |
Returns the squared length of the vector. More... | |
template<typename E > | |
T | distanceTo (const E &other) const |
Returns the distance to the other vector. More... | |
template<typename E > | |
T | distanceSquaredTo (const E &other) const |
Returns the squared distance to the other vector. More... | |
template<typename U > | |
VectorTypeCast< U, VectorN< T >, 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, VectorN, E > | add (const E &v) const |
Computes this + v. More... | |
VectorScalarAdd< T, VectorN > | add (const T &s) const |
Computes this + (s, s, ... , s). More... | |
template<typename E > | |
VectorSub< T, VectorN, E > | sub (const E &v) const |
Computes this - v. More... | |
VectorScalarSub< T, VectorN > | sub (const T &s) const |
Computes this - (s, s, ... , s). More... | |
template<typename E > | |
VectorMul< T, VectorN, E > | mul (const E &v) const |
Computes this * v. More... | |
VectorScalarMul< T, VectorN > | mul (const T &s) const |
Computes this * (s, s, ... , s). More... | |
template<typename E > | |
VectorDiv< T, VectorN, E > | div (const E &v) const |
Computes this / v. More... | |
VectorScalarDiv< T, VectorN > | div (const T &s) const |
Computes this / (s, s, ... , s). More... | |
template<typename E > | |
T | dot (const E &v) const |
Computes dot product. More... | |
VectorScalarRSub< T, VectorN > | rsub (const T &s) const |
Computes (s, s, ... , s) - this. More... | |
template<typename E > | |
VectorSub< T, VectorN, E > | rsub (const E &v) const |
Computes v - this. More... | |
VectorScalarRDiv< T, VectorN > | rdiv (const T &s) const |
Computes (s, s, ... , s) / this. More... | |
template<typename E > | |
VectorDiv< T, VectorN, 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... | |
template<typename Callback > | |
void | parallelForEach (Callback func) |
Iterates the vector and invoke given func for each element in parallel using multi-threading. More... | |
template<typename Callback > | |
void | parallelForEachIndex (Callback func) const |
Iterates the vector and invoke given func for each index in parallel using multi-threading. More... | |
T | operator[] (size_t i) const |
Returns the i -th element. More... | |
T & | operator[] (size_t i) |
Returns the reference to the i -th element. More... | |
template<typename U > | |
VectorN & | operator= (const std::initializer_list< U > &lst) |
Sets vector with given initializer list. More... | |
template<typename E > | |
VectorN & | operator= (const VectorExpression< T, E > &other) |
Sets vector with expression template. More... | |
VectorN & | operator= (const VectorN &other) |
Copy assignment. More... | |
VectorN & | operator= (VectorN &&other) |
Move assignment. More... | |
VectorN & | operator+= (const T &s) |
Computes this += (s, s, ... , s) More... | |
template<typename E > | |
VectorN & | operator+= (const E &v) |
Computes this += v. More... | |
VectorN & | operator-= (const T &s) |
Computes this -= (s, s, ... , s) More... | |
template<typename E > | |
VectorN & | operator-= (const E &v) |
Computes this -= v. More... | |
VectorN & | operator*= (const T &s) |
Computes this *= (s, s, ... , s) More... | |
template<typename E > | |
VectorN & | operator*= (const E &v) |
Computes this *= v. More... | |
VectorN & | operator/= (const T &s) |
Computes this /= (s, s, ... , s) More... | |
template<typename E > | |
VectorN & | operator/= (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... | |
![]() | |
size_t | size () const |
Size of the vector. More... | |
const VectorN< T > & | operator() () const |
Returns actual implementation (the subclass). More... | |
General purpose dynamically-sizedN-D vector class.
This class defines N-D vector data where its size can be defined dynamically.
T | Type of the element. |
typedef std::vector<T> jet::VectorN< T >::ContainerType |
jet::VectorN< T >::VectorN | ( | ) |
Constructs empty vector.
jet::VectorN< T >::VectorN | ( | size_t | n, |
const T & | val = 0 |
||
) |
Constructs default vector (val, val, ... , val).
jet::VectorN< T >::VectorN | ( | const std::initializer_list< U > & | lst | ) |
Constructs vector with given initializer list.
jet::VectorN< T >::VectorN | ( | const VectorExpression< T, E > & | other | ) |
Constructs vector with expression template.
jet::VectorN< T >::VectorN | ( | const VectorN< T > & | other | ) |
Copy constructor.
jet::VectorN< T >::VectorN | ( | VectorN< T > && | other | ) |
Move constructor.
T jet::VectorN< T >::absmax | ( | ) | const |
Returns the absolute maximum element.
T jet::VectorN< T >::absmin | ( | ) | const |
Returns the absolute minimum element.
ArrayAccessor1<T> jet::VectorN< T >::accessor | ( | ) |
Returns the array accessor.
VectorAdd<T, VectorN, E> jet::VectorN< T >::add | ( | const E & | v | ) | const |
Computes this + v.
VectorScalarAdd<T, VectorN> jet::VectorN< T >::add | ( | const T & | s | ) | const |
Computes this + (s, s, ... , s).
void jet::VectorN< T >::append | ( | const T & | val | ) |
Adds an element.
T& jet::VectorN< T >::at | ( | size_t | i | ) |
Returns reference to the i
-th element of the vector.
T jet::VectorN< T >::at | ( | size_t | i | ) | const |
Returns const reference to the i
-th element of the vector.
T jet::VectorN< T >::avg | ( | ) | const |
Returns the average of all the elements.
ContainerType::iterator jet::VectorN< T >::begin | ( | ) |
Returns the begin iterator of the vector.
ContainerType::const_iterator jet::VectorN< T >::begin | ( | ) | const |
Returns the begin const iterator of the vector.
VectorTypeCast<U, VectorN<T>, T> jet::VectorN< T >::castTo | ( | ) | const |
Returns a vector with different value type.
void jet::VectorN< T >::clear | ( | ) |
Clears the vector and make it zero-dimensional.
ConstArrayAccessor1<T> jet::VectorN< T >::constAccessor | ( | ) | const |
Returns the const array accessor.
T* jet::VectorN< T >::data | ( | ) |
Returns the raw pointer to the vector data.
const T* const jet::VectorN< T >::data | ( | ) | const |
Returns the const raw pointer to the vector data.
T jet::VectorN< T >::distanceSquaredTo | ( | const E & | other | ) | const |
Returns the squared distance to the other vector.
T jet::VectorN< T >::distanceTo | ( | const E & | other | ) | const |
Returns the distance to the other vector.
VectorDiv<T, VectorN, E> jet::VectorN< T >::div | ( | const E & | v | ) | const |
Computes this / v.
VectorScalarDiv<T, VectorN> jet::VectorN< T >::div | ( | const T & | s | ) | const |
Computes this / (s, s, ... , s).
size_t jet::VectorN< T >::dominantAxis | ( | ) | const |
Returns the index of the dominant axis.
Computes dot product.
ContainerType::iterator jet::VectorN< T >::end | ( | ) |
Returns the end iterator of the vector.
ContainerType::const_iterator jet::VectorN< T >::end | ( | ) | const |
Returns the end const iterator of the vector.
void jet::VectorN< T >::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:
void jet::VectorN< T >::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:
Computes this += v.
void jet::VectorN< T >::iadd | ( | const T & | s | ) |
Computes this += (s, s, ... , s).
Computes this /= v.
void jet::VectorN< T >::idiv | ( | const T & | s | ) |
Computes this /= (s, s, ... , s).
Computes this *= v.
void jet::VectorN< T >::imul | ( | const T & | s | ) |
Computes this *= (s, s, ... , s).
bool jet::VectorN< T >::isEqual | ( | const E & | other | ) | const |
Returns true if other
is the same as this vector.
bool jet::VectorN< T >::isSimilar | ( | const E & | other, |
T | epsilon = std::numeric_limits< T >::epsilon() |
||
) | const |
Returns true if other
is similar to this vector.
Computes this -= v.
void jet::VectorN< T >::isub | ( | const T & | s | ) |
Computes this -= (s, s, ... , s).
T jet::VectorN< T >::length | ( | ) | const |
Returns the length of the vector.
T jet::VectorN< T >::lengthSquared | ( | ) | const |
Returns the squared length of the vector.
T jet::VectorN< T >::max | ( | ) | const |
Returns the maximum element.
T jet::VectorN< T >::min | ( | ) | const |
Returns the minimum element.
VectorMul<T, VectorN, E> jet::VectorN< T >::mul | ( | const E & | v | ) | const |
Computes this * v.
VectorScalarMul<T, VectorN> jet::VectorN< T >::mul | ( | const T & | s | ) | const |
Computes this * (s, s, ... , s).
void jet::VectorN< T >::normalize | ( | ) |
Normalizes this vector.
VectorScalarDiv<T, VectorN> jet::VectorN< T >::normalized | ( | ) | const |
Returns normalized vector.
Returns true if other
is the not same as this vector.
Computes this *= v.
VectorN& jet::VectorN< T >::operator*= | ( | const T & | s | ) |
Computes this *= (s, s, ... , s)
Computes this += v.
VectorN& jet::VectorN< T >::operator+= | ( | const T & | s | ) |
Computes this += (s, s, ... , s)
Computes this -= v.
VectorN& jet::VectorN< T >::operator-= | ( | const T & | s | ) |
Computes this -= (s, s, ... , s)
Computes this /= v.
VectorN& jet::VectorN< T >::operator/= | ( | const T & | s | ) |
Computes this /= (s, s, ... , s)
VectorN& jet::VectorN< T >::operator= | ( | const std::initializer_list< U > & | lst | ) |
Sets vector with given initializer list.
VectorN& jet::VectorN< T >::operator= | ( | const VectorExpression< T, E > & | other | ) |
Sets vector with expression template.
VectorN& jet::VectorN< T >::operator= | ( | const VectorN< T > & | other | ) |
Copy assignment.
VectorN& jet::VectorN< T >::operator= | ( | VectorN< T > && | other | ) |
Move assignment.
Returns true if other
is the same as this vector.
T& jet::VectorN< T >::operator[] | ( | size_t | i | ) |
Returns the reference to the i
-th element.
T jet::VectorN< T >::operator[] | ( | size_t | i | ) | const |
Returns the i
-th element.
void jet::VectorN< T >::parallelForEach | ( | Callback | func | ) |
Iterates the vector and invoke given func
for each element in parallel using multi-threading.
This function iterates the vector elements and invoke the callback function func
in parallel using multi-threading. The callback function takes vector's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.
void jet::VectorN< T >::parallelForEachIndex | ( | Callback | func | ) | const |
Iterates the vector and invoke given func
for each index in parallel using multi-threading.
This function iterates the vector elements and invoke the callback function func
in parallel using multi-threading. The callback function takes one parameter which is the index of the vector. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
VectorDiv<T, VectorN, E> jet::VectorN< T >::rdiv | ( | const E & | v | ) | const |
Computes v / this.
VectorScalarRDiv<T, VectorN> jet::VectorN< T >::rdiv | ( | const T & | s | ) | const |
Computes (s, s, ... , s) / this.
void jet::VectorN< T >::resize | ( | size_t | n, |
const T & | val = 0 |
||
) |
Resizes to n
dimensional vector with initial value val
.
VectorSub<T, VectorN, E> jet::VectorN< T >::rsub | ( | const E & | v | ) | const |
Computes v - this.
VectorScalarRSub<T, VectorN> jet::VectorN< T >::rsub | ( | const T & | s | ) | const |
Computes (s, s, ... , s) - this.
void jet::VectorN< T >::set | ( | const std::initializer_list< U > & | lst | ) |
Sets all elements with given initializer list.
void jet::VectorN< T >::set | ( | const T & | s | ) |
Sets all elements to s
.
void jet::VectorN< T >::set | ( | const VectorExpression< T, E > & | other | ) |
Sets vector with expression template.
void jet::VectorN< T >::setZero | ( | ) |
Sets all elements to zero.
size_t jet::VectorN< T >::size | ( | ) | const |
Returns the size of the vector.
VectorSub<T, VectorN, E> jet::VectorN< T >::sub | ( | const E & | v | ) | const |
Computes this - v.
VectorScalarSub<T, VectorN> jet::VectorN< T >::sub | ( | const T & | s | ) | const |
Computes this - (s, s, ... , s).
size_t jet::VectorN< T >::subminantAxis | ( | ) | const |
Returns the index of the subminant axis.
T jet::VectorN< T >::sum | ( | ) | const |
Returns the sum of all the elements.
void jet::VectorN< T >::swap | ( | VectorN< T > & | other | ) |
Swaps the content of the vector with other
vector.