Horizon
Loading...
Searching...
No Matches
VECTOR2< T > Class Template Reference

Define 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 (const wxPoint &aPoint)
 Constructor with a wxPoint as argument.
 VECTOR2 (const wxSize &aSize)
 Constructor with a wxSize as argument.
 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. Beware of rounding issues.
 VECTOR2 (const VECTOR2< T > &aVec)
 Copy a vector.
template<typename CastedType>
VECTOR2< CastedType > operator() () const
 Cast a vector to another specialized subclass. Beware of rounding issues.
 operator wxPoint () const
 Implement the cast to wxPoint.
T EuclideanNorm () const
 Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
extended_type SquaredEuclideanNorm () const
 Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
VECTOR2< T > Perpendicular () const
 Compute the perpendicular vector.
VECTOR2< T > Resize (T aNewLength) const
 Return a vector of the same direction, but length specified in aNewLength.
double Angle () const
 Compute the angle of the vector.
VECTOR2< T > Rotate (double aAngle) const
 Rotate the vector by a given angle.
const std::string Format () const
 Return the vector formatted as a string.
extended_type Cross (const VECTOR2< T > &aVector) const
 Compute cross product of self with aVector.
extended_type Dot (const VECTOR2< T > &aVector) const
 Compute 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

T x
T 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 >

Define a general 2D-vector/point.

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

Member Function Documentation

◆ Angle()

template<class T>
double VECTOR2< T >::Angle ( ) const

Compute the angle of the vector.

Returns
the vector angle in radians.

◆ EuclideanNorm()

template<class T>
T VECTOR2< T >::EuclideanNorm ( ) const

Compute 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 ( ) const

Return the vector formatted as a string.

Returns
the formatted string

◆ operator wxPoint()

template<class T = int>
VECTOR2< T >::operator wxPoint ( ) const
inlineexplicit

Implement the cast to wxPoint.

Returns
the vector cast to wxPoint.

◆ Perpendicular()

template<class T>
VECTOR2< T > VECTOR2< T >::Perpendicular ( ) const

Compute the perpendicular vector.

Returns
Perpendicular vector

◆ Resize()

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

Return a vector of the same direction, but length specified in aNewLength.

Parameters
aNewLengthis the length of the rescaled vector.
Returns
the rescaled vector.

◆ Rotate()

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

Rotate 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 ( ) const

Compute 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: