VMTK
VMATH_NAMESPACE::Vector2< T > Class Template Reference

#include <vmath.h>

Public Member Functions

 Vector2 ()
 
 Vector2 (T nx, T ny)
 
 Vector2 (const Vector2< T > &src)
 
template<class FromT >
 Vector2 (const Vector2< FromT > &src)
 
template<class FromT >
Vector2< T > & operator= (const Vector2< FromT > &rhs)
 
Vector2< T > & operator= (const Vector2< T > &rhs)
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
Vector2< T > operator+ (const Vector2< T > &rhs) const
 
Vector2< T > operator- (const Vector2< T > &rhs) const
 
Vector2< T > operator* (const Vector2< T > &rhs) const
 
Vector2< T > operator/ (const Vector2< T > &rhs) const
 
Vector2< T > & operator+= (const Vector2< T > &rhs)
 
Vector2< T > & operator-= (const Vector2< T > &rhs)
 
Vector2< T > & operator*= (const Vector2< T > &rhs)
 
Vector2< T > & operator/= (const Vector2< T > &rhs)
 
Vector2< T > operator+ (T rhs) const
 
Vector2< T > operator- (T rhs) const
 
Vector2< T > operator* (T rhs) const
 
Vector2< T > operator/ (T rhs) const
 
Vector2< T > & operator+= (T rhs)
 
Vector2< T > & operator-= (T rhs)
 
Vector2< T > & operator*= (T rhs)
 
Vector2< T > & operator/= (T rhs)
 
bool operator== (const Vector2< T > &rhs) const
 
bool operator!= (const Vector2< T > &rhs) const
 
Vector2< T > operator- () const
 
length () const
 
void normalize ()
 
Vector2< T > vectorDirection (const Vector2< T > v1, const Vector2< T > v2) const
 
Vector2< T > vectorNormal (const Vector2< T > v1, const Vector2< T > v2) const
 
lengthSq () const
 
Vector2< T > lerp (T fact, const Vector2< T > &r) const
 
 operator T* ()
 
 operator const T * () const
 
std::string toString () const
 
void print ()
 

Public Attributes

union {
   T   x
 
   T   s
 
}; 
 
union {
   T   y
 
   T   t
 
}; 
 

Friends

std::ostream & operator<< (std::ostream &lhs, const Vector2< T > &rhs)
 

Detailed Description

template<class T>
class VMATH_NAMESPACE::Vector2< T >

Class for two dimensional vector. There are three ways of accessing vector components. Let's have Vector2f v, you can either:

  • access as position(x,y) — v.x = v.y = 3;
  • access as texture coordinate (s,t) — v.s = v.t = 3;
  • access via operator[] — v[0] = v[1] = 3;

Definition at line 170 of file vmath.h.

Constructor & Destructor Documentation

◆ Vector2() [1/4]

template<class T>
VMATH_NAMESPACE::Vector2< T >::Vector2 ( )
inline

Creates and sets to (0,0)

Definition at line 205 of file vmath.h.

◆ Vector2() [2/4]

template<class T>
VMATH_NAMESPACE::Vector2< T >::Vector2 ( nx,
ny 
)
inline

Creates and sets to (x,y)

Parameters
nxinitial x-coordinate value
nyinitial y-coordinate value

Definition at line 215 of file vmath.h.

◆ Vector2() [3/4]

template<class T>
VMATH_NAMESPACE::Vector2< T >::Vector2 ( const Vector2< T > &  src)
inline

Copy constructor.

Parameters
srcSource of data for new created instance.

Definition at line 224 of file vmath.h.

◆ Vector2() [4/4]

template<class T>
template<class FromT >
VMATH_NAMESPACE::Vector2< T >::Vector2 ( const Vector2< FromT > &  src)
inline

Copy casting constructor.

Parameters
srcSource of data for new created instance.

Definition at line 235 of file vmath.h.

Member Function Documentation

◆ length()

template<class T>
T VMATH_NAMESPACE::Vector2< T >::length ( ) const
inline

Get length of vector.

Returns
lenght of vector

Definition at line 497 of file vmath.h.

Here is the caller graph for this function:

◆ lengthSq()

template<class T>
T VMATH_NAMESPACE::Vector2< T >::lengthSq ( ) const
inline

Return square of length.

Returns
length ^ 2
Note
This method is faster then length(). For comparison of length of two vector can be used just this value, instead of more expensive length() method.

Definition at line 536 of file vmath.h.

◆ lerp()

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::lerp ( fact,
const Vector2< T > &  r 
) const
inline

Linear interpolation of two vectors

Parameters
factFactor of interpolation. For translation from position of this vector to vector r, values of factor goes from 0.0 to 1.0.
rSecond Vector for interpolation
Note
However values of fact parameter are reasonable only in interval [0.0 , 1.0], you can pass also values outside of this interval and you can get result (extrapolation?)

Definition at line 551 of file vmath.h.

◆ normalize()

template<class T>
void VMATH_NAMESPACE::Vector2< T >::normalize ( )
inline

Normalize vector

Definition at line 505 of file vmath.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator const T *()

template<class T>
VMATH_NAMESPACE::Vector2< T >::operator const T * ( ) const
inline

Conversion to pointer operator

Returns
Constant Pointer to internally stored (in management of class Vector2<T>) used for passing Vector2<T> values to gl*2[fd] functions.

Definition at line 571 of file vmath.h.

◆ operator T*()

template<class T>
VMATH_NAMESPACE::Vector2< T >::operator T* ( )
inline

Conversion to pointer operator

Returns
Pointer to internally stored (in management of class Vector2<T>) used for passing Vector2<T> values to gl*2[fd] functions.

Definition at line 562 of file vmath.h.

◆ operator!=()

template<class T>
bool VMATH_NAMESPACE::Vector2< T >::operator!= ( const Vector2< T > &  rhs) const
inline

Inequality test operator

Parameters
rhsRight hand side argument of binary operator.
Returns
not (lhs == rhs) :-P

Definition at line 477 of file vmath.h.

◆ operator*() [1/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator* ( const Vector2< T > &  rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 318 of file vmath.h.

◆ operator*() [2/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator* ( rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 399 of file vmath.h.

◆ operator*=() [1/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator*= ( const Vector2< T > &  rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 358 of file vmath.h.

◆ operator*=() [2/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator*= ( rhs)
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 439 of file vmath.h.

◆ operator+() [1/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator+ ( const Vector2< T > &  rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 300 of file vmath.h.

◆ operator+() [2/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator+ ( rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 381 of file vmath.h.

◆ operator+=() [1/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator+= ( const Vector2< T > &  rhs)
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 336 of file vmath.h.

◆ operator+=() [2/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator+= ( rhs)
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 417 of file vmath.h.

◆ operator-() [1/3]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator- ( const Vector2< T > &  rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 309 of file vmath.h.

◆ operator-() [2/3]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator- ( rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 390 of file vmath.h.

◆ operator-() [3/3]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator- ( ) const
inline

Unary negate operator

Returns
negated vector

Definition at line 487 of file vmath.h.

◆ operator-=() [1/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator-= ( const Vector2< T > &  rhs)
inline

Substraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 347 of file vmath.h.

◆ operator-=() [2/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator-= ( rhs)
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 428 of file vmath.h.

◆ operator/() [1/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator/ ( const Vector2< T > &  rhs) const
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 327 of file vmath.h.

◆ operator/() [2/2]

template<class T>
Vector2<T> VMATH_NAMESPACE::Vector2< T >::operator/ ( rhs) const
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 408 of file vmath.h.

◆ operator/=() [1/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator/= ( const Vector2< T > &  rhs)
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 369 of file vmath.h.

◆ operator/=() [2/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator/= ( rhs)
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 450 of file vmath.h.

◆ operator=() [1/2]

template<class T>
template<class FromT >
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator= ( const Vector2< FromT > &  rhs)
inline

Copy casting operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 247 of file vmath.h.

◆ operator=() [2/2]

template<class T>
Vector2<T>& VMATH_NAMESPACE::Vector2< T >::operator= ( const Vector2< T > &  rhs)
inline

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 258 of file vmath.h.

◆ operator==()

template<class T>
bool VMATH_NAMESPACE::Vector2< T >::operator== ( const Vector2< T > &  rhs) const
inline

Equality test operator

Parameters
rhsRight hand side argument of binary operator.
Note
Test of equality is based of threshold EPSILON value. To be two values equal, must satisfy this condition | lhs.x - rhs.y | < EPSILON, same for y-coordinate.

Definition at line 467 of file vmath.h.

◆ operator[]() [1/2]

template<class T>
T& VMATH_NAMESPACE::Vector2< T >::operator[] ( int  n)
inline

Array access operator

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, else reference to y y coordinate.

Definition at line 271 of file vmath.h.

◆ operator[]() [2/2]

template<class T>
const T& VMATH_NAMESPACE::Vector2< T >::operator[] ( int  n) const
inline

Constant array access operator

Parameters
nArray index
Returns
For n = 0, reference to x coordinate, else reference to y y coordinate.

Definition at line 286 of file vmath.h.

◆ print()

template<class T>
void VMATH_NAMESPACE::Vector2< T >::print ( )
inline

Show the print of string representation.

Definition at line 602 of file vmath.h.

Here is the call graph for this function:

◆ toString()

template<class T>
std::string VMATH_NAMESPACE::Vector2< T >::toString ( ) const
inline

Gets string representation.

Definition at line 592 of file vmath.h.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  lhs,
const Vector2< T > &  rhs 
)
friend

Output to stream operator

Parameters
lhsLeft hand side argument of operator (commonly ostream instance).
rhsRight hand side argument of operator.
Returns
Left hand side argument - the ostream object passed to operator.

Definition at line 583 of file vmath.h.

Member Data Documentation

◆ s

template<class T>
T VMATH_NAMESPACE::Vector2< T >::s

First element of vector, alias for S-coordinate. For textures notation.

Definition at line 184 of file vmath.h.

◆ t

template<class T>
T VMATH_NAMESPACE::Vector2< T >::t

Second element of vector, alias for T-coordinate. For textures notation.

Definition at line 198 of file vmath.h.

◆ x

template<class T>
T VMATH_NAMESPACE::Vector2< T >::x

First element of vector, alias for X-coordinate.

Definition at line 178 of file vmath.h.

◆ y

template<class T>
T VMATH_NAMESPACE::Vector2< T >::y

Second element of vector, alias for Y-coordinate.

Definition at line 192 of file vmath.h.


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