Horizon
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
VECTOR2< T > Class Template Reference

Class VECTOR2 defines a general 2D-vector/point. More...

#include <vector2d.h>

Public Types

typedef VECTOR2_TRAITS< T >::extended_type extended_type
 
typedef T coord_type
 

Public Member Functions

 VECTOR2 ()
 Construct a 2D-vector with x, y = 0.
 
 VECTOR2 (T x, T y)
 Construct a vector with given components x, y.
 
template<typename CastingType >
 VECTOR2 (const VECTOR2< CastingType > &aVec)
 Initializes a vector from another specialization. More...
 
template<typename CastedType >
VECTOR2< CastedType > operator() () const
 Casts a vector to another specialized subclass. More...
 
EuclideanNorm () const
 Destructor. More...
 
extended_type SquaredEuclideanNorm () const
 Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2). More...
 
VECTOR2< T > Perpendicular () const
 Function Perpendicular computes the perpendicular vector. More...
 
VECTOR2< T > Resize (T aNewLength) const
 Function Resize returns a vector of the same direction, but length specified in aNewLength. More...
 
double Angle () const
 Function Angle computes the angle of the vector. More...
 
VECTOR2< T > Rotate (double aAngle) const
 Function Rotate rotates the vector by a given angle. More...
 
const std::string Format () const
 Function Format returns the vector formatted as a string. More...
 
extended_type Cross (const VECTOR2< T > &aVector) const
 Function Cross() computes cross product of self with aVector.
 
extended_type Dot (const VECTOR2< T > &aVector) const
 Function Dot() computes dot product of self with aVector.
 
VECTOR2< T > & operator= (const VECTOR2< T > &aVector)
 Assignment operator.
 
VECTOR2< T > operator+ (const VECTOR2< T > &aVector) const
 Vector addition operator.
 
VECTOR2< T > operator+ (const T &aScalar) const
 Scalar addition operator.
 
VECTOR2< T > & operator+= (const VECTOR2< T > &aVector)
 Compound assignment operator.
 
VECTOR2< T > & operator+= (const T &aScalar)
 Compound assignment operator.
 
VECTOR2< T > operator- (const VECTOR2< T > &aVector) const
 Vector subtraction operator.
 
VECTOR2< T > operator- (const T &aScalar) const
 Scalar subtraction operator.
 
VECTOR2< T > & operator-= (const VECTOR2< T > &aVector)
 Compound assignment operator.
 
VECTOR2< T > & operator-= (const T &aScalar)
 Compound assignment operator.
 
VECTOR2< T > operator- ()
 Negate Vector operator.
 
extended_type operator* (const VECTOR2< T > &aVector) const
 Scalar product operator.
 
VECTOR2< T > operator* (const T &aFactor) const
 Multiplication with a factor.
 
VECTOR2< T > operator/ (const T &aFactor) const
 Division with a factor.
 
bool operator== (const VECTOR2< T > &aVector) const
 Equality operator.
 
bool operator!= (const VECTOR2< T > &aVector) const
 Not equality operator.
 
bool operator< (const VECTOR2< T > &aVector) const
 Smaller than operator.
 
bool operator<= (const VECTOR2< T > &aVector) const
 
bool operator> (const VECTOR2< T > &aVector) const
 Greater than operator.
 
bool operator>= (const VECTOR2< T > &aVector) const
 

Public Attributes

x
 
y
 

Static Public Attributes

static constexpr extended_type ECOORD_MAX = std::numeric_limits<extended_type>::max()
 
static constexpr extended_type ECOORD_MIN = std::numeric_limits<extended_type>::min()
 

Detailed Description

template<class T = int>
class VECTOR2< T >

Class VECTOR2 defines a general 2D-vector/point.

This class uses templates to be universal. Several operators are provided to help easy implementing of linear algebra equations.

Constructor & Destructor Documentation

◆ VECTOR2()

template<class T = int>
template<typename CastingType >
VECTOR2< T >::VECTOR2 ( const VECTOR2< CastingType > &  aVec)
inline

Initializes a vector from another specialization.

Beware of rouding issues.

Member Function Documentation

◆ Angle()

template<class T >
double VECTOR2< T >::Angle

Function Angle computes the angle of the vector.

Returns
vector angle, in radians

◆ EuclideanNorm()

template<class T >
T VECTOR2< T >::EuclideanNorm

Destructor.

Function Euclidean Norm computes the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2). It is used to calculate the length of the vector.

Returns
Scalar, the euclidean norm

◆ Format()

template<class T >
const std::string VECTOR2< T >::Format

Function Format returns the vector formatted as a string.

Returns
the formatted string

◆ operator()()

template<class T = int>
template<typename CastedType >
VECTOR2<CastedType> VECTOR2< T >::operator() ( ) const
inline

Casts a vector to another specialized subclass.

Beware of rouding issues.

◆ Perpendicular()

template<class T >
VECTOR2< T > VECTOR2< T >::Perpendicular

Function Perpendicular computes the perpendicular vector.

Returns
Perpendicular vector

◆ Resize()

template<class T >
VECTOR2< T > VECTOR2< T >::Resize ( aNewLength) const

Function Resize returns a vector of the same direction, but length specified in aNewLength.

Parameters
aNewLengthlength of the rescaled vector
Returns
rescaled vector

◆ Rotate()

template<class T >
VECTOR2< T > VECTOR2< T >::Rotate ( double  aAngle) const

Function Rotate rotates the vector by a given angle.

Rotate a VECTOR2 by aAngle.

Parameters
aAnglerotation angle in radians
Returns
rotated vector
Parameters
aAngle= rotation angle in radians

◆ SquaredEuclideanNorm()

template<class T >
VECTOR2< T >::extended_type VECTOR2< T >::SquaredEuclideanNorm

Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).

It is used to calculate the length of the vector.

Returns
Scalar, the euclidean norm

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