PTEMS  0.1.0-dev+git.81fd0e4
PolyTopic Element Method Solver
ptems::BasicVector< T, 2 > Struct Template Reference

Vector representing a point in two-dimensional space. More...

#include <ptems/vector.hpp>

Public Types

using ConjugateType = BasicVector< typename std::conditional_t< is_complex_v< T >, T, std::complex< T > >, 2 >
 The type of the conjugate of the vector. More...
 

Public Member Functions

constexpr BasicVector ()
 Construct a zero vector. More...
 
constexpr BasicVector (T value)
 Construct a vector with all components equal to the specified value. More...
 
template<typename U >
constexpr BasicVector (const BasicVector< U, 2 > rhs)
 Construct a vector by copying the specified vector. More...
 
template<typename U >
constexpr BasicVectoroperator= (const BasicVector< U, 2 > rhs)
 Copy the specified vector to this. More...
 
constexpr BasicVectoroperator= (T rhs)
 Set all components tof vector equal to a constants. More...
 
constexpr BasicVector (T x, T y)
 Construct a vector for the specified point. More...
 
template<typename U >
constexpr BasicVectoroperator+= (const BasicVector< U, 2 > &rhs)
 Adds another 2D vector to this vector. More...
 
constexpr BasicVectoroperator+= (T rhs)
 Adds a scalar to this vector. More...
 
template<typename U >
constexpr BasicVectoroperator-= (const BasicVector< U, 2 > &rhs)
 Subtracts another 2D vector to this vector. More...
 
constexpr BasicVectoroperator-= (T rhs)
 Subtracts a scalar from this vector. More...
 
template<typename U >
constexpr BasicVectoroperator/= (U rhs)
 Divides all components of this vector by a constant. More...
 
template<typename U >
constexpr BasicVectoroperator/= (const BasicVector< U, 2 > &rhs)
 Performs elementwise division of all components of this vector by the other vector. More...
 
template<typename U >
constexpr BasicVectoroperator*= (U rhs)
 Multiplies all components of this vector by a constant. More...
 
template<typename U >
constexpr BasicVectoroperator*= (const BasicVector< U, 2 > &rhs)
 Performs elementwise multiplication of all components of this vector by the other vector. More...
 
constexpr BasicVector operator- () const
 Returns the negated vector. More...
 
constexpr BasicVectorRotateCW90 ()
 Rotates the current vector clockwise by 90 degrees. More...
 
constexpr BasicVectorRotateCCW90 ()
 Rotates the current vector counter-clockwise by 90 degrees. More...
 
BasicVectorRotateCCW (remove_complex_t< T > angle)
 Rotates the current vector counter-clockwise by the specified angle in radians. More...
 
BasicVectorRotateCW (remove_complex_t< T > angle)
 Rotates the current vector clockwise by the specified angle in radians. More...
 
constexpr BasicVector RotatedCW90 () const
 Computes a vector which is the current vector rotated clockwise by 90 degrees. More...
 
constexpr BasicVector RotatedCCW90 () const
 Computes a vector which is the current vector rotated counter-clockwise by 90 degrees. More...
 
BasicVector RotatedCCW (remove_complex_t< T > angle) const
 Computes a vector which is the current vector counter-clockwise by the specified angle in radians. More...
 
BasicVector RotatedCW (remove_complex_t< T > angle) const
 Computes a vector which is the current vector clockwise by the specified angle in radians. More...
 
template<typename U >
constexpr std::common_type_t< T, U > Dot (const BasicVector< U, 2 > &rhs) const
 Computes the dot product of this vector with the specified vector. More...
 
constexpr BasicVectorNormalise ()
 Normalises the current vector. More...
 
constexpr BasicVector Normalised () const
 Gets a new vector which is the normalised version of this vector. More...
 
template<typename U >
std::common_type_t< T, U > Wedge (const BasicVector< U, 2 > &rhs) const
 Computes the wedge product of two vectors. More...
 
template<typename U , typename = std::enable_if_t<!is_complex_v<T> && !is_complex_v<U>>>
std::common_type_t< T, U > Angle (const BasicVector< U, 2 > &rhs) const
 Computes the angle between the specified vector and the current vector. More...
 
constexpr T operator[] (std::size_t i) const
 Gets a component of the vector by index. More...
 
constexpr T & operator[] (std::size_t i)
 Gets a mutable reference to the component of the vector by index. More...
 
constexpr remove_complex_t< T > Length () const
 Computes the length of the vector. More...
 
constexpr remove_complex_t< T > LengthSquared () const
 Gets the square of the length of the vector. More...
 
ConjugateType Conjugate () const
 Computes the complex conjugate of the vector. More...
 
BasicVectorConjugateOverwrite () const
 Overwrites the vector with its complex conjugate. More...
 
std::size_t size () const
 Gets the number of elements in the vector. More...
 

Public Attributes

X
 The x-component of the vector. More...
 
Y
 The y-component of the vector. More...
 

Detailed Description

template<typename T>
struct ptems::BasicVector< T, 2 >

Vector representing a point in two-dimensional space.

Member Typedef Documentation

◆ ConjugateType

template<typename T >
using ptems::BasicVector< T, 2 >::ConjugateType = BasicVector<typename std::conditional_t<is_complex_v<T>, T, std::complex<T> >,2>

The type of the conjugate of the vector.

Will either be the same type if T is complex, otherwise a vector of std::complex<T>.

Constructor & Destructor Documentation

◆ BasicVector() [1/4]

template<typename T >
constexpr ptems::BasicVector< T, 2 >::BasicVector ( )
inlineconstexpr

Construct a zero vector.

◆ BasicVector() [2/4]

template<typename T >
constexpr ptems::BasicVector< T, 2 >::BasicVector ( value)
inlineexplicitconstexpr

Construct a vector with all components equal to the specified value.

Parameters
valueValue to fill in each component of the vector

◆ BasicVector() [3/4]

template<typename T >
template<typename U >
constexpr ptems::BasicVector< T, 2 >::BasicVector ( const BasicVector< U, 2 >  rhs)
inlineconstexpr

Construct a vector by copying the specified vector.

Template Parameters
UType of the vector to copy
Parameters
rhsVector to copy

◆ BasicVector() [4/4]

template<typename T >
constexpr ptems::BasicVector< T, 2 >::BasicVector ( x,
y 
)
inlineconstexpr

Construct a vector for the specified point.

Parameters
xThe x-component of the vector
yThe y-component of the vector

Member Function Documentation

◆ Angle()

template<typename T >
template<typename U , typename = std::enable_if_t<!is_complex_v<T> && !is_complex_v<U>>>
std::common_type_t<T,U> ptems::BasicVector< T, 2 >::Angle ( const BasicVector< U, 2 > &  rhs) const
inline

Computes the angle between the specified vector and the current vector.

Note
Not defined for complex vectors (neither T nor U can be complex)
Template Parameters
UType of the components of the vector to compute angle with
Parameters
rhsVector to compute angle with
Returns
Angle, in the range \( [-\pi,\pi] \), to rotate this vector by (counter-clockwise) to get the rhs vector.

◆ Conjugate()

template<typename T >
ConjugateType ptems::BasicVector< T, 2 >::Conjugate ( ) const
inline

Computes the complex conjugate of the vector.

Returns
The complex conjugate of the vector

◆ ConjugateOverwrite()

template<typename T >
BasicVector& ptems::BasicVector< T, 2 >::ConjugateOverwrite ( ) const
inline

Overwrites the vector with its complex conjugate.

Returns
this

◆ Dot()

template<typename T >
template<typename U >
constexpr std::common_type_t<T,U> ptems::BasicVector< T, 2 >::Dot ( const BasicVector< U, 2 > &  rhs) const
inlineconstexpr

Computes the dot product of this vector with the specified vector.

Template Parameters
UType of the components of the vector to dot product with
Parameters
rhsVector to dot product with this vector
Returns
The result of the dot product

◆ Length()

template<typename T >
constexpr remove_complex_t<T> ptems::BasicVector< T, 2 >::Length ( ) const
inlineconstexpr

Computes the length of the vector.

Returns
The vector length.

◆ LengthSquared()

template<typename T >
constexpr remove_complex_t<T> ptems::BasicVector< T, 2 >::LengthSquared ( ) const
inlineconstexpr

Gets the square of the length of the vector.

Returns
The length squared.

◆ Normalise()

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::Normalise ( )
inlineconstexpr

Normalises the current vector.

Returns
Reference to this vector after normalisation.

◆ Normalised()

template<typename T >
constexpr BasicVector ptems::BasicVector< T, 2 >::Normalised ( ) const
inlineconstexpr

Gets a new vector which is the normalised version of this vector.

Returns
The normalised vector

◆ operator*=() [1/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator*= ( const BasicVector< U, 2 > &  rhs)
inlineconstexpr

Performs elementwise multiplication of all components of this vector by the other vector.

Template Parameters
UType of the components of the vector to multiply by
Parameters
rhsVector to multiply by elementwise
Returns
Reference to this vector after multiplying by rhs

◆ operator*=() [2/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator*= ( rhs)
inlineconstexpr

Multiplies all components of this vector by a constant.

Template Parameters
UType of right hand side
Parameters
rhsConstant to multiple vector by
Returns
Reference to this vector after multiplying by rhs

◆ operator+=() [1/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator+= ( const BasicVector< U, 2 > &  rhs)
inlineconstexpr

Adds another 2D vector to this vector.

Template Parameters
UType of the components of the vector to add
Parameters
rhsVector to add
Returns
Reference to this vector after adding rhs

◆ operator+=() [2/2]

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator+= ( rhs)
inlineconstexpr

Adds a scalar to this vector.

Parameters
rhsScalar value to add
Returns
Reference to this vector after adding rhs

◆ operator-()

template<typename T >
constexpr BasicVector ptems::BasicVector< T, 2 >::operator- ( ) const
inlineconstexpr

Returns the negated vector.

Parameters
rhsVector to negate
Returns
The negated vector

◆ operator-=() [1/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator-= ( const BasicVector< U, 2 > &  rhs)
inlineconstexpr

Subtracts another 2D vector to this vector.

Template Parameters
UType of the components of the vector to subtract
Parameters
rhsVector to subtract
Returns
Reference to this vector after subtracting rhs

◆ operator-=() [2/2]

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator-= ( rhs)
inlineconstexpr

Subtracts a scalar from this vector.

Parameters
rhsScalar value to subtract
Returns
Reference to this vector after subtracting rhs

◆ operator/=() [1/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator/= ( const BasicVector< U, 2 > &  rhs)
inlineconstexpr

Performs elementwise division of all components of this vector by the other vector.

Template Parameters
UType of the components of the vector to divide by
Parameters
rhsVector to divide by elementwise
Returns
Reference to this vector after dividing by rhs

◆ operator/=() [2/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator/= ( rhs)
inlineconstexpr

Divides all components of this vector by a constant.

Template Parameters
UType of right hand side
Parameters
rhsConstant to divide vector by
Returns
Reference to this vector after dividing by rhs

◆ operator=() [1/2]

template<typename T >
template<typename U >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator= ( const BasicVector< U, 2 >  rhs)
inlineconstexpr

Copy the specified vector to this.

Template Parameters
UType of the vector to copy
Parameters
rhsVector to copy

◆ operator=() [2/2]

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::operator= ( rhs)
inlineconstexpr

Set all components tof vector equal to a constants.

Parameters
rhsScalar to set vector to

◆ operator[]() [1/2]

template<typename T >
constexpr T& ptems::BasicVector< T, 2 >::operator[] ( std::size_t  i)
inlineconstexpr

Gets a mutable reference to the component of the vector by index.

Parameters
iThe index of the component of the vector to get (must be 0 or 1).
Exceptions
std::out_of_rangeIf i is not 0 or 1.
Returns
Mutable reference to the value at the specified component

◆ operator[]() [2/2]

template<typename T >
constexpr T ptems::BasicVector< T, 2 >::operator[] ( std::size_t  i) const
inlineconstexpr

Gets a component of the vector by index.

Parameters
iThe index of the component of the vector to get (must be 0 or 1).
Exceptions
std::out_of_rangeIf i is not 0 or 1.
Returns
Value at the specified component

◆ RotateCCW()

template<typename T >
BasicVector& ptems::BasicVector< T, 2 >::RotateCCW ( remove_complex_t< T >  angle)
inline

Rotates the current vector counter-clockwise by the specified angle in radians.

Warning
This method may not make sense for vectors of complex numbers
Parameters
angleAngle to rotate by
Returns
Reference to this vector after rotation

◆ RotateCCW90()

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::RotateCCW90 ( )
inlineconstexpr

Rotates the current vector counter-clockwise by 90 degrees.

Warning
This method may not make sense for vectors of complex numbers
Returns
Reference to this vector after rotation

◆ RotateCW()

template<typename T >
BasicVector& ptems::BasicVector< T, 2 >::RotateCW ( remove_complex_t< T >  angle)
inline

Rotates the current vector clockwise by the specified angle in radians.

Warning
This method may not make sense for vectors of complex numbers
Parameters
angleAngle to rotate by
Returns
Reference to this vector after rotation

◆ RotateCW90()

template<typename T >
constexpr BasicVector& ptems::BasicVector< T, 2 >::RotateCW90 ( )
inlineconstexpr

Rotates the current vector clockwise by 90 degrees.

Warning
This method may not make sense for vectors of complex numbers
Returns
Reference to this vector after rotation

◆ RotatedCCW()

template<typename T >
BasicVector ptems::BasicVector< T, 2 >::RotatedCCW ( remove_complex_t< T >  angle) const
inline

Computes a vector which is the current vector counter-clockwise by the specified angle in radians.

Warning
This method may not make sense for vectors of complex numbers
Parameters
angleAngle to rotate by
Returns
The rotated vector

◆ RotatedCCW90()

template<typename T >
constexpr BasicVector ptems::BasicVector< T, 2 >::RotatedCCW90 ( ) const
inlineconstexpr

Computes a vector which is the current vector rotated counter-clockwise by 90 degrees.

Warning
This method may not make sense for vectors of complex numbers
Returns
The rotated vector

◆ RotatedCW()

template<typename T >
BasicVector ptems::BasicVector< T, 2 >::RotatedCW ( remove_complex_t< T >  angle) const
inline

Computes a vector which is the current vector clockwise by the specified angle in radians.

Warning
This method may not make sense for vectors of complex numbers
Parameters
angleAngle to rotate by
Returns
The rotated vector

◆ RotatedCW90()

template<typename T >
constexpr BasicVector ptems::BasicVector< T, 2 >::RotatedCW90 ( ) const
inlineconstexpr

Computes a vector which is the current vector rotated clockwise by 90 degrees.

Warning
This method may not make sense for vectors of complex numbers
Returns
The rotated vector

◆ size()

template<typename T >
std::size_t ptems::BasicVector< T, 2 >::size ( ) const
inline

Gets the number of elements in the vector.

Returns
2

◆ Wedge()

template<typename T >
template<typename U >
std::common_type_t<T,U> ptems::BasicVector< T, 2 >::Wedge ( const BasicVector< U, 2 > &  rhs) const
inline

Computes the wedge product of two vectors.

Warning
This method may not make sense for vectors of complex numbers
Template Parameters
UType of the components of the vector to wedge product with
Parameters
rhsVector to compute wedge with
Returns
Area of the parallelogram defined by the two vectors, or zero if vectors are linearly dependent

Member Data Documentation

◆ X

template<typename T >
T ptems::BasicVector< T, 2 >::X

The x-component of the vector.

◆ Y

template<typename T >
T ptems::BasicVector< T, 2 >::Y

The y-component of the vector.


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