Efficient, generic implementation of a 2-dimensional vector.
The Vector2 class is the representation of a 2D vector with a total of 2 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:
\f[\left(\begin{array}{*{2}{c}} x & y \\ \end{array}\right)\f]
These elements can be accessed directly with the subscript operator. The numbering of the vector elements is
\f[\left(\begin{array}{*{2}{c}} 0 & 1 \\ \end{array}\right)\f]
#include <Types.h>
Public Types | |
using | Length = typename SqrtTrait< Type >::Type |
Return type of the Vector2<Type>::length function. More... | |
using | value_type = Type |
Public Member Functions | |
Vector2 ()=default | |
Vector2 (Type init) | |
Constructor for a homogenous initialization of all elements. More... | |
template<typename Other > | |
Vector2 (Other init) | |
Vector2 (Type x, Type y) | |
Constructor for a direct initialization of all vector elements. More... | |
Vector2 (const Type *init) | |
Constructor for an array initializer. More... | |
Vector2 (const Vector2 &v)=default | |
template<typename Other > | |
Vector2 (const Vector2< Other > &v) | |
Conversion constructor from different Vector2 instances. More... | |
template<typename Other > | |
Vector2< Type > & | operator= (const Vector2< Other > &v) |
template<typename Other > | |
Vector2< Type > & | operator+= (const Vector2< Other > &rhs) |
template<typename Other > | |
Vector2< Type > & | operator-= (const Vector2< Other > &rhs) |
template<typename Other > | |
Vector2< Type > & | operator*= (Other rhs) |
template<typename Other > | |
Vector2< Type > & | operator/= (Other rhs) |
Operators | |
Vector2 & | operator= (const Vector2 &v)=default |
template<typename Other > | |
Vector2 & | operator= (const Vector2< Other > &v) |
Assignment operator for different Vector2 instances. More... | |
template<typename Other > | |
bool | operator== (Other rhs) const |
Equality operator for the comparison of a vector and a scalar value. More... | |
template<typename Other > | |
bool | operator== (const Vector2< Other > &rhs) const |
Equality operator for the comparison of two vectors. More... | |
template<typename Other > | |
bool | operator!= (Other rhs) const |
Inequality operator for the comparison of a vector and a scalar value. More... | |
template<typename Other > | |
bool | operator!= (const Vector2< Other > &rhs) const |
Inequality operator for the comparison of two vectors. More... | |
Type & | operator[] (uint_t index) |
Subscript operator for the direct access to the vector elements. More... | |
const Type & | operator[] (uint_t index) const |
Subscript operator for the direct access to the vector elements. More... | |
Arithmetic operators | |
The return type of the arithmetic operators depends on the involved data types of the vectors. HIGH denotes the more significant data type of the arithmetic operation (for further detail see the MathTrait class description). | |
Vector2 | operator- () const |
Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)). More... | |
template<typename Other > | |
Vector2 & | operator+= (const Vector2< Other > &rhs) |
Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)). More... | |
template<typename Other > | |
Vector2 & | operator-= (const Vector2< Other > &rhs) |
Subtraction assignment operator for the subtraction of two vectors. More... | |
template<typename Other > | |
Vector2 & | operator*= (Other rhs) |
Multiplication assignment operator for the multiplication between a vector and. More... | |
template<typename Other > | |
Vector2 & | operator/= (Other rhs) |
Division assignment operator for the division of a vector by a scalar value. More... | |
template<typename Other > | |
Vector2< typename MathTrait< Type, Other >::High > | operator+ (const Vector2< Other > &rhs) const |
Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)). More... | |
template<typename Other > | |
Vector2< typename MathTrait< Type, Other >::High > | operator- (const Vector2< Other > &rhs) const |
Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)). More... | |
template<typename Other > | |
Vector2< typename MathTrait< Type, Other >::High > | operator* (Other rhs) const |
Multiplication operator for the multiplication of a vector and a scalar value. More... | |
template<typename Other > | |
MathTrait< Type, Other >::High | operator* (const Vector2< Other > &rhs) const |
Multiplication operator for the scalar product (inner product) of two vectors. More... | |
template<typename Other > | |
Vector2< typename MathTrait< Type, Other >::High > | operator/ (Other rhs) const |
Division operator for the division of a vector by a scalar value. More... | |
Utility functions | |
uint_t | indexOfMax () const |
Returns index of absolute maximum value. More... | |
uint_t | indexOfMin () const |
Returns index of absolute minimum value. More... | |
void | set (Type x, Type y) |
Set function for a direct assignment of all vector elements. More... | |
Length | length () const |
Calculation of the vector length \(|\vec{a}|\). More... | |
Type | sqrLength () const |
Calculation of the vector square length \(|\vec{a}|^2\). More... | |
Vector2< Length > | getNormalized () const |
Calculation of the normalized vector ( \(|\vec{a}|=1\)). More... | |
Type * | data () |
const Type * | data () const |
Private Attributes | |
Member variables | |
Type | v_ [2] = {Type(), Type()} |
The two statically allocated vector elements. More... | |
using walberla::math::Vector2< Type >::Length = typename SqrtTrait<Type>::Type |
Return type of the Vector2<Type>::length function.
using walberla::math::Vector2< Type >::value_type = Type |
|
inlineexplicitdefault |
|
inlineexplicit |
Constructor for a homogenous initialization of all elements.
init | Initial value for all vector elements. |
|
inlineexplicit |
|
inlineexplicit |
Constructor for a direct initialization of all vector elements.
x | The initial value for the x-component. |
y | The initial value for the y-component. |
|
inlineexplicit |
Constructor for an array initializer.
init | Pointer to the initialization array. |
The array is assumed to have at least three valid elements.
|
inlinedefault |
|
inline |
Conversion constructor from different Vector2 instances.
v | Vector to be copied. |
|
inline |
|
inline |
|
inline |
Calculation of the normalized vector ( \(|\vec{a}|=1\)).
The function returns the normalized vector.
|
inline |
Returns index of absolute maximum value.
|
inline |
Returns index of absolute minimum value.
|
inline |
Calculation of the vector length \(|\vec{a}|\).
The return type of the length function depends on the actual type of the vector instance:
Type | Length |
float | float |
integral data types and double | double |
long double | long double |
|
inline |
Inequality operator for the comparison of two vectors.
rhs | The right-hand-side vector for the comparison. |
|
inline |
Inequality operator for the comparison of a vector and a scalar value.
rhs | The right-hand-side scalar value for the comparison. |
If one value of the vector is inequal to the scalar value, the inequality test returns true, otherwise false.
|
inline |
Multiplication operator for the scalar product (inner product) of two vectors.
( \( s=\vec{a}*\vec{b} \)).
rhs | The right-hand-side vector for the inner product. |
The operator returns a scalar value of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
|
inline |
Multiplication operator for the multiplication of a vector and a scalar value.
( \( \vec{a}=\vec{b}*s \)).
rhs | The right-hand-side scalar value for the multiplication. |
The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
|
inline |
Multiplication assignment operator for the multiplication between a vector and.
a scalar value ( \( \vec{a}*=s \)).
rhs | The right-hand-side scalar value for the multiplication. |
|
inline |
|
inline |
Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)).
rhs | The right-hand-side vector to be added to the vector. |
The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).
|
inline |
Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)).
rhs | The right-hand-side vector to be added to the vector. |
|
inline |
|
inline |
Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)).
|
inline |
Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)).
rhs | The right-hand-side vector to be subtracted from the vector. |
The operator returns a vector of the higher-order data type of the two involved vector data types (in fact the two template arguments Type and Other ).
|
inline |
Subtraction assignment operator for the subtraction of two vectors.
( \( \vec{a}-=\vec{b} \)).
rhs | The right-hand-side vector to be subtracted from the vector. |
|
inline |
|
inline |
Division operator for the division of a vector by a scalar value.
( \( \vec{a}=\vec{b}/s \)).
rhs | The right-hand-side scalar value for the division. |
The operator returns a vector of the higher-order data type of the two involved data types (in fact the two template arguments Type and Other ).
Note: No check for 0 is applied.
|
inline |
Division assignment operator for the division of a vector by a scalar value.
( \( \vec{a}/=s \)).
rhs | The right-hand-side scalar value for the division. |
Note: No check for 0 is applied.
|
inline |
|
inlinedefault |
|
inline |
Assignment operator for different Vector2 instances.
v | Vector to be copied. |
|
inline |
|
inline |
Equality operator for the comparison of two vectors.
rhs | The right-hand-side vector for the comparison. |
|
inline |
Equality operator for the comparison of a vector and a scalar value.
rhs | The right-hand-side scalar value for the comparison. |
If all values of the vector are equal to the scalar value, the equality test returns true, otherwise false.
|
inline |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range \([0..2]\). |
|
inline |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range \([0..2]\). |
|
inline |
Set function for a direct assignment of all vector elements.
x | The initial value for the x-component. |
y | The initial value for the y-component. |
|
inline |
Calculation of the vector square length \(|\vec{a}|^2\).
|
private |
The two statically allocated vector elements.
Access to the vector values is gained via the subscript operator. The order of the elements is
\[\left(\begin{array}{*{2}{c}} 0 & 1 \\ \end{array}\right)\]