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

Detailed Description

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

Efficient, generic implementation of a 3-dimensional vector.

The Vector3 class is the representation of a 3D vector with a total of 3 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:

                         \f[\left(\begin{array}{*{3}{c}}
                         x & y & z \\
                         \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}{*{3}{c}}
                         0 & 1 & 2 \\
                         \end{array}\right)\f]

#include <Types.h>

+ Inheritance diagram for walberla::math::Vector3< Type >:

Public Types

typedef SqrtTrait< Type >::Type Length
 Vector length return type. More...
 
typedef Type value_type
 

Public Member Functions

 Vector3 ()=default
 
 Vector3 (Type init)
 Constructor for a homogenous initialization of all elements. More...
 
template<typename Other >
 Vector3 (Other init)
 
 Vector3 (Type x, Type y, Type z)
 Constructor for a direct initialization of all vector elements. More...
 
 Vector3 (const Type *init)
 Constructor for an array initializer. More...
 
 Vector3 (const Vector3 &v)=default
 
template<typename Other >
 Vector3 (const Vector3< Other > &v)
 Conversion constructor from different Vector3 instances. More...
 
template<typename Other >
Vector3< Type > & operator= (const Vector3< Other > &v)
 
template<typename Other >
Vector3< Type > & operator%= (const Vector3< Other > &rhs)
 
template<typename Other >
Vector3< Type > & operator+= (const Vector3< Other > &rhs)
 
template<typename Other >
Vector3< Type > & operator-= (const Vector3< Other > &rhs)
 
template<typename Other >
Vector3< Type > & operator*= (Other rhs)
 
template<typename Other >
Vector3< Type > & operator/= (Other rhs)
 
Operators
Vector3operator= (const Vector3 &v)=default
 
template<typename Other >
Vector3operator= (const Vector3< Other > &v)
 Assignment operator for different Vector3 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 Vector3< 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 Vector3< 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).

Vector3 operator- () const
 Unary minus operator for the inversion of a vector ( \( \vec{a} = -\vec{b} \)). More...
 
template<typename Other >
Vector3operator%= (const Vector3< Other > &rhs)
 Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)). More...
 
template<typename Other >
Vector3operator+= (const Vector3< Other > &rhs)
 Addition assignment operator for the addition of two vectors ( \( \vec{a}+=\vec{b} \)). More...
 
template<typename Other >
Vector3operator-= (const Vector3< Other > &rhs)
 Subtraction assignment operator for the subtraction of two vectors. More...
 
template<typename Other >
Vector3operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a vector and. More...
 
template<typename Other >
Vector3operator/= (Other rhs)
 Division assignment operator for the division of a vector by a scalar value. More...
 
template<typename Other >
Vector3< typename MathTrait< Type, Other >::High > operator% (const Vector3< Other > &rhs) const
 Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)). More...
 
template<typename Other >
Vector3< typename MathTrait< Type, Other >::High > operator+ (const Vector3< Other > &rhs) const
 Addition operator for the addition of two vectors ( \( \vec{a}=\vec{b}+\vec{c} \)). More...
 
template<typename Other >
Vector3< typename MathTrait< Type, Other >::High > operator- (const Vector3< Other > &rhs) const
 Subtraction operator for the subtraction of two vectors ( \( \vec{a}=\vec{b}-\vec{c} \)). More...
 
template<typename Other >
Vector3< 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 Vector3< Other > &rhs) const
 Multiplication operator for the scalar product (inner product) of two vectors. More...
 
template<typename Other >
Vector3< typename MathTrait< Type, Other >::High > operator/ (Other rhs) const
 Division operator for the divison 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...
 
Type max () const
 Returns maximum value. More...
 
Type min () const
 Returns minimum value. More...
 
void set (Type x, Type y, Type z)
 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...
 
Vector3< LengthgetNormalized () const
 Calculation of the normalized vector ( \(|\vec{a}|=1\)). More...
 
Vector3< LengthgetNormalizedOrZero () const
 
void reset ()
 Sets all components of the vector to 0. More...
 
Type * data ()
 
const Type * data () const
 

Private Attributes

Member variables
Type v_ [3] = {Type(), Type(), Type()}
 The three statically allocated vector elements. More...
 

Member Typedef Documentation

◆ Length

template<typename Type >
typedef SqrtTrait<Type>::Type walberla::math::Vector3< Type >::Length

Vector length return type.

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

◆ value_type

template<typename Type >
typedef Type walberla::math::Vector3< Type >::value_type

Constructor & Destructor Documentation

◆ Vector3() [1/7]

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

◆ Vector3() [2/7]

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

Constructor for a homogenous initialization of all elements.

Parameters
initInitial value for all vector elements.

◆ Vector3() [3/7]

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

◆ Vector3() [4/7]

template<typename Type >
walberla::math::Vector3< Type >::Vector3 ( Type  x,
Type  y,
Type  z 
)
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.
zThe initial value for the z-component.

◆ Vector3() [5/7]

template<typename Type >
walberla::math::Vector3< Type >::Vector3 ( 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.

◆ Vector3() [6/7]

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

◆ Vector3() [7/7]

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

Conversion constructor from different Vector3 instances.

Parameters
vVector to be copied.

Member Function Documentation

◆ data() [1/2]

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

◆ data() [2/2]

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

◆ getNormalized()

template<typename Type >
Vector3< Length > & walberla::math::Vector3< Type >::getNormalized
inline

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

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

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

The function returns the normalized vector.

Returns
The normalized vector or the original vector if vector is too small.

◆ getNormalizedOrZero()

template<typename Type >
Vector3< typename Vector3< Type >::Length > walberla::math::Vector3< Type >::getNormalizedOrZero
inline

◆ indexOfMax()

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

Returns index of absolute maximum value.

◆ indexOfMin()

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

Returns index of absolute minimum value.

◆ length()

template<typename Type >
SqrtTrait< Type >::Type walberla::math::Vector3< 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

◆ max()

template<typename Type >
Type walberla::math::Vector3< Type >::max
inline

Returns maximum value.

◆ min()

template<typename Type >
Type walberla::math::Vector3< Type >::min
inline

Returns minimum value.

◆ operator!=() [1/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector3< Type >::operator!= ( const Vector3< 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::Vector3< 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%()

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

Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).

Parameters
rhsThe right-hand-side vector for the cross product.
Returns
The cross product.

◆ operator%=() [1/2]

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

Cross product (outer product) of two vectors ( \( \vec{a}=\vec{b}\times\vec{c} \)).

Parameters
rhsThe right-hand-side vector for the cross product.
Returns
The cross product.

◆ operator%=() [2/2]

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

◆ operator*() [1/2]

template<typename Type >
template<typename Other >
MathTrait< Type, Other >::High walberla::math::Vector3< Type >::operator* ( const Vector3< 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 >
Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< 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 >
Vector3< Type > & walberla::math::Vector3< 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 >
Vector3<Type>& walberla::math::Vector3< Type >::operator*= ( Other  rhs)
inline

◆ operator+()

template<typename Type >
template<typename Other >
Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator+ ( const Vector3< 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 >
Vector3< Type > & walberla::math::Vector3< Type >::operator+= ( const Vector3< 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 >
Vector3<Type>& walberla::math::Vector3< Type >::operator+= ( const Vector3< Other > &  rhs)
inline

◆ operator-() [1/2]

template<typename Type >
Vector3< Type > walberla::math::Vector3< 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 >
Vector3< typename MathTrait< Type, Other >::High > walberla::math::Vector3< Type >::operator- ( const Vector3< 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 >
Vector3< Type > & walberla::math::Vector3< Type >::operator-= ( const Vector3< 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 >
Vector3<Type>& walberla::math::Vector3< Type >::operator-= ( const Vector3< Other > &  rhs)
inline

◆ operator/()

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

Division operator for the divison 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 >
Vector3< Type > & walberla::math::Vector3< 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 >
Vector3<Type>& walberla::math::Vector3< Type >::operator/= ( Other  rhs)
inline

◆ operator=() [1/3]

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

◆ operator=() [2/3]

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

Assignment operator for different Vector3 instances.

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

◆ operator=() [3/3]

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

◆ operator==() [1/2]

template<typename Type >
template<typename Other >
bool walberla::math::Vector3< Type >::operator== ( const Vector3< 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::Vector3< 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::Vector3< 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::Vector3< 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.

◆ reset()

template<typename Type >
void walberla::math::Vector3< Type >::reset
inline

Sets all components of the vector to 0.

◆ set()

template<typename Type >
void walberla::math::Vector3< Type >::set ( Type  x,
Type  y,
Type  z 
)
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.
zThe initial value for the z-component.

◆ sqrLength()

template<typename Type >
Type walberla::math::Vector3< 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::Vector3< Type >::v_[3] = {Type(), Type(), Type()}
private

The three statically allocated vector elements.

Access to the vector values is gained via the subscript operator. The order of the elements is

\[\left(\begin{array}{*{3}{c}} 0 & 1 & 2 \\ \end{array}\right)\]


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