Gamedev Framework (gf)  0.2.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 (void)
 Iterator.to the first element. More...
 
Tend (void)
 Iterator to the element after the last one. More...
 
T const * begin (void) const
 Iterator.to the first element (const version). More...
 
T const * end (void) const
 Iterator on the element after the last one (const version). More...
 
T const * cbegin (void) const
 Iterator.on the first element (const version). More...
 
T const * cend (void) 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== (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Equality operator between two vectors. More...
 
template<typename T , std::size_t N>
bool operator!= (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Inequality operator between two vectors. More...
 
template<typename T , std::size_t N>
Vector< T, Noperator- (const 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,
N
operator+ (const Vector< T, N > &lhs, const 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, const 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,
N
operator+ (const Vector< T, N > &lhs, U rhs)
 Right scalar addition. 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,
N
operator+ (T lhs, const 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,
N
operator- (const Vector< T, N > &lhs, const 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, const 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,
N
operator- (const Vector< T, N > &lhs, U rhs)
 Right scalar substraction. 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,
N
operator- (T lhs, const 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,
N
operator* (const Vector< T, N > &lhs, const 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, const 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,
N
operator* (const 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,
N
operator* (T lhs, const 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,
N
operator/ (const Vector< T, N > &lhs, const 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, const 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,
N
operator/ (const 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,
N
operator/ (T lhs, const Vector< U, N > &rhs)
 Left scalar division. More...
 
template<std::size_t N>
Vector< bool, Noperator|| (const Vector< bool, N > &lhs, const Vector< bool, N > &rhs)
 Component-wise logical or operator. More...
 
template<std::size_t N>
Vector< bool, Noperator&& (const Vector< bool, N > &lhs, const Vector< bool, N > &rhs)
 Component-wise logical and operator. More...
 
template<typename T , std::size_t N>
T dot (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Scalar product. More...
 
template<typename T , std::size_t N>
Vector< T, Nmin (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise minimum. More...
 
template<typename T , std::size_t N>
Vector< T, Nmax (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise maximum. More...
 
template<typename T , std::size_t N>
Vector< T, Nabs (const Vector< T, N > &val)
 Component-wise absolute value. More...
 
template<typename T , std::size_t N>
Vector< bool, Nequals (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise equality operator. More...
 
template<typename T , std::size_t N>
Vector< bool, NlessThan (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise comparison operator. More...
 
template<typename T , std::size_t N>
Vector< bool, NgreaterThan (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise comparison operator. More...
 
template<typename T , std::size_t N>
Vector< T, Nselect (const Vector< bool, N > &cond, const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Component-wise selection operator. More...
 
template<typename T , std::size_t N>
Vector< T, Nclamp (const Vector< T, N > &val, const Vector< T, N > &lo, const Vector< T, N > &hi)
 Component-wise clamp function. More...
 
template<typename T , std::size_t N>
Vector< T, Nclamp (const Vector< T, N > &val, T lo, T hi)
 Component-wise clamp function. More...
 
template<typename T , typename U , std::size_t N>
Vector< typename
std::common_type< T, U >::type,
N
lerp (const Vector< T, N > &lhs, const Vector< T, N > &rhs, U t)
 Component-wise lerp function. More...
 
template<typename T , std::size_t N>
T manhattanLength (const Vector< T, N > &vec)
 Manhattan length of a vector. More...
 
template<typename T , std::size_t N>
T squareLength (const Vector< T, N > &vec)
 Square Euclidean length of a vector. More...
 
template<typename T , std::size_t N>
T euclideanLength (const Vector< T, N > &vec)
 Euclidean length of a vector. More...
 
template<typename T , std::size_t N>
T chebyshevLength (const Vector< T, N > &vec)
 Chebyshev length of a vector. More...
 
template<typename T , std::size_t N>
T manhattanDistance (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Manhattan distance between two vectors. More...
 
template<typename T , std::size_t N>
T squareDistance (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Square Euclidean distance between two vectors. More...
 
template<typename T , std::size_t N>
T euclideanDistance (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Euclidean distance between two vectors. More...
 
template<typename T , std::size_t N>
T chebyshevDistance (const Vector< T, N > &lhs, const Vector< T, N > &rhs)
 Chebyshev distance between two vectors. More...
 
template<typename T , std::size_t N>
Vector< T, Nnormalize (const 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 >
constexpr Vector< T, 2 > perp (const Vector< T, 2 > &vec)
 Perpendicular vector. More...
 
template<typename T >
constexpr Vector< T, 3 > cross (const Vector< T, 3 > &lhs, const Vector< T, 3 > &rhs)
 Cross product. 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

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.

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
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
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.
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
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

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

Iterator.to the first element.

Returns
A pointer to the first element.
template<typename T, std::size_t N>
T const* gf::Vector< T, N >::begin ( void  ) const
inline

Iterator.to the first element (const version).

Returns
A pointer on the first const element.
template<typename T, std::size_t N>
T const* gf::Vector< T, N >::cbegin ( void  ) const
inline

Iterator.on the first element (const version).

Returns
A pointer on the first const element.
template<typename T, std::size_t N>
T const* gf::Vector< T, N >::cend ( void  ) 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.
template<typename T, std::size_t N>
T* gf::Vector< T, N >::end ( void  )
inline

Iterator to the element after the last one.

Returns
An invalid pointer that is the adress after the last element.
template<typename T, std::size_t N>
T const* gf::Vector< T, N >::end ( void  ) 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.
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.

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
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

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

Component-wise absolute value.

template<typename T , std::size_t N>
T chebyshevDistance ( const Vector< T, N > &  lhs,
const 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()
template<typename T , std::size_t N>
T chebyshevLength ( const Vector< T, N > &  vec)
related

Chebyshev length of a vector.

The Chebyshev length \( l \) of a vector \( (u_1, \ldots, u_N) \) is:

\[ l = \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()
template<typename T , std::size_t N>
Vector< T, N > clamp ( const Vector< T, N > &  val,
const Vector< T, N > &  lo,
const Vector< T, N > &  hi 
)
related

Component-wise clamp function.

Relative to two other vectors.

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

Component-wise clamp function.

Relative to two values.

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

Cross product.

Parameters
lhsA first vector
rhsA second vector
Returns
The cross product of the two vectors
template<typename T , std::size_t N>
T dot ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Scalar product.

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

Component-wise equality operator.

template<typename T , std::size_t N>
T euclideanDistance ( const Vector< T, N > &  lhs,
const 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()
template<typename T , std::size_t N>
T euclideanLength ( const Vector< T, N > &  vec)
related

Euclidean length of a vector.

The Euclidean length \( l \) of a vector \( (u_1, \ldots, u_N) \) is:

\[ l = \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()
template<typename T , std::size_t N>
Vector< bool, N > greaterThan ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Component-wise comparison operator.

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

Component-wise lerp function.

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

Component-wise comparison operator.

template<typename T , std::size_t N>
T manhattanDistance ( const Vector< T, N > &  lhs,
const 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()
template<typename T , std::size_t N>
T manhattanLength ( const Vector< T, N > &  vec)
related

Manhattan length of a vector.

The Manhattan length \( l \) of a vector \( (u_1, \ldots, u_N) \) is:

\[ l = \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()
template<typename T , std::size_t N>
Vector< T, N > max ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Component-wise maximum.

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

Component-wise minimum.

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

Normalize a vector.

The normalized vector of \( v \) is a vector in the same direction but with a (euclidean) length of 1. A normalized vector is also called a unit vector.

Parameters
vecA vector
Returns
A normalized vector
template<typename T , std::size_t N>
bool operator!= ( const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Inequality operator between two vectors.

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

Component-wise logical and operator.

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

Component-wise multiplication.

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* ( const Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar multiplication.

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,
const Vector< U, N > &  rhs 
)
related

Left scalar multiplication.

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

Component-wise multiplication and assignment.

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.

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

Component-wise addition.

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+ ( const Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar addition.

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,
const Vector< U, N > &  rhs 
)
related

Left scalar addition.

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

Component-wise addition and assignment.

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

Component-wise unary minus.

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

Component-wise substraction.

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- ( const Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar substraction.

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,
const Vector< U, N > &  rhs 
)
related

Left scalar substraction.

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

Component-wise substraction and assignment.

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

Component-wise division.

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/ ( const Vector< T, N > &  lhs,
U  rhs 
)
related

Right scalar division.

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,
const Vector< U, N > &  rhs 
)
related

Left scalar division.

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

Component-wise division and assignment.

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.

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

Equality operator between two vectors.

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

Component-wise logical or operator.

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

Perpendicular vector.

Parameters
vecA vector
Returns
A perpendicular vector
template<typename T , std::size_t N>
Vector< T, N > select ( const Vector< bool, N > &  cond,
const Vector< T, N > &  lhs,
const Vector< T, N > &  rhs 
)
related

Component-wise selection operator.

template<typename T , std::size_t N>
T squareDistance ( const Vector< T, N > &  lhs,
const 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()
template<typename T , std::size_t N>
T squareLength ( const Vector< T, N > &  vec)
related

Square Euclidean length of a vector.

The square Euclidean length \( l \) of a vector \( (u_1, \ldots, u_N) \) is:

\[ l = \sum_{i = 1}^{N} u_i^2 \]

Parameters
vecA vector.
Returns
The square Euclidean length of the vector
See also
euclideanLength(), squareDistance()
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

Member Data Documentation

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.