walberla::math::Vector2< Type > Class Template Reference

Detailed Description

template<typename Type>
class walberla::math::Vector2< Type >

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
Vector2operator= (const Vector2 &v)=default
 
template<typename Other >
Vector2operator= (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 >
Vector2operator+= (const Vector2< Other > &rhs)
 Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)). More...
 
template<typename Other >
Vector2operator-= (const Vector2< Other > &rhs)
 Subtraction assignment operator for the subtraction of two vectors. More...
 
template<typename Other >
Vector2operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a vector and. More...
 
template<typename Other >
Vector2operator/= (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< LengthgetNormalized () 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...
 

Member Typedef Documentation

◆ Length

template<typename Type >
using walberla::math::Vector2< Type >::Length = typename SqrtTrait<Type>::Type

Return type of the Vector2<Type>::length function.

◆ value_type

template<typename Type >
using walberla::math::Vector2< Type >::value_type = Type

Constructor & Destructor Documentation

◆ Vector2() [1/7]

template<typename Type >
walberla::math::Vector2< Type >::Vector2 ( )
inlineexplicitdefault

◆ Vector2() [2/7]

template<typename Type >
walberla::math::Vector2< Type >::Vector2 ( Type  init)
inlineexplicit

Constructor for a homogenous initialization of all elements.

Parameters
initInitial value for all vector elements.

◆ Vector2() [3/7]

template<typename Type >
template<typename Other >
walberla::math::Vector2< Type >::Vector2 ( Other  init)
inlineexplicit

◆ Vector2() [4/7]

template<typename Type >
walberla::math::Vector2< Type >::Vector2 ( Type  x,
Type  y 
)
inlineexplicit

Constructor for a direct initialization of all vector elements.

Parameters
xThe initial value for the x-component.
yThe initial value for the y-component.

◆ Vector2() [5/7]

template<typename Type >
walberla::math::Vector2< Type >::Vector2 ( const Type *  init)
inlineexplicit

Constructor for an array initializer.

Parameters
initPointer to the initialization array.

The array is assumed to have at least three valid elements.

◆ Vector2() [6/7]

template<typename Type >
walberla::math::Vector2< Type >::Vector2 ( const Vector2< Type > &  v)
inlinedefault

◆ Vector2() [7/7]

template<typename Type >
template<typename Other >
walberla::math::Vector2< Type >::Vector2 ( const Vector2< Other > &  v)
inline

Conversion constructor from different Vector2 instances.

Parameters
vVector to be copied.

Member Function Documentation

◆ data() [1/2]

template<typename Type >
Type* walberla::math::Vector2< Type >::data ( )
inline

◆ data() [2/2]

template<typename Type >
const Type* walberla::math::Vector2< Type >::data ( ) const
inline

◆ getNormalized()

template<typename Type >
Vector2< typename Vector2< Type >::Length > walberla::math::Vector2< Type >::getNormalized
inline

Calculation of the normalized vector ( \(|\vec{a}|=1\)).

Precondition
\(|\vec{a}|\neq0\)
Returns
The normalized vector.

The function returns the normalized vector.

◆ indexOfMax()

template<typename Type >
uint_t walberla::math::Vector2< Type >::indexOfMax
inline

Returns index of absolute maximum value.

◆ indexOfMin()

template<typename Type >
uint_t walberla::math::Vector2< Type >::indexOfMin
inline

Returns index of absolute minimum value.

◆ length()

template<typename Type >
SqrtTrait< Type >::Type walberla::math::Vector2< Type >::length
inline

Calculation of the vector length \(|\vec{a}|\).

Returns
The length of the vector.

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

◆ operator!=() [1/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector2< Type >::operator!= ( const Vector2< Other > &  rhs) const
inline

Inequality operator for the comparison of two vectors.

Parameters
rhsThe right-hand-side vector for the comparison.
Returns
bool

◆ operator!=() [2/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector2< Type >::operator!= ( Other  rhs) const
inline

Inequality operator for the comparison of a vector and a scalar value.

Parameters
rhsThe right-hand-side scalar value for the comparison.
Returns
bool

If one value of the vector is inequal to the scalar value, the inequality test returns true, otherwise false.

◆ operator*() [1/2]

template<typename Type >
template<typename Other >
MathTrait< Type, Other >::High walberla::math::Vector2< Type >::operator* ( const Vector2< Other > &  rhs) const
inline

Multiplication operator for the scalar product (inner product) of two vectors.

( \( s=\vec{a}*\vec{b} \)).

Parameters
rhsThe right-hand-side vector for the inner product.
Returns
The scalar 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 ).

◆ operator*() [2/2]

template<typename Type >
template<typename Other >
Vector2< typename MathTrait< Type, Other >::High > walberla::math::Vector2< Type >::operator* ( Other  rhs) const
inline

Multiplication operator for the multiplication of a vector and a scalar value.

( \( \vec{a}=\vec{b}*s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
The scaled result vector.

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

◆ operator*=() [1/2]

template<typename Type >
template<typename Other >
Vector2< Type > & walberla::math::Vector2< Type >::operator*= ( Other  rhs)
inline

Multiplication assignment operator for the multiplication between a vector and.

a scalar value ( \( \vec{a}*=s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
Reference to the vector.

◆ operator*=() [2/2]

template<typename Type >
template<typename Other >
Vector2<Type>& walberla::math::Vector2< Type >::operator*= ( Other  rhs)
inline

◆ operator+()

template<typename Type >
template<typename Other >
Vector2< typename MathTrait< Type, Other >::High > walberla::math::Vector2< Type >::operator+ ( const Vector2< Other > &  rhs) const
inline

Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)).

Parameters
rhsThe right-hand-side vector to be added to the vector.
Returns
The sum of the two vectors.

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

◆ operator+=() [1/2]

template<typename Type >
template<typename Other >
Vector2< Type > & walberla::math::Vector2< Type >::operator+= ( const Vector2< Other > &  rhs)
inline

Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)).

Parameters
rhsThe right-hand-side vector to be added to the vector.
Returns
Reference to the vector.

◆ operator+=() [2/2]

template<typename Type >
template<typename Other >
Vector2<Type>& walberla::math::Vector2< Type >::operator+= ( const Vector2< Other > &  rhs)
inline

◆ operator-() [1/2]

template<typename Type >
Vector2< Type > walberla::math::Vector2< Type >::operator-
inline

Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)).

Returns
The inverse of the vector.

◆ operator-() [2/2]

template<typename Type >
template<typename Other >
Vector2< typename MathTrait< Type, Other >::High > walberla::math::Vector2< Type >::operator- ( const Vector2< Other > &  rhs) const
inline

Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)).

Parameters
rhsThe right-hand-side vector to be subtracted from the vector.
Returns
The difference of the two vectors.

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

◆ operator-=() [1/2]

template<typename Type >
template<typename Other >
Vector2< Type > & walberla::math::Vector2< Type >::operator-= ( const Vector2< Other > &  rhs)
inline

Subtraction assignment operator for the subtraction of two vectors.

( \( \vec{a}-=\vec{b} \)).

Parameters
rhsThe right-hand-side vector to be subtracted from the vector.
Returns
Reference to the vector.

◆ operator-=() [2/2]

template<typename Type >
template<typename Other >
Vector2<Type>& walberla::math::Vector2< Type >::operator-= ( const Vector2< Other > &  rhs)
inline

◆ operator/()

template<typename Type >
template<typename Other >
Vector2< typename MathTrait< Type, Other >::High > walberla::math::Vector2< Type >::operator/ ( Other  rhs) const
inline

Division operator for the division of a vector by a scalar value.

( \( \vec{a}=\vec{b}/s \)).

Parameters
rhsThe right-hand-side scalar value for the division.
Returns
The scaled result vector.

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.

◆ operator/=() [1/2]

template<typename Type >
template<typename Other >
Vector2< Type > & walberla::math::Vector2< Type >::operator/= ( Other  rhs)
inline

Division assignment operator for the division of a vector by a scalar value.

( \( \vec{a}/=s \)).

Parameters
rhsThe right-hand-side scalar value for the division.
Returns
Reference to the vector.

Note: No check for 0 is applied.

◆ operator/=() [2/2]

template<typename Type >
template<typename Other >
Vector2<Type>& walberla::math::Vector2< Type >::operator/= ( Other  rhs)
inline

◆ operator=() [1/3]

template<typename Type >
Vector2& walberla::math::Vector2< Type >::operator= ( const Vector2< Type > &  v)
inlinedefault

◆ operator=() [2/3]

template<typename Type >
template<typename Other >
Vector2< Type > & walberla::math::Vector2< Type >::operator= ( const Vector2< Other > &  v)
inline

Assignment operator for different Vector2 instances.

Parameters
vVector to be copied.
Returns
Reference to the assigned vector.

◆ operator=() [3/3]

template<typename Type >
template<typename Other >
Vector2<Type>& walberla::math::Vector2< Type >::operator= ( const Vector2< Other > &  v)
inline

◆ operator==() [1/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector2< Type >::operator== ( const Vector2< Other > &  rhs) const
inline

Equality operator for the comparison of two vectors.

Parameters
rhsThe right-hand-side vector for the comparison.
Returns
bool

◆ operator==() [2/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector2< Type >::operator== ( Other  rhs) const
inline

Equality operator for the comparison of a vector and a scalar value.

Parameters
rhsThe right-hand-side scalar value for the comparison.
Returns
bool

If all values of the vector are equal to the scalar value, the equality test returns true, otherwise false.

◆ operator[]() [1/2]

template<typename Type >
Type & walberla::math::Vector2< Type >::operator[] ( uint_t  index)
inline

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range \([0..2]\).
Returns
Reference to the accessed value.

◆ operator[]() [2/2]

template<typename Type >
const Type & walberla::math::Vector2< Type >::operator[] ( uint_t  index) const
inline

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range \([0..2]\).
Returns
Reference-to-const to the accessed value.

◆ set()

template<typename Type >
void walberla::math::Vector2< Type >::set ( Type  x,
Type  y 
)
inline

Set function for a direct assignment of all vector elements.

Parameters
xThe initial value for the x-component.
yThe initial value for the y-component.

◆ sqrLength()

template<typename Type >
Type walberla::math::Vector2< Type >::sqrLength
inline

Calculation of the vector square length \(|\vec{a}|^2\).

Returns
The square length of the vector.

Member Data Documentation

◆ v_

template<typename Type >
Type walberla::math::Vector2< Type >::v_[2] = {Type(), Type()}
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)\]


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