Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
Public Member Functions | Public Attributes | Related Functions | List of all members
gf::Vector< T, N > Struct Template Reference

General purpose math vector. More...

#include <gf/Vector.h>

Public Member Functions

 Vector ()=default
 Default constructor. More...
 
 Vector (T val)
 Constructor that fills the vector with a value. More...
 
 Vector (T *array)
 Constructor that takes an array. More...
 
 Vector (std::initializer_list< T > list)
 Constructor that takes an initializer list. More...
 
 Vector (const Vector &other)=default
 Default copy constructor. More...
 
template<typename U >
 Vector (const Vector< U, N > &other)
 Converting copy constructor. More...
 
Vectoroperator= (const Vector &other)=default
 Default copy assignment. More...
 
T operator[] (std::size_t i) const
 Access to the \( i \)-th coordinate. More...
 
Toperator[] (std::size_t i)
 Access to the \( i \)-th coordinate. More...
 
Tbegin ()
 Iterator.to the first element. More...
 
Tend ()
 Iterator to the element after the last one. More...
 
const Tbegin () const
 Iterator.to the first element (const version). More...
 
const Tend () const
 Iterator on the element after the last one (const version). More...
 
const Tcbegin () const
 Iterator.on the first element (const version). More...
 
const Tcend () const
 Iterator on the element after the last one (const version). More...
 

Public Attributes

T data [N]
 The internal representation of the vector. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T , std::size_t N>
bool operator== (Vector< T, N > lhs, Vector< T, N > rhs)
 Equality operator between two vectors. More...
 
template<typename T , std::size_t N>
bool operator!= (Vector< T, N > lhs, Vector< T, N > rhs)
 Inequality operator between two vectors. More...
 
template<typename T , std::size_t N>
Vector< T, Noperator- (Vector< T, N > val)
 Component-wise unary minus. More...
 
template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, Noperator+ (Vector< T, N > lhs, Vector< U, N > rhs)
 Component-wise addition. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator+= (Vector< T, N > &lhs, Vector< U, N > rhs)
 Component-wise addition and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, Noperator+ (Vector< T, N > lhs, U rhs)
 Right scalar addition. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator+= (Vector< T, N > &lhs, U rhs)
 Right scalar addition and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, Noperator+ (T lhs, Vector< U, N > rhs)
 Left scalar addition. More...
 
template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, Noperator- (Vector< T, N > lhs, Vector< U, N > rhs)
 Component-wise substraction. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator-= (Vector< T, N > &lhs, Vector< U, N > rhs)
 Component-wise substraction and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, Noperator- (Vector< T, N > lhs, U rhs)
 Right scalar substraction. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator-= (Vector< T, N > &lhs, U rhs)
 Right scalar substraction and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, Noperator- (T lhs, Vector< U, N > rhs)
 Left scalar substraction. More...
 
template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, Noperator* (Vector< T, N > lhs, Vector< U, N > rhs)
 Component-wise multiplication. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator*= (Vector< T, N > &lhs, Vector< U, N > rhs)
 Component-wise multiplication and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, Noperator* (Vector< T, N > lhs, U rhs)
 Right scalar multiplication. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator*= (Vector< T, N > &lhs, U rhs)
 Right scalar multiplication and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, Noperator* (T lhs, Vector< U, N > rhs)
 Left scalar multiplication. More...
 
template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, Noperator/ (Vector< T, N > lhs, Vector< U, N > rhs)
 Component-wise division. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator/= (Vector< T, N > &lhs, Vector< U, N > rhs)
 Component-wise division and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, Noperator/ (Vector< T, N > lhs, U rhs)
 Right scalar division. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, N > & operator/= (Vector< T, N > &lhs, U rhs)
 Right scalar division and assignment. More...
 
template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, Noperator/ (T lhs, Vector< U, N > rhs)
 Left scalar division. More...
 
template<std::size_t N>
Vector< bool, Noperator|| (Vector< bool, N > lhs, Vector< bool, N > rhs)
 Component-wise logical or operator. More...
 
template<std::size_t N>
Vector< bool, Noperator&& (Vector< bool, N > lhs, Vector< bool, N > rhs)
 Component-wise logical and operator. More...
 
template<typename T , std::size_t N>
T dot (Vector< T, N > lhs, Vector< T, N > rhs)
 Scalar product. More...
 
template<typename T , std::size_t N>
Vector< T, Nmin (Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise minimum. More...
 
template<typename T , std::size_t N>
Vector< T, Nmax (Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise maximum. More...
 
template<typename T , std::size_t N>
Vector< T, Nabs (Vector< T, N > val)
 Component-wise absolute value. More...
 
template<typename T , std::size_t N>
Vector< bool, Nequals (Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise equality operator. More...
 
template<typename T , std::size_t N>
Vector< bool, NlessThan (Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise comparison operator. More...
 
template<typename T , std::size_t N>
Vector< bool, NgreaterThan (Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise comparison operator. More...
 
template<typename T , std::size_t N>
Vector< T, Nselect (Vector< bool, N > cond, Vector< T, N > lhs, Vector< T, N > rhs)
 Component-wise selection operator. More...
 
template<typename T , std::size_t N>
Vector< T, Nclamp (Vector< T, N > val, Vector< T, N > lo, Vector< T, N > hi)
 Component-wise clamp function. More...
 
template<typename T , std::size_t N>
Vector< T, Nclamp (Vector< T, N > val, T lo, T hi)
 Component-wise clamp function. More...
 
template<typename T , typename U , std::size_t N>
Vector< T, Nlerp (Vector< T, N > lhs, Vector< T, N > rhs, U t)
 Component-wise lerp function. More...
 
template<typename T , std::size_t N>
T manhattanLength (Vector< T, N > vec)
 Manhattan length of a vector. More...
 
template<typename T , std::size_t N>
T squareLength (Vector< T, N > vec)
 Square Euclidean length of a vector. More...
 
template<typename T , std::size_t N>
T euclideanLength (Vector< T, N > vec)
 Euclidean length of a vector. More...
 
template<typename T , std::size_t N>
T chebyshevLength (Vector< T, N > vec)
 Chebyshev length of a vector. More...
 
template<typename T , std::size_t N>
T naturalLength (Vector< T, N > vec)
 Natural length of a vector. More...
 
template<typename T , std::size_t N>
T manhattanDistance (Vector< T, N > lhs, Vector< T, N > rhs)
 Manhattan distance between two vectors. More...
 
template<typename T , std::size_t N>
T squareDistance (Vector< T, N > lhs, Vector< T, N > rhs)
 Square Euclidean distance between two vectors. More...
 
template<typename T , std::size_t N>
T euclideanDistance (Vector< T, N > lhs, Vector< T, N > rhs)
 Euclidean distance between two vectors. More...
 
template<typename T , std::size_t N>
T chebyshevDistance (Vector< T, N > lhs, Vector< T, N > rhs)
 Chebyshev distance between two vectors. More...
 
template<typename T , std::size_t N>
T naturalDistance (Vector< T, N > lhs, Vector< T, N > rhs)
 Natural distance between two vectors. More...
 
template<typename T , std::size_t N>
Vector< T, Nnormalize (Vector< T, N > vec)
 Normalize a vector. More...
 
template<typename T >
Vector< T, 2 > unit (T angle)
 Unit vector in a specified direction. More...
 
template<typename T >
float angle (Vector< T, 2 > vec)
 Angle of a vector relative to the x-axis. More...
 
template<typename T >
constexpr Vector< T, 2 > perp (Vector< T, 2 > vec)
 Perpendicular vector. More...
 
template<typename T >
Vector< T, 2 > vectorTripleProduct (Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
 Regular vector triple product. More...
 
template<typename T >
Vector< T, 2 > inverseVectorTripleProduct (Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c)
 Inverse vector triple product. More...
 
template<typename T >
constexpr T cross (Vector< T, 2 > lhs, Vector< T, 2 > rhs)
 Cross product for 2D vectors. More...
 
template<typename T >
constexpr Vector< T, 3 > cross (Vector< T, 3 > lhs, Vector< T, 3 > rhs)
 Cross product for 3D vectors. More...
 

Detailed Description

template<typename T, std::size_t N>
struct gf::Vector< T, N >

General purpose math vector.

gf::Vector is a class that represents an element of a N-dimensional space. It is used throughout the library for different purposes.

The template parameter T is the type of coordinates. . It can be any type that supports arithmetic operations (+, -, *, /) and relational operators (==, !=, <, >).

Several specializations are defined for common use cases:

This class was designed according to the article On Vector Math Libraries by Nathan Reed.

Constructor & Destructor Documentation

◆ Vector() [1/6]

template<typename T, std::size_t N>
gf::Vector< T, N >::Vector ( )
default

Default constructor.

This constructor is defaulted so that this type is trivial.

◆ Vector() [2/6]

template<typename T, std::size_t N>
gf::Vector< T, N >::Vector ( T  val)
inlineexplicit

Constructor that fills the vector with a value.

This constructor takes a value and fills the entire vector with this value. Care must be taken when calling this constructor:

gf::Vector<int, 5> vecOK(42); // OK, vector is filled with 42
gf::Vector<int, 5> vecKO{42}; // KO, vector is initialized with a 42 in the first coordinate
Parameters
valThe value to fill the vector with

◆ Vector() [3/6]

template<typename T, std::size_t N>
gf::Vector< T, N >::Vector ( T array)
inlineexplicit

Constructor that takes an array.

This constructor can ease conversion from other math libraries. The array must contain enough data for N dimensions.

float array[5] = { 1.0f, -1.0f, 0.5f, -2.0f, 0.0f };
Parameters
arrayAn array with the values of the vector

◆ Vector() [4/6]

template<typename T, std::size_t N>
gf::Vector< T, N >::Vector ( std::initializer_list< T list)
inline

Constructor that takes an initializer list.

This constructor allows to use an initializer list to define the coordinates of the vector.

gf::Vector<bool, 5> vec1{ true, true, false, true, false };
gf::Vector<bool, 5> vec2 = { false, true, true, false, true };
Parameters
listAn initializer list.

◆ Vector() [5/6]

template<typename T, std::size_t N>
gf::Vector< T, N >::Vector ( const Vector< T, N > &  other)
default

Default copy constructor.

This constructor is defaulted so that this type is trivial.

Parameters
otherThe vector to copy from

◆ Vector() [6/6]

template<typename T, std::size_t N>
template<typename U >
gf::Vector< T, N >::Vector ( const Vector< U, N > &  other)
inline

Converting copy constructor.

Parameters
otherThe vector to copy from

Member Function Documentation

◆ begin() [1/2]

template<typename T, std::size_t N>
T* gf::Vector< T, N >::begin ( )
inline

Iterator.to the first element.

Returns
A pointer to the first element.

◆ begin() [2/2]

template<typename T, std::size_t N>
const T* gf::Vector< T, N >::begin ( ) const
inline

Iterator.to the first element (const version).

Returns
A pointer on the first const element.

◆ cbegin()

template<typename T, std::size_t N>
const T* gf::Vector< T, N >::cbegin ( ) const
inline

Iterator.on the first element (const version).

Returns
A pointer on the first const element.

◆ cend()

template<typename T, std::size_t N>
const T* gf::Vector< T, N >::cend ( ) const
inline

Iterator on the element after the last one (const version).

Returns
An invalid pointer that is the adress after the last const element.

◆ end() [1/2]

template<typename T, std::size_t N>
T* gf::Vector< T, N >::end ( )
inline

Iterator to the element after the last one.

Returns
An invalid pointer that is the adress after the last element.

◆ end() [2/2]

template<typename T, std::size_t N>
const T* gf::Vector< T, N >::end ( ) const
inline

Iterator on the element after the last one (const version).

Returns
An invalid pointer that is the adress after the last const element.

◆ operator=()

template<typename T, std::size_t N>
Vector& gf::Vector< T, N >::operator= ( const Vector< T, N > &  other)
default

Default copy assignment.

This operator is defaulted so that this type is trivial.

◆ operator[]() [1/2]

template<typename T, std::size_t N>
T gf::Vector< T, N >::operator[] ( std::size_t  i) const
inline

Access to the \( i \)-th coordinate.

gf::Vector<int, 5> vec = { 1, 3, 5, 7, 9 };
std::printf("%i", vec[1]); // prints 3
Parameters
ithe coordinate number
Returns
The \( i \)-th coordinate of the vector

◆ operator[]() [2/2]

template<typename T, std::size_t N>
T& gf::Vector< T, N >::operator[] ( std::size_t  i)
inline

Access to the \( i \)-th coordinate.

vec[0] = vec[1] = vec[2] = vec[3] = vec[4] = 0;
Parameters
ithe coordinate number
Returns
The \( i \)-th coordinate of the vector

Friends And Related Function Documentation

◆ abs()

template<typename T , std::size_t N>
Vector< T, N > abs ( Vector< T, N val)
related

Component-wise absolute value.

◆ angle()

template<typename T >
float angle ( Vector< T, 2 >  vec)
related

Angle of a vector relative to the x-axis.

Parameters
vecThe vector
Returns
The angle of the vector

◆ chebyshevDistance()

template<typename T , std::size_t N>
T chebyshevDistance ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Chebyshev distance between two vectors.

The Chebyshev distance between two vectors is the Chebyshev length of the difference of the two vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The Chebyshev distance between the two vectors
See also
chebyshevLength()

◆ chebyshevLength()

template<typename T , std::size_t N>
T chebyshevLength ( Vector< T, N vec)
related

Chebyshev length of a vector.

The Chebyshev length \( \|\mathbf{u}\|_{\infty} \) of a vector \( \mathbf{u} = (u_1, \ldots, u_N) \) is:

\[ \|u\|_{\infty} = \max_{i = 1}^{N} |u_i| \]

The Chebyshev length is also called the infinity norm or maximum norm.

Parameters
vecA vector.
Returns
The Chebyshev length of the vector
See also
chebyshevDistance()

◆ clamp() [1/2]

template<typename T , std::size_t N>
Vector< T, N > clamp ( Vector< T, N val,
Vector< T, N lo,
Vector< T, N hi 
)
related

Component-wise clamp function.

Relative to two other vectors.

◆ clamp() [2/2]

template<typename T , std::size_t N>
Vector< T, N > clamp ( Vector< T, N val,
T  lo,
T  hi 
)
related

Component-wise clamp function.

Relative to two values.

◆ cross() [1/2]

template<typename T >
constexpr T cross ( Vector< T, 2 >  lhs,
Vector< T, 2 >  rhs 
)
related

Cross product for 2D vectors.

The cross product of 2D vectors is not really a cross product, it is the magnitude of the vector resulting from a 3D cross product of 2D vectors with \( z = 0 \). The cross product \( \mathbf{a} \times \mathbf{b} \) of the vectors \( \mathbf{a} \) and \( \mathbf{b} \) is:

\[ \mathbf{a} \times \mathbf{b} = \mathbf{a}^{\perp} \cdot \mathbf{b} \]

The 2D cross product is also known as the perp dot product or wedge product.

Parameters
lhsA first vector
rhsA second vector
Returns
The cross product of the two vectors

◆ cross() [2/2]

template<typename T >
constexpr Vector< T, 3 > cross ( Vector< T, 3 >  lhs,
Vector< T, 3 >  rhs 
)
related

Cross product for 3D vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The cross product of the two vectors

◆ dot()

template<typename T , std::size_t N>
T dot ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Scalar product.

The scalar product or dot product of two vectors \( \mathbf{a} = (a_1, \ldots, a_N) \) and \( \mathbf{b} = (b_1, \ldots, b_N) \) is:

\[ \mathbf{a} \cdot \mathbf{b} = \sum_{i=1}^{N} a_i b_i = a_1 b_1 + \ldots + a_N b_N \]

◆ equals()

template<typename T , std::size_t N>
Vector< bool, N > equals ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise equality operator.

◆ euclideanDistance()

template<typename T , std::size_t N>
T euclideanDistance ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Euclidean distance between two vectors.

The Euclidean distance between two vectors is the Euclidean length of the difference of the two vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The Euclidean distance between the two vectors
See also
euclideanLength()

◆ euclideanLength()

template<typename T , std::size_t N>
T euclideanLength ( Vector< T, N vec)
related

Euclidean length of a vector.

The Euclidean length \( \|\mathbf{u}\|_2 \) of a vector \( \mathbf{u} = (u_1, \ldots, u_N) \) is:

\[ \|\mathbf{u}\|_2 = \sqrt{\sum_{i = 1}^{N} u_i^2} \]

The Euclidean length is also called the 2-norm.

Parameters
vecA vector.
Returns
The Euclidean length of the vector
See also
euclideanDistance()

◆ greaterThan()

template<typename T , std::size_t N>
Vector< bool, N > greaterThan ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise comparison operator.

◆ inverseVectorTripleProduct()

template<typename T >
Vector< T, 2 > inverseVectorTripleProduct ( Vector< T, 2 >  a,
Vector< T, 2 >  b,
Vector< T, 2 >  c 
)
related

Inverse vector triple product.

The inverse vector triple product of vectors \( \mathbf{a} \), \( \mathbf{b} \) and \( \mathbf{c} \) is:

\[ (\mathbf{a} \times \mathbf{b}) \times \mathbf{c} = -\mathbf{c} \times (\mathbf{a} \times \mathbf{b}) = -(\mathbf{c} \cdot \mathbf{b}) \mathbf{a} + (\mathbf{c} \cdot \mathbf{a}) \mathbf{b} \]

See also
vectorTripleProduct()

◆ lerp()

template<typename T , typename U , std::size_t N>
Vector< T, N > lerp ( Vector< T, N lhs,
Vector< T, N rhs,
U  t 
)
related

Component-wise lerp function.

◆ lessThan()

template<typename T , std::size_t N>
Vector< bool, N > lessThan ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise comparison operator.

◆ manhattanDistance()

template<typename T , std::size_t N>
T manhattanDistance ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Manhattan distance between two vectors.

The Manhattan distance between two vectors is the Manhattan length of the difference of the two vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The Manhattan distance between the two vectors
See also
manhattanLength()

◆ manhattanLength()

template<typename T , std::size_t N>
T manhattanLength ( Vector< T, N vec)
related

Manhattan length of a vector.

The Manhattan length \( \|\mathbf{u}\|_1 \) of a vector \( \mathbf{u} = (u_1, \ldots, u_N) \) is:

\[ \|\mathbf{u}\|_1 = \sum_{i = 1}^{N} |u_i| \]

The Manhattan length is also called the 1-norm.

Parameters
vecA vector.
Returns
The Manhattan length of the vector
See also
manhattanDistance()

◆ max()

template<typename T , std::size_t N>
Vector< T, N > max ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise maximum.

◆ min()

template<typename T , std::size_t N>
Vector< T, N > min ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise minimum.

◆ naturalDistance()

template<typename T , std::size_t N>
T naturalDistance ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Natural distance between two vectors.

The natural distance between two vectors is the natural length of the difference of the two vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The natural distance between the two vectors
See also
naturalLength()

◆ naturalLength()

template<typename T , std::size_t N>
T naturalLength ( Vector< T, N vec)
related

Natural length of a vector.

The natural length \( L \) of a vector: \( \mathbf{u} = (u_1, \ldots, u_N) \) is:

\[ L = \|\mathbf{u}\|_1 + \|\mathbf{u}\|_2^2 = \sum_{i = 1}^{N} |u_i| + \sum_{i = 1}^{N} u_i^2 \]

It's the sum of the Manhattan length and the square length.

Parameters
vecA vector.
Returns
The natural length of the vector
See also
naturalDistance()

◆ normalize()

template<typename T , std::size_t N>
Vector< T, N > normalize ( Vector< T, N vec)
related

Normalize a vector.

The normalized vector of \( \mathbf{u} \) is a vector in the same direction but with a (euclidean) length of 1:

\[ \frac{\mathbf{u}}{\|\mathbf{u}\|_2} \]

A normalized vector is also called a unit vector.

Parameters
vecA vector
Returns
A normalized vector

◆ operator!=()

template<typename T , std::size_t N>
bool operator!= ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Inequality operator between two vectors.

◆ operator&&()

template<std::size_t N>
Vector< bool, N > operator && ( Vector< bool, N lhs,
Vector< bool, N rhs 
)
related

Component-wise logical and operator.

◆ operator*() [1/3]

template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, N > operator* ( Vector< T, N lhs,
Vector< U, N rhs 
)
related

Component-wise multiplication.

◆ operator*() [2/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, N > operator* ( Vector< T, N lhs,
U  rhs 
)
related

Right scalar multiplication.

◆ operator*() [3/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, N > operator* ( T  lhs,
Vector< U, N rhs 
)
related

Left scalar multiplication.

◆ operator*=() [1/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator*= ( Vector< T, N > &  lhs,
Vector< U, N rhs 
)
related

Component-wise multiplication and assignment.

◆ operator*=() [2/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator*= ( Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar multiplication and assignment.

◆ operator+() [1/3]

template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, N > operator+ ( Vector< T, N lhs,
Vector< U, N rhs 
)
related

Component-wise addition.

◆ operator+() [2/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, N > operator+ ( Vector< T, N lhs,
U  rhs 
)
related

Right scalar addition.

◆ operator+() [3/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, N > operator+ ( T  lhs,
Vector< U, N rhs 
)
related

Left scalar addition.

◆ operator+=() [1/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator+= ( Vector< T, N > &  lhs,
Vector< U, N rhs 
)
related

Component-wise addition and assignment.

◆ operator+=() [2/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator+= ( Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar addition and assignment.

◆ operator-() [1/4]

template<typename T , std::size_t N>
Vector< T, N > operator- ( Vector< T, N val)
related

Component-wise unary minus.

◆ operator-() [2/4]

template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, N > operator- ( Vector< T, N lhs,
Vector< U, N rhs 
)
related

Component-wise substraction.

◆ operator-() [3/4]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, N > operator- ( Vector< T, N lhs,
U  rhs 
)
related

Right scalar substraction.

◆ operator-() [4/4]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, N > operator- ( T  lhs,
Vector< U, N rhs 
)
related

Left scalar substraction.

◆ operator-=() [1/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator-= ( Vector< T, N > &  lhs,
Vector< U, N rhs 
)
related

Component-wise substraction and assignment.

◆ operator-=() [2/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator-= ( Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar substraction and assignment.

◆ operator/() [1/3]

template<typename T , typename U , std::size_t N>
Vector< typename std::common_type< T, U >::type, N > operator/ ( Vector< T, N lhs,
Vector< U, N rhs 
)
related

Component-wise division.

◆ operator/() [2/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<U>::value, U>::type>
Vector< typename std::common_type< T, U >::type, N > operator/ ( Vector< T, N lhs,
U  rhs 
)
related

Right scalar division.

◆ operator/() [3/3]

template<typename T , typename U , std::size_t N, typename E = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
Vector< typename std::common_type< T, U >::type, N > operator/ ( T  lhs,
Vector< U, N rhs 
)
related

Left scalar division.

◆ operator/=() [1/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator/= ( Vector< T, N > &  lhs,
Vector< U, N rhs 
)
related

Component-wise division and assignment.

◆ operator/=() [2/2]

template<typename T , typename U , std::size_t N>
Vector< T, N > & operator/= ( Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar division and assignment.

◆ operator==()

template<typename T , std::size_t N>
bool operator== ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Equality operator between two vectors.

◆ operator||()

template<std::size_t N>
Vector< bool, N > operator|| ( Vector< bool, N lhs,
Vector< bool, N rhs 
)
related

Component-wise logical or operator.

◆ perp()

template<typename T >
constexpr Vector< T, 2 > perp ( Vector< T, 2 >  vec)
related

Perpendicular vector.

The perpendicular vector \( \mathbf{u}^{\perp} \) of vector \( \mathbf{u} = (x, y) \) is:

\[ \mathbf{u}^{\perp} = (-y, x) \]

Parameters
vecA vector
Returns
A perpendicular vector

◆ select()

template<typename T , std::size_t N>
Vector< T, N > select ( Vector< bool, N cond,
Vector< T, N lhs,
Vector< T, N rhs 
)
related

Component-wise selection operator.

◆ squareDistance()

template<typename T , std::size_t N>
T squareDistance ( Vector< T, N lhs,
Vector< T, N rhs 
)
related

Square Euclidean distance between two vectors.

The square Euclidean distance between two vectors is the square Euclidean length of the difference of the two vectors.

Parameters
lhsA first vector
rhsA second vector
Returns
The square Euclidean distance between the two vectors
See also
squareLength(), euclideanDistance()

◆ squareLength()

template<typename T , std::size_t N>
T squareLength ( Vector< T, N vec)
related

Square Euclidean length of a vector.

The square Euclidean length \( \|\mathbf{u}\|_2^2 \) of a vector \( \mathbf{u} = (u_1, \ldots, u_N) \) is:

\[ \|\mathbf{u}\|_2^2 = \sum_{i = 1}^{N} u_i^2 \]

Parameters
vecA vector.
Returns
The square Euclidean length of the vector
See also
euclideanLength(), squareDistance()

◆ unit()

template<typename T >
Vector< T, 2 > unit ( T  angle)
related

Unit vector in a specified direction.

Parameters
angleThe angle of the direction
Returns
A unit vector

◆ vectorTripleProduct()

template<typename T >
Vector< T, 2 > vectorTripleProduct ( Vector< T, 2 >  a,
Vector< T, 2 >  b,
Vector< T, 2 >  c 
)
related

Regular vector triple product.

The regular vector triple product of vectors \( \mathbf{a} \), \( \mathbf{b} \) and \( \mathbf{c} \) is:

\[ \mathbf{a} \times (\mathbf{b} \times \mathbf{c}) = (\mathbf{a} \cdot \mathbf{c}) \mathbf{b} - (\mathbf{a} \cdot \mathbf{b}) \mathbf{c} \]

See also
inverseVectorTripleProduct()

Member Data Documentation

◆ data

template<typename T, std::size_t N>
T gf::Vector< T, N >::data[N]

The internal representation of the vector.

A vector is represented with an array of N values of type T. It can be accessed directly, like an array or like a pointer, which can ease interoperability with other libraries.