| TGX 1.1.3 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Classes | Typedefs | Functions
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>
TGX_INLINE 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>
TGX_INLINE 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_INLINE 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>
TGX_INLINE Tfloat | tgx::dist (const Vec2< T > &V1, const Vec2< T > &V2)
| Compute the euclidian distance between two vectors. More...
template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>
TGX_INLINE Tfloat | tgx::dist_fast (const Vec2< T > &V1, const Vec2< T > &V2)
| Compute the euclidian distance between two vectors. More...
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator+ (Vec2< T > V1, const Vec2< T > &V2)
| Addition operator. More...
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator- (Vec2< T > V1, const Vec2< T > &V2)
| Substraction operator. More...
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator* (Vec2< T > V1, const Vec2< T > &V2)
| Multiplication operator. More...
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator/ (Vec2< T > V1, const Vec2< T > &V2)
| Division operator. More...
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator+ (const T a, Vec2< T > V)
| Scalar addition operator.
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator+ (Vec2< T > V, const T a)
| Scalar addition operator.
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator- (Vec2< T > V, const T a)
| Scalar substraction operator.
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator* (const T a, Vec2< T > V)
| Scalar multiplication operator.
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator* (Vec2< T > V, const T a)
| Scalar multiplication operator.
template<typename T >
TGX_INLINE Vec2< T > | tgx::operator/ (Vec2< T > V, const T a)
| Scalar division operator.
template<typename T >
TGX_INLINE T | tgx::dotProduct (const Vec2< T > &U, const Vec2< T > &V)
| Return the dot product U.V between two vectors.
TGX_INLINE float | tgx::dotProduct (const Vec2< float > &U, const Vec2< float > &V)
| Return the dot product U.V between two float vectors using fused multiply-add operations when enabled for the target architecture.
template<typename T >
TGX_INLINE 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>
TGX_INLINE Vec2< T > | tgx::lerp (Tfloat alpha, const Vec2< T > &V1, const 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>

TGX_INLINE 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

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ normalize_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

TGX_INLINE 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

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ dist()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

TGX_INLINE Tfloat tgx::dist | ( | const Vec2< T > & | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Compute the euclidian distance between two vectors.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ dist_fast()

template<typename T , typename Tfloat = typename DefaultFPType<T>::fptype>

TGX_INLINE Tfloat tgx::dist_fast | ( | const Vec2< T > & | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Compute the euclidian distance between two vectors.

Use fast_sqrt() approximation to speedup computations.

Template Parameters

  Tfloat | Floating point type used for computation (use default floating point type if unspecified).

## ◆ operator+()

template<typename T >

TGX_INLINE Vec2< T > tgx::operator+ | ( | Vec2< T > | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Addition operator.

Coordinates by coordinates

## ◆ operator-()

template<typename T >

TGX_INLINE Vec2< T > tgx::operator- | ( | Vec2< T > | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Substraction operator.

Coordinates by coordinates

## ◆ operator*()

template<typename T >

TGX_INLINE Vec2< T > tgx::operator* | ( | Vec2< T > | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Multiplication operator.

Coordinates by coordinates

## ◆ operator/()

template<typename T >

TGX_INLINE Vec2< T > tgx::operator/ | ( | Vec2< T > | V1,
|  | const Vec2< T > & | V2
| ) |  |
| inline

Division operator.

Coordinates by coordinates

## ◆ crossProduct()

template<typename T >

TGX_INLINE 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]).