TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Math::TypedVector2< Type > Class Template Reference

#include <tb_vector.hpp>

Public Member Functions

 TypedVector2 (const SkipInitialization &fastAndStupid)
 
 TypedVector2 (void)
 
 TypedVector2 (const Type valueX, const Type valueY)
 
 TypedVector2 (const Type *componentArray)
 
 TypedVector2 (const TypedVector2 &other)
 
template<typename FromType >
 TypedVector2 (const TypedVector2< FromType > &other)
 
 ~TypedVector2 (void)
 
TypedVector2operator= (const TypedVector2 &other)
 
bool operator== (const TypedVector2 &other) const
 
bool operator!= (const TypedVector2 &other) const
 
 operator const Type * (void) const
 
 operator Type * (void)
 
template<typename ToType >
 operator TypedVector2< ToType > (void) const
 
const Type & operator[] (const int index) const
 
const Type & operator[] (const std::size_t &index) const
 
Type & operator[] (const int index)
 
Type & operator[] (const std::size_t &index)
 

Static Public Member Functions

static TypedVector2 Zero (void)
 
static TypedVector2 One (void)
 
static TypedVector2 Right (void)
 
static TypedVector2 Left (void)
 
static TypedVector2 Up (void)
 
static TypedVector2 Down (void)
 
static Type Dot (const TypedVector2< Type > &leftSide, const TypedVector2< Type > &rightSide)
 
static TypedVector2 Normalize (const TypedVector2< Type > &value)
 
static TypedVector2 Normalize (const TypedVector2< Type > &value, Type &magnitude)
 

Public Attributes

union {
   Type   mComponents [2]
 
   struct {
      Type   x
 
      Type   y
 
   } 
 
}; 
 

Detailed Description

template<typename Type>
class TurtleBrains::Math::TypedVector2< Type >

The TypedVector2 object is a two component mathematical vector of Types packed together with some functionality to perform basic vector math.

Constructor & Destructor Documentation

◆ TypedVector2() [1/5]

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::TypedVector2 ( const SkipInitialization fastAndStupid)
inlineexplicit

Constructs a TypedVector2 object leaving the members uninitialized and must be initialized manually before the object is used.

Note
Should be used only if the consequences are understood, and even then only sparingly.

◆ TypedVector2() [2/5]

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::TypedVector2 ( void  )
inline

Constructs a default TypedVector2 object with all components set to Type(0).

◆ TypedVector2() [3/5]

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::TypedVector2 ( const Type  valueX,
const Type  valueY 
)
inline

Constructs a TypedVector2 object with each component initialized with the values provided.

Parameters
valueXThe value to initialize the x component as.
valueYThe value to initialize the y component as.

◆ TypedVector2() [4/5]

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::TypedVector2 ( const Type *  componentArray)
inlineexplicit

Constructs a TypedVector2 object with the supplied Type array, which must contain at least 2 Types.

Parameters
componentArrayMust have at least 2 Types, one for each component in the TypedVector2.

◆ TypedVector2() [5/5]

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::TypedVector2 ( const TypedVector2< Type > &  other)
inline

Constructs a TypedVector2 object by copying another TypedVector2 object, each component will be initialized to the value of the other components.

Parameters
otherThe TypedVector2 object to initialize component values to.

◆ ~TypedVector2()

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::~TypedVector2 ( void  )
inline

Nothing needs to happen to destroy a TypedVector2 object.

Member Function Documentation

◆ Dot()

template<typename Type >
static Type TurtleBrains::Math::TypedVector2< Type >::Dot ( const TypedVector2< Type > &  leftSide,
const TypedVector2< Type > &  rightSide 
)
inlinestatic

Perform a dot product on two TypedVector2 objects, returning the scalar result.

◆ Normalize() [1/2]

template<typename Type >
static TypedVector2 TurtleBrains::Math::TypedVector2< Type >::Normalize ( const TypedVector2< Type > &  value)
inlinestatic

Take a Vector2 and returns a unit length vector in the same direction.

◆ Normalize() [2/2]

template<typename Type >
static TypedVector2 TurtleBrains::Math::TypedVector2< Type >::Normalize ( const TypedVector2< Type > &  value,
Type &  magnitude 
)
inlinestatic

Take a Vector2 and returns a unit length vector in the same direction while also returning the original magnitude.

◆ One()

template<typename Type >
static TypedVector2 TurtleBrains::Math::TypedVector2< Type >::One ( void  )
inlinestatic

Creates and returns a TypedVector2 object representing 1, 1.

◆ operator const Type *()

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::operator const Type * ( void  ) const
inlineexplicit

Returns a const Type array of the TypedVector2 components.

◆ operator Type *()

template<typename Type >
TurtleBrains::Math::TypedVector2< Type >::operator Type * ( void  )
inlineexplicit

Returns a Type array of the TypedVector2 components. If modified the internal components will also be modified as well.

◆ operator TypedVector2< ToType >()

template<typename Type >
template<typename ToType >
TurtleBrains::Math::TypedVector2< Type >::operator TypedVector2< ToType > ( void  ) const
inlineexplicit

Casts a Vector to Vector to move from float to double or such.

◆ operator!=()

template<typename Type >
bool TurtleBrains::Math::TypedVector2< Type >::operator!= ( const TypedVector2< Type > &  other) const
inline

Inequality operator, returns the opposite of the equality operator, which compares each value in one TypedVector2 object to another using IsEqual to compare the floating point component values.

◆ operator=()

template<typename Type >
TypedVector2& TurtleBrains::Math::TypedVector2< Type >::operator= ( const TypedVector2< Type > &  other)
inline

Assignment operator, sets each component of the TypedVector2 object to the values of the other object.

Parameters
otherThe TypedVector2 object to set the components to.

◆ operator==()

template<typename Type >
bool TurtleBrains::Math::TypedVector2< Type >::operator== ( const TypedVector2< Type > &  other) const
inline

Equality operator, compares each component of the TypedVector2 object to the values of another TypedVector2 returning true if all components are equal, or false if any of the components are not equal.

Parameters
otherThe TypedVector2 object to compare against.
Note
Because the components are floating point values tbMath::IsEqual is used to compare the components for equality using the default tolerance: kTolerance.

◆ operator[]() [1/2]

template<typename Type >
Type& TurtleBrains::Math::TypedVector2< Type >::operator[] ( const int  index)
inline

Returns a reference to one of the TypedVector2 components by an index provided by the VectorComponent enum. If the reference returned is modified, the internal components will also be modified as well.

◆ operator[]() [2/2]

template<typename Type >
const Type& TurtleBrains::Math::TypedVector2< Type >::operator[] ( const int  index) const
inline

Returns a reference to one of the TypedVector2 components by an index provided by the VectorComponent enum.

◆ Zero()

template<typename Type >
static TypedVector2 TurtleBrains::Math::TypedVector2< Type >::Zero ( void  )
inlinestatic

Creates and returns a TypedVector2 object representing 0, 0.