TGX 1.0.3
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
Loading...
Searching...
No Matches
Vec2.h File Reference

2D vector. More...

#include <stdint.h>
#include "Misc.h"

Go to the source code of this file.

Classes

struct  tgx::Vec2< T >
 Generic 2D vector [specializations iVec2, fVec2, dVec2]. More...
 

Typedefs

typedef Vec2< int > tgx::iVec2
 Integer-valued 2D vector.
 
typedef Vec2< float > tgx::fVec2
 Floating point valued 2D vector with single (float) precision.
 
typedef Vec2< double > tgx::dVec2
 Floating point valued 2D vector with double precision.
 

Functions

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > tgx::normalize (Vec2< T > V)
 Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > tgx::normalize_fast (Vec2< T > V)
 Return the vector normalized to have unit norm (do nothing if the vector is 0). More...
 
template<typename T >
tgx::dist2 (const Vec2< T > V1, const Vec2< T > V2)
 Compute the squared euclidian distance between two vectors.
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::dist (Vec2< T > V1, const Vec2< T > V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::dist_fast (Vec2< T > V1, const Vec2< T > V2)
 Compute the euclidian distance between two vectors. More...
 
template<typename T >
Vec2< T > tgx::operator+ (Vec2< T > V1, const Vec2< T > V2)
 Addition operator. More...
 
template<typename T >
Vec2< T > tgx::operator- (Vec2< T > V1, const Vec2< T > V2)
 Substraction operator. More...
 
template<typename T >
Vec2< T > tgx::operator* (Vec2< T > V1, const Vec2< T > V2)
 Multiplication operator. More...
 
template<typename T >
Vec2< T > tgx::operator/ (Vec2< T > V1, const Vec2< T > V2)
 Division operator. More...
 
template<typename T >
Vec2< T > tgx::operator+ (const T a, Vec2< T > V)
 Scalar addition operator.
 
template<typename T >
Vec2< T > tgx::operator+ (Vec2< T > V, const T a)
 Scalar addition operator.
 
template<typename T >
Vec2< T > tgx::operator- (const T a, Vec2< T > V)
 Scalar substraction operator.
 
template<typename T >
Vec2< T > tgx::operator- (Vec2< T > V, const T a)
 Scalar substraction operator.
 
template<typename T >
Vec2< T > tgx::operator* (const T a, Vec2< T > V)
 Scalar multiplication operator.
 
template<typename T >
Vec2< T > tgx::operator* (Vec2< T > V, const T a)
 Scalar multiplication operator.
 
template<typename T >
Vec2< T > tgx::operator/ (const T a, Vec2< T > V)
 Scalar division operator.
 
template<typename T >
Vec2< T > tgx::operator/ (Vec2< T > V, const T a)
 Scalar division operator.
 
template<typename T >
tgx::dotProduct (const Vec2< T > U, const Vec2< T > V)
 Return the dot product U.V between two vectors.
 
template<typename T >
tgx::crossProduct (const Vec2< T > &U, const Vec2< T > &V)
 Return the cross product UxV (i.e. More...
 
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > tgx::lerp (Tfloat alpha, Vec2< T > V1, Vec2< T > V2)
 Return the linear interpolation: V1 + alpha(V2 - V1).
 

Detailed Description

2D vector.

Function Documentation

◆ normalize()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > tgx::normalize ( Vec2< T >  V)
inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ normalize_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Vec2< T > tgx::normalize_fast ( Vec2< T >  V)
inline

Return the vector normalized to have unit norm (do nothing if the vector is 0).

Use fast_invsqrt() approximation to speedup computations.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ dist()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::dist ( Vec2< T >  V1,
const Vec2< T >  V2 
)

Compute the euclidian distance between two vectors.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ dist_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
Tfloat tgx::dist_fast ( Vec2< T >  V1,
const Vec2< T >  V2 
)

Compute the euclidian distance between two vectors.

Use fast_sqrt() approximation to speedup computations.

Template Parameters
TfloatFloating point type used for computation (use default floating point type if unspecified).

◆ operator+()

template<typename T >
Vec2< T > tgx::operator+ ( Vec2< T >  V1,
const Vec2< T >  V2 
)
inline

Addition operator.

Coordinates by coordinates

◆ operator-()

template<typename T >
Vec2< T > tgx::operator- ( Vec2< T >  V1,
const Vec2< T >  V2 
)
inline

Substraction operator.

Coordinates by coordinates

◆ operator*()

template<typename T >
Vec2< T > tgx::operator* ( Vec2< T >  V1,
const Vec2< T >  V2 
)
inline

Multiplication operator.

Coordinates by coordinates

◆ operator/()

template<typename T >
Vec2< T > tgx::operator/ ( Vec2< T >  V1,
const Vec2< T >  V2 
)
inline

Division operator.

Coordinates by coordinates

◆ crossProduct()

template<typename T >
T tgx::crossProduct ( const Vec2< T > &  U,
const Vec2< T > &  V 
)
inline

Return the cross product UxV (i.e.

the determinant of the 2 row vector matrix [U V]).