IOLink  IOL_v1.2.0_release
iolink::Vector< T, N > Class Template Referencefinal

An arithmetic vector. More...

#include <iolink/Vector.h>

Public Types

using ValueType = T
 
using Iterator = typename std::array< T, N >::iterator
 
using ConstIterator = typename std::array< T, N >::const_iterator
 

Public Member Functions

 Vector ()
 Create a vector with unitialized values.
 
 Vector (std::initializer_list< ValueType > init)
 Create a vector with the values contained in a bracket list.
 
 Vector (const VectorX< ValueType > &other)
 Build a Vector from a VectorX of same type. More...
 
 Vector (const VectorX< ValueType > &other, ValueType padding)
 Build a vector from a VectorX of same type. More...
 
template<typename U >
 Vector (const Vector< U, N > &other)
 Build a vector from a vector storing another type. More...
 
 Vector (const Vector &other)=default
 
Vectoroperator= (const Vector &other)=default
 
 Vector (Vector &&other) noexcept=default
 
Vectoroperator= (Vector &&other) noexcept=default
 
size_t size () const
 Returns the size of the vector, which also correspond to vector number of dimension.
 
ValueType at (size_t index) const
 Access vector's value at given index.
 
void setAt (size_t index, ValueType value)
 Set value as given index.
 
ValueType operator[] (size_t index) const
 
ValueType & operator[] (size_t index)
 
double squaredLength () const
 Returns the vector's norm, squared. More...
 
double length () const
 Returns the vector's norm. More...
 
void normalize ()
 Normalize the vector.
 
Iterator begin () noexcept
 
ConstIterator begin () const noexcept
 
Iterator end () noexcept
 
ConstIterator end () const noexcept
 
bool operator== (const Vector &other) const
 
bool operator!= (const Vector &other) const
 
std::string toString () const
 
Vector operator- () const
 
Vectoroperator+= (const Vector &v)
 
Vectoroperator-= (const Vector &v)
 
Vector operator+ (const Vector &v) const
 
Vector operator- (const Vector &v) const
 
Vectoroperator*= (ValueType value)
 
Vectoroperator/= (ValueType value)
 
Vector operator* (ValueType v) const
 
Vector operator/ (ValueType v) const
 
ValueType dot (const Vector &v) const
 Dot product of two vectors.
 
Vector cross (const Vector &v) const
 Cross product of two vectors. More...
 
Vectoroperator*= (const Vector &v)
 
Vectoroperator/= (const Vector &v)
 
Vector operator* (const Vector &v) const
 
Vector operator/ (const Vector &v) const
 
bool operator< (const Vector &other) const
 
bool operator<= (const Vector &other) const
 
bool operator> (const Vector &other) const
 
bool operator>= (const Vector &other) const
 
 operator VectorX< ValueType > () const
 

Static Public Member Functions

static Vector createUniform (ValueType value)
 Create a vector with the given value for all components. More...
 

Friends

Vector operator* (ValueType value, Vector v)
 

Detailed Description

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

An arithmetic vector.

Template Parameters
TThe type wrote in the vector.
NThe size, or number of dimension of the vector.

Aliases can be used to made this class more practical to use. They use the following convention: VectorNX Where N is the size and X the type. The types currently available are:

  • U8 and I8 respectively for unsigned and signed 8bits integers.
  • U16 and I16 respectively for unsigned and signed 16bits integers.
  • U32 and I32 respectively for unsigned and signed 32bits integers.
  • U64 and I64 respectively for unsigned and signed 64bits integers.
  • F for single precision floats.
  • D for double precision floats.

Examples:

  • Vector2i32: 2 dimensional 32bits signed integer.
  • Vector3f: 3 dimensionnal single precision float.

Constructor & Destructor Documentation

◆ Vector() [1/3]

template<typename T , size_t N>
iolink::Vector< T, N >::Vector ( const VectorX< ValueType > &  other)

Build a Vector from a VectorX of same type.

If the VectorX has a size different of N, behavior is undefined.

◆ Vector() [2/3]

template<typename T , size_t N>
iolink::Vector< T, N >::Vector ( const VectorX< ValueType > &  other,
ValueType  padding 
)

Build a vector from a VectorX of same type.

Parameters
otherVectorX to use to build the new vector
paddingValue to put at the end of vector to fill missing values. Fox example, Vector4({4, 5}, 0) will create the Vector {4, 5, 0, 0}.

◆ Vector() [3/3]

template<typename T , size_t N>
template<typename U >
iolink::Vector< T, N >::Vector ( const Vector< U, N > &  other)
inlineexplicit

Build a vector from a vector storing another type.

Template Parameters
UThe type of the source vector.
Parameters
otherThe vector to convert.

Member Function Documentation

◆ createUniform()

template<typename T , size_t N>
static Vector iolink::Vector< T, N >::createUniform ( ValueType  value)
static

Create a vector with the given value for all components.

Parameters
valueThe value wich the vector's data will be filled.

◆ cross()

template<typename T , size_t N>
Vector iolink::Vector< T, N >::cross ( const Vector< T, N > &  v) const

Cross product of two vectors.

Work only for vectors of size 3.

◆ length()

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

Returns the vector's norm.

Specifically, it is the L1 norm that's computed here.

◆ squaredLength()

template<typename T , size_t N>
double iolink::Vector< T, N >::squaredLength ( ) const

Returns the vector's norm, squared.

Specifically, it is the L1 norm that's computed here.


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