Allolib  1.0
C++ Components For Interactive Multimedia
al::Vec< N, T > Class Template Reference

Fixed-size n-vector. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/math/al_Vec.hpp>

Inheritance diagram for al::Vec< N, T >:
al::VecElems< N, T >

Public Types

typedef T value_type
 

Public Member Functions

 Vec (const T &v=T())
 
 Vec (const T &v1, const T &v2)
 
 Vec (const T &v1, const T &v2, const T &v3)
 
 Vec (const T &v1, const T &v2, const T &v3, const T &v4)
 
template<int N2, class T2 >
 Vec (const Vec< N2, T2 > &v)
 
template<class Tv , class Ts >
 Vec (const Vec< N - 1, Tv > &v, const Ts &s)
 
template<class T2 >
 Vec (const T2 *v, int stride=1)
 
template<class V >
V & as ()
 Get reference to self as another type.
 
template<class V >
const V & as () const
 
const T * elems () const
 Get read-only pointer to elements.
 
T * elems ()
 Get read-write pointer to elements.
 
T * begin ()
 
const T * begin () const
 
T * end ()
 
const T * end () const
 
T & operator[] (size_t i)
 Set element at index with no bounds checking.
 
const T & operator[] (size_t i) const
 Get element at index with no bounds checking.
 
bool operator== (const Vec &v) const
 Return true if objects are element-wise equal, false otherwise.
 
bool operator== (const T &v) const
 Return true if all elements are equal to value, false otherwise.
 
bool operator!= (const Vec &v) const
 Return true if objects are not element-wise equal, false otherwise.
 
bool operator!= (const T &v) const
 Return true if all elements are not equal to value, false otherwise.
 
Vec< 2, T > get (int i0, int i1) const
 Get a vector comprised of indexed elements.
 
Vec< 3, T > get (int i0, int i1, int i2) const
 Get a vector comprised of indexed elements.
 
Vec< 4, T > get (int i0, int i1, int i2, int i3) const
 Get a vector comprised of indexed elements.
 
template<int M>
Vec< M, T > sub (int begin=0) const
 Get a subvector.
 
template<int M>
Vec< M, T > & sub (int begin=0)
 
Vecoperator= (const Vec &v)
 
Vecoperator= (const T &v)
 
Vecoperator+= (const Vec &v)
 
Vecoperator+= (const T &v)
 
Vecoperator-= (const Vec &v)
 
Vecoperator-= (const T &v)
 
Vecoperator*= (const Vec &v)
 
Vecoperator*= (const T &v)
 
Vecoperator/= (const Vec &v)
 
Vecoperator/= (const T &v)
 
Vec operator+ (const Vec &v) const
 
Vec operator+ (const T &v) const
 
Vec operator- (const Vec &v) const
 
Vec operator- (const T &v) const
 
Vec operator* (const Vec &v) const
 
Vec operator* (const T &v) const
 
Vec operator/ (const Vec &v) const
 
Vec operator/ (const T &v) const
 
Vec operator- () const
 
bool operator> (const Vec &v) const
 
bool operator< (const Vec &v) const
 
template<class T2 >
Vecset (const Vec< N, T2 > &v)
 Set elements from another vector.
 
template<int N2, class T2 >
Vecset (const Vec< N2, T2 > &v)
 Set elements from another vector.
 
template<class Tv , class Ts >
Vecset (const Vec< N - 1, Tv > &v, const Ts &s)
 Set elements from another vector and scalar.
 
Vecset (const T &v)
 Set all elements to the same value.
 
template<class T2 >
Vecset (const T2 *v)
 Set elements from raw C-pointer.
 
template<class T2 >
Vecset (const T2 *v, int stride)
 Set elements from strided raw C-pointer.
 
Vecset (const T &v1, const T &v2)
 Set first 2 elements.
 
Vecset (const T &v1, const T &v2, const T &v3)
 Set first 3 elements.
 
Vecset (const T &v1, const T &v2, const T &v3, const T &v4)
 Set first 4 elements.
 
Vecset (const T &v1, const T &v2, const T &v3, const T &v4, const T &v5)
 Set first 5 elements.
 
Vecset (const T &v1, const T &v2, const T &v3, const T &v4, const T &v5, const T &v6)
 Set first 6 elements.
 
Veczero ()
 Set all elements to zero.
 
template<int Dimension>
Vec by (T shift) const
 Returns a nearby vector along some dimension. More...
 
Vec byx (T shift) const
 Returns a nearby vector along x.
 
Vec byy (T shift) const
 Returns a nearby vector along y.
 
Vec byz (T shift) const
 Returns a nearby vector along z.
 
template<class U >
dot (const Vec< N, U > &v) const
 Returns dot (inner) product between vectors.
 
mag () const
 Returns magnitude.
 
magSqr () const
 Returns magnitude squared.
 
norm (const T &p) const
 Returns p-norm of elements. More...
 
norm1 () const
 Return 1-norm of elements.
 
norm2 () const
 Return 2-norm of elements.
 
product () const
 Returns product of elements.
 
sum () const
 Returns sum of elements.
 
sumAbs () const
 Returns sum of absolute value of elements.
 
Veclerp (const Vec &target, T amt)
 Linearly interpolate towards some target.
 
Vecmag (T v)
 Set magnitude (preserving direction)
 
Vecnegate ()
 Negates all elements.
 
Vecnormalize (T scale=T(1))
 Set magnitude to one without changing direction. More...
 
Vec normalized (T scale=T(1)) const
 Return closest vector lying on unit sphere. More...
 
Vec projection (const Vec &u) const
 Get projection of vector onto a unit vector.
 
Vec rejection (const Vec &u) const
 Get rejection of vector from a unit vector. More...
 
Vecreflect (const Vec &u)
 Relect vector around a unit vector.
 
Vecrotate (double angle, int dim1=0, int dim2=1)
 Rotate vector on a global plane. More...
 
void print (FILE *out=stdout) const
 debug printing
 

Static Public Member Functions

static int size ()
 Returns number of elements.
 
static Vecpun (T *src)
 Returns C array type punned into a vector.
 
static const Vecpun (const T *src)
 

Public Attributes

x
 
y
 
z
 
w
 

Detailed Description

template<int N, class T>
class al::Vec< N, T >

Fixed-size n-vector.

This is a fixed size array to enable better loop unrolling optimizations by the compiler and to avoid an extra 'size' data member for small-sized arrays.

Definition at line 117 of file al_Vec.hpp.

Constructor & Destructor Documentation

◆ Vec() [1/7]

template<int N, class T >
al::Vec< N, T >::Vec ( const T &  v = T())
inline
Parameters
[in]vvalue to initialize all elements to

Definition at line 124 of file al_Vec.hpp.

◆ Vec() [2/7]

template<int N, class T >
al::Vec< N, T >::Vec ( const T &  v1,
const T &  v2 
)
inline
Parameters
[in]v1value to initialize first element
[in]v2value to initialize second element

Definition at line 128 of file al_Vec.hpp.

◆ Vec() [3/7]

template<int N, class T >
al::Vec< N, T >::Vec ( const T &  v1,
const T &  v2,
const T &  v3 
)
inline
Parameters
[in]v1value to initialize first element
[in]v2value to initialize second element
[in]v3value to initialize third element

Definition at line 133 of file al_Vec.hpp.

◆ Vec() [4/7]

template<int N, class T >
al::Vec< N, T >::Vec ( const T &  v1,
const T &  v2,
const T &  v3,
const T &  v4 
)
inline
Parameters
[in]v1value to initialize first element
[in]v2value to initialize second element
[in]v3value to initialize third element
[in]v4value to initialize fourth element

Definition at line 139 of file al_Vec.hpp.

◆ Vec() [5/7]

template<int N, class T >
template<int N2, class T2 >
al::Vec< N, T >::Vec ( const Vec< N2, T2 > &  v)
inline
Parameters
[in]vvector to initialize all elements to

Definition at line 145 of file al_Vec.hpp.

◆ Vec() [6/7]

template<int N, class T >
template<class Tv , class Ts >
al::Vec< N, T >::Vec ( const Vec< N - 1, Tv > &  v,
const Ts &  s 
)
inline
Parameters
[in]vvector to initialize all elements to
[in]svalue of last element

Definition at line 152 of file al_Vec.hpp.

◆ Vec() [7/7]

template<int N, class T >
template<class T2 >
al::Vec< N, T >::Vec ( const T2 *  v,
int  stride = 1 
)
inline
Parameters
[in]vpointer to array to initialize all elements to
[in]stridestride factor through array

Definition at line 159 of file al_Vec.hpp.

Member Function Documentation

◆ by()

template<int N, class T >
template<int Dimension>
Vec al::Vec< N, T >::by ( shift) const
inline

Returns a nearby vector along some dimension.

Template Parameters
DimensionThe dimension along which to get a nearby vector
Parameters
[in]shiftThe amount to shift along specified dimension

Definition at line 389 of file al_Vec.hpp.

◆ norm()

template<int N, class T >
T al::Vec< N, T >::norm ( const T &  p) const
inline

Returns p-norm of elements.

The p-norm is pth root of the sum of the absolute value of the elements raised to the pth power, (sum |x_n|^p) ^ (1/p).

Definition at line 424 of file al_Vec.hpp.

◆ normalize()

template<int N, class T >
Vec< N, T > & al::Vec< N, T >::normalize ( scale = T(1))

Set magnitude to one without changing direction.

Parameters
[in]scaleamount to scale magnitude

Definition at line 729 of file al_Vec.hpp.

◆ normalized()

template<int N, class T >
Vec al::Vec< N, T >::normalized ( scale = T(1)) const
inline

Return closest vector lying on unit sphere.

Parameters
[in]scaleamount to scale magnitude of result

Definition at line 489 of file al_Vec.hpp.

◆ rejection()

template<int N, class T >
Vec al::Vec< N, T >::rejection ( const Vec< N, T > &  u) const
inline

Get rejection of vector from a unit vector.

This also gives the projection onto a plane defined by normal 'u'.

Definition at line 498 of file al_Vec.hpp.

◆ rotate()

template<int N, class T >
Vec& al::Vec< N, T >::rotate ( double  angle,
int  dim1 = 0,
int  dim2 = 1 
)
inline

Rotate vector on a global plane.

Parameters
[in]angleangle of right-handed rotation, in radians
[in]dim1dimension to rotate from
[in]dim2dimension to rotate towards

Definition at line 508 of file al_Vec.hpp.


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