mu
mu::Vector2D< T > Class Template Reference

A two dimensional vector. More...

#include <vector2d.h>

Inheritance diagram for mu::Vector2D< T >:
Collaboration diagram for mu::Vector2D< T >:

Public Member Functions

template<class Tt = T>
 Vector2D (const Vector< 2, Tt > &other)
 Construct a new Vector2D object from a Vector object. More...
 
T & x () noexcept
 x component More...
 
const T & x () const noexcept
 const x component More...
 
T & y () noexcept
 y component More...
 
const T & y () const noexcept
 const y component More...
 
template<class TScalar = T>
std::enable_if_t< std::is_arithmetic< TScalar >::value, void > rotate (TScalar angle)
 rotates this Vector by an angle [rad] More...
 
template<class TScalar = T>
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector2D< T > > rotated (TScalar angle)
 returns a Vector2D that is rotated by an angle [rad] More...
 
- Public Member Functions inherited from mu::Vector< 2, T >
constexpr Vector ()=default
 Construct a new Vector object. More...
 
 Vector (TArgs &&... args)
 Construct a new Vector object from a number of N values. More...
 
 Vector (const Vector< Nn, U > &v)
 Construct a new Vector from an existing Vector of a different type. More...
 
 Vector (const std::array< T, N > &a)
 Construct a new Vector object from an std::array. More...
 
 Vector (const std::array< U, N > &a)
 Construct a new Vector object from an std::array of a different type. More...
 
 Vector (const U &value)
 Construct a new Vector object from a single value. More...
 
 Vector (const Vector &other)=default
 Copy construct a new Vector object. More...
 
 Vector (Vector &&other) noexcept=default
 Move construct a new Vector object. More...
 
 ~Vector ()=default
 Destroy the Vector object.
 
Vectoroperator= (const Vector &other)=default
 Copy assignment operator. More...
 
Vectoroperator= (Vector &&other) noexcept=default
 Move assignment operator. More...
 
T & operator[] (size_type idx) noexcept
 access an element within the vector More...
 
const T & operator[] (size_type idx) const noexcept
 const access an element within the vector More...
 
T & at (size_type idx)
 access an element within the vector More...
 
const T & at (size_type idx) const
 const access an element within the vector More...
 
constexpr size_type size () const noexcept
 returns the size of the vector More...
 
iterator begin () noexcept
 returns an iterator pointing to the first element More...
 
const_iterator begin () const noexcept
 returns a const iterator pointing to the first element More...
 
iterator end () noexcept
 returns an iterator pointing to the element following the last element More...
 
const_iterator end () const noexcept
 returns a const iterator pointing to the element following the last element More...
 
min () const
 get the min value of the vector More...
 
max () const
 get the max value of the vector More...
 
sum () const
 sum up all the elements of the vector More...
 
mean () const
 mean of all the elements of the vector More...
 
std::conditional_t< std::is_same< U, void >::value, T, U > dot (const Vector< N2, T2 > &rhs) const
 dot product of two vectors More...
 
std::conditional_t< std::is_same< U, void >::value, Vector< M2, T >, Vector< M2, U > > dot (const Matrix< N2, M2, T2 > &rhs) const
 dot product of a vector and a matrix More...
 
std () const
 calculates the standard deviation More...
 
length () const
 euclidean vector length More...
 
void normalize ()
 normalizes this vector More...
 
Vector< N, T > normalized ()
 returns a normalized vector More...
 
void flip ()
 flips this vector, i.e. reverses its elements More...
 
Vector< N, T > flipped () const
 returns a flipped vector More...
 
void sort ()
 sort vector elements in ascending order More...
 
void sort (const Compare &comp)
 sort vector elements by providing a condition More...
 
Vector< N, T > sorted () const
 returns a sorted vector More...
 
Vector< N, T > sorted (const Compare &comp) const
 
bool operator== (const Vector< N, U > &rhs) const
 equality operator More...
 
bool operator!= (const Vector< N, U > &rhs) const
 unequality operator More...
 
Vector< N, T > & operator+= (const Vector< N, U > &rhs)
 plus equal operator More...
 
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > &> operator+= (const TScalar &scalar)
 add a scalar to this vector More...
 
Vector< N, T > & operator-= (const Vector< N, U > &rhs)
 minus equal operator More...
 
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > &> operator-= (const TScalar &scalar)
 subtract a scalar from every element of this vector More...
 
Vector< N, T > & operator*= (const Vector< N, U > &rhs)
 multiplication equal operator More...
 
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > &> operator*= (const TScalar &scalar)
 multiply a scalar with this vector More...
 
Vector< N, T > & operator/= (const Vector< N, U > &rhs)
 divison equal operator More...
 
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > &> operator/= (const TScalar &scalar)
 divide every element of this vector by a scalar More...
 

Additional Inherited Members

- Public Types inherited from mu::Vector< 2, T >
using value_type = typename std::array< T, N >::value_type
 
using size_type = typename std::array< T, N >::size_type
 
using iterator = typename std::array< T, N >::iterator
 
using const_iterator = typename std::array< T, N >::const_iterator
 
- Protected Attributes inherited from mu::Vector< 2, T >
std::array< T, N > data_
 

Detailed Description

template<typename T>
class mu::Vector2D< T >

A two dimensional vector.

Template Parameters
Ttype

Constructor & Destructor Documentation

◆ Vector2D()

template<typename T>
template<class Tt = T>
mu::Vector2D< T >::Vector2D ( const Vector< 2, Tt > &  other)
inline

Construct a new Vector2D object from a Vector object.

Example
mu::Vector2D<float> a = {1.5F, 2.5F};
Template Parameters
Tt
Parameters
other

Member Function Documentation

◆ rotate()

template<typename T>
template<class TScalar = T>
std::enable_if_t<std::is_arithmetic<TScalar>::value, void> mu::Vector2D< T >::rotate ( TScalar  angle)
inline

rotates this Vector by an angle [rad]

the euclidean vector length remains unchanged by rotation!

Example
// rotate by pi/2 multiple times
mu::Vector2D<float> a = {1.0F, 0.0F};
a.rotate(mu::pi2); // [ 0, 1 ]
a.rotate(mu::pi2); // [ -1, 0 ]
a.rotate(mu::pi2); // [ 0, -1 ]
a.rotate(mu::pi2); // [ 1, 0 ]
Template Parameters
T
Parameters
angle
Returns
std::enable_if<std::is_floating_point<U>::value, void>::type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotated()

template<typename T>
template<class TScalar = T>
std::enable_if_t<std::is_arithmetic<TScalar>::value, Vector2D<T> > mu::Vector2D< T >::rotated ( TScalar  angle)
inline

returns a Vector2D that is rotated by an angle [rad]

Example
// rotated by pi/2. creates new vector
mu::Vector2D<float> a = {1.0F, 0.0F};
mu::Vector2D<float> b = a.rotated(mu::pi2); // [ 0, 1 ]
See also
rotate()
Template Parameters
T
Parameters
angle
Returns
std::enable_if<std::is_floating_point<U>::value, Vector2D<T>>::type
Here is the call graph for this function:

◆ x() [1/2]

template<typename T>
T& mu::Vector2D< T >::x ( )
inlinenoexcept

x component

Example
mu::Vector2D<int> a = {7, 8};
int x = a.x();
Returns
T&
Here is the caller graph for this function:

◆ x() [2/2]

template<typename T>
const T& mu::Vector2D< T >::x ( ) const
inlinenoexcept

const x component

Example
const mu::Vector2D<int> a = {7, 8};
int x = a.x();
Returns
const T&

◆ y() [1/2]

template<typename T>
T& mu::Vector2D< T >::y ( )
inlinenoexcept

y component

Example
mu::Vector2D<int> a = {7, 8};
int y = a.y();
Returns
T&
Here is the caller graph for this function:

◆ y() [2/2]

template<typename T>
const T& mu::Vector2D< T >::y ( ) const
inlinenoexcept

const y component

Example
const mu::Vector2D<int> a = {7, 8};
int y = a.y();
Returns
const T&

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