philsupertramp/game-math
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Friends | List of all members
vec2< T > Struct Template Reference

#include <vec2.h>

Public Member Functions

 vec2 ()
 
 vec2 (const T &_x, const T &_y)
 
 vec2 (const T &_v)
 
 vec2 (const vec2< T > &_v)
 
float length () const
 
vec2< T > normalize () const
 
vec2< T > & operator+= (const vec2< T > &rhs)
 
vec2< T > & operator-= (const vec2< T > &rhs)
 
vec2< T > & operator*= (const T &rhs)
 
vec2< T > & operator/= (const T &rhs)
 
vec2< T > & operator/= (const vec2< T > &rhs)
 
constexpr vec2< T > & operator= (vec2< T > const &V)
 
T & operator[] (const int &index)
 
const T & operator[] (const int &index) const
 
template<typename U >
 operator vec2< U > ()
 

Public Attributes

union {
   struct {
      T   x
 
      T   y
 
   } 
 
}; 
 packed data More...
 
const size_t dim = 2
 object dimension More...
 

Friends

vec2< T > operator+ (vec2< T > lhs, const vec2< T > &rhs)
 
vec2< T > operator- (vec2< T > lhs, const vec2< T > &rhs)
 
vec2< T > operator* (vec2< T > lhs, const T &rhs)
 
vec2< T > operator* (const T &lhs, vec2< T > rhs)
 
vec2< T > operator/ (const vec2< T > &lhs, vec2< T > rhs)
 
operator* (vec2< T > lhs, const vec2< T > &rhs)
 
vec2< T > operator/ (vec2< T > lhs, const T &rhs)
 
bool operator== (const vec2< T > &lhs, const vec2< T > &rhs)
 
template<class U >
std::ostream & operator<< (std::ostream &, const vec2< U > &)
 

Detailed Description

template<class T>
struct vec2< T >

2D vector representation

Template Parameters
T
Examples
TestMatrix.cpp, TestUtils.cpp, mat/TestMat2.cpp, vec/TestVec2.cpp, and vec/TestVec4.cpp.

Constructor & Destructor Documentation

◆ vec2() [1/4]

template<class T >
vec2< T >::vec2 ( )
inline

default constructor

◆ vec2() [2/4]

template<class T >
vec2< T >::vec2 ( const T &  _x,
const T &  _y 
)
inline

two-element constructor

Parameters
_x
_y

◆ vec2() [3/4]

template<class T >
vec2< T >::vec2 ( const T &  _v)
inlineexplicit

single value constructor initializes all elements with given _v

Parameters
_v

◆ vec2() [4/4]

template<class T >
vec2< T >::vec2 ( const vec2< T > &  _v)
inline

copy constructor

Parameters
_v

Member Function Documentation

◆ length()

template<class T >
float vec2< T >::length ( ) const
inline

length getter

Returns
Examples
vec/TestVec2.cpp.

◆ normalize()

template<class T >
vec2< T > vec2< T >::normalize ( ) const
inline

getter for normalized vector

Returns
Examples
TestUtils.cpp, and vec/TestVec2.cpp.

◆ operator vec2< U >()

template<class T >
template<typename U >
vec2< T >::operator vec2< U > ( )
inlineexplicit

cast into other type

Template Parameters
U
Returns

◆ operator*=()

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

vector-scalar multiplication

Parameters
rhs
Returns

◆ operator+=()

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

vector-vector addition

Parameters
rhs
Returns

◆ operator-=()

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

vector-vector subtraction

Parameters
rhs
Returns

◆ operator/=() [1/2]

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

vector-scalar division

Parameters
rhs
Returns

◆ operator/=() [2/2]

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

◆ operator=()

template<class T >
constexpr vec2< T > & vec2< T >::operator= ( vec2< T > const &  V)
inlineconstexpr

assignment operator

Parameters
V
Returns

◆ operator[]() [1/2]

template<class T >
T & vec2< T >::operator[] ( const int &  index)
inline

member access

Parameters
index
Returns

◆ operator[]() [2/2]

template<class T >
const T & vec2< T >::operator[] ( const int &  index) const
inline

const member access

Parameters
index
Returns

Friends And Related Function Documentation

◆ operator* [1/3]

template<class T >
vec2< T > operator* ( const T &  lhs,
vec2< T >  rhs 
)
friend

scalar-vector multiplication

Parameters
lhs
rhs
Returns

◆ operator* [2/3]

template<class T >
vec2< T > operator* ( vec2< T >  lhs,
const T &  rhs 
)
friend

vec-scalar multiplication

Parameters
lhs
rhs
Returns

◆ operator* [3/3]

template<class T >
T operator* ( vec2< T >  lhs,
const vec2< T > &  rhs 
)
friend

vector-vector multiplication (dot-product)

Parameters
lhs
rhs
Returns

◆ operator+

template<class T >
vec2< T > operator+ ( vec2< T >  lhs,
const vec2< T > &  rhs 
)
friend

vec-vec addition

Parameters
lhs
rhs
Returns

◆ operator-

template<class T >
vec2< T > operator- ( vec2< T >  lhs,
const vec2< T > &  rhs 
)
friend

vec-vec subtraction

Parameters
lhs
rhs
Returns

◆ operator/ [1/2]

template<class T >
vec2< T > operator/ ( const vec2< T > &  lhs,
vec2< T >  rhs 
)
friend

◆ operator/ [2/2]

template<class T >
vec2< T > operator/ ( vec2< T >  lhs,
const T &  rhs 
)
friend

vector-scalar division

Parameters
lhs
rhs
Returns

◆ operator<<

template<class T >
template<class U >
std::ostream & operator<< ( std::ostream &  ,
const vec2< U > &   
)
friend

beautified std::cout operator

Template Parameters
U
Returns

◆ operator==

template<class T >
bool operator== ( const vec2< T > &  lhs,
const vec2< T > &  rhs 
)
friend

equality comparison operator

Parameters
lhs
rhs
Returns

Member Data Documentation

◆ 

union { ... } vec2< T >::@1

packed data

◆ dim

template<class T >
const size_t vec2< T >::dim = 2

object dimension

◆ x

template<class T >
T vec2< T >::x

◆ y

template<class T >
T vec2< T >::y

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