2D vector More...

#include <line.h>

+ Inheritance diagram for clan::Vec2< Type >:

Public Types

typedef Type datatype
 

Public Member Functions

 Vec2 ()
 
 Vec2 (const Type &scalar)
 
 Vec2 (const Vec3< Type > &copy)
 
 Vec2 (const Vec4< Type > &copy)
 
 Vec2 (const Type &p1, const Type &p2)
 
 Vec2 (const Type *array_xy)
 
 Vec2 (const Vec2< double > &copy)
 
 Vec2 (const Vec2< float > &copy)
 
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
template<>
 Vec2 (const Vec2< float > &copy)
 
template<>
 Vec2 (const Vec2< double > &copy)
 
template<>
 Vec2 (const Vec2< int > &copy)
 
Angle angle (const Vec2< Type > &vector) const
 Calculate the angle between this vector and an other vector. More...
 
Angle angle_line (const Vec2< Type > &point) const
 Calculate the angle of the line joining this point and other point. More...
 
Angle angle_normed (const Vec2< Type > &vector) const
 Calculate the angle between this vector and an other vector, where the vectors are unit vectors. More...
 
Type distance (const Vec2< Type > &vector) const
 Calculate the distance between this vector and an other vector. More...
 
Type dot (const Vec2< Type > &vector) const
 Dot products this vector with an other vector. More...
 
bool is_equal (const Vec2< Type > &other, Type epsilon) const
 Returns true if equal within the bounds of an epsilon. More...
 
Type length () const
 Returns the length (magnitude) of this vector. More...
 
template<>
double length () const
 
template<>
float length () const
 
Vec2< Type > & normalize ()
 Normalizes this vector. More...
 
bool operator!= (const Vec2< Type > &vector) const
 != operator. More...
 
void operator*= (const Vec2< Type > &vector)
 *= operator. More...
 
void operator*= (Type value)
 *= operator. More...
 
void operator+= (const Vec2< Type > &vector)
 += operator. More...
 
void operator+= (Type value)
 += operator. More...
 
Vec2< Type > operator- () const
 
  • operator.
More...
 
void operator-= (const Vec2< Type > &vector)
 -= operator. More...
 
void operator-= (Type value)
 -= operator. More...
 
void operator/= (const Vec2< Type > &vector)
 /= operator. More...
 
void operator/= (Type value)
 /= operator. More...
 
bool operator< (const Vec2< Type > &vector) const
 < operator. More...
 
Vec2< Type > & operator= (const Vec2< Type > &vector)
 = operator. More...
 
bool operator== (const Vec2< Type > &vector) const
 == operator. More...
 
Vec2< Type > & rotate (const Vec2< Type > &hotspot, const Angle &angle)
 Rotate this vector around another point. More...
 
Vec2< Type > & round ()
 Rounds all components of this vector. More...
 
Type round_value (float value) const
 Rounds a value for the datatype. More...
 

Static Public Member Functions

static Pointx< Type > calc_origin (Origin origin, const Sizex< Type > &size)
 Returns the anchor point for the origin within the dimensions of the size structure. More...
 
static Type dot (const Vec2< Type > &vector_1, const Vec2< Type > &vector_2)
 Dot products a vector with an other vector. More...
 
static bool is_equal (const Vec2< Type > &first, const Vec2< Type > &second, Type epsilon)
 Returns true if equal within the bounds of an epsilon. More...
 
static Vec2< Type > normalize (const Vec2< Type > &vector)
 Normalizes a vector. More...
 
static Vec2< Type > rotate (const Vec2< Type > &vector, const Vec2< Type > &hotspot, const Angle &angle)
 Rotate a vector around another point. More...
 
static Vec2< Type > round (const Vec2< Type > &vector)
 Rounds all components on a vector. More...
 

Public Attributes

union {
   Type   r
 
   Type   s
 
   Type   x
 
}; 
 
union {
   Type   g
 
   Type   t
 
   Type   y
 
}; 
 

Detailed Description

template<typename Type>
singleton clan::Vec2< Type >

2D vector

These vector templates are defined for:
char (Vec2c), unsigned char (Vec2uc), short (Vec2s),
unsigned short (Vec2us), int (Vec2i), unsigned int (Vec2ui), float (Vec2f), double (Vec2d)

Member Typedef Documentation

template<typename Type>
typedef Type clan::Vec2< Type >::datatype

Constructor & Destructor Documentation

template<typename Type>
clan::Vec2< Type >::Vec2 ( )
inline
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Type &  scalar)
inlineexplicit
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Vec3< Type > &  copy)
inlineexplicit
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Vec4< Type > &  copy)
inlineexplicit
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Type &  p1,
const Type &  p2 
)
inlineexplicit
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Type *  array_xy)
inlineexplicit
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Vec2< double > &  copy)
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Vec2< float > &  copy)
template<typename Type>
clan::Vec2< Type >::Vec2 ( const Vec2< int > &  copy)
template<>
clan::Vec2< unsigned char >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< unsigned char >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< unsigned char >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< char >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< char >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< char >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< unsigned short >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< unsigned short >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< unsigned short >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< short >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< short >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< short >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< int >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< int >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< int >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< unsigned int >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< unsigned int >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< unsigned int >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< float >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< float >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< float >::Vec2 ( const Vec2< int > &  copy)
inline
template<>
clan::Vec2< double >::Vec2 ( const Vec2< float > &  copy)
inline
template<>
clan::Vec2< double >::Vec2 ( const Vec2< double > &  copy)
inline
template<>
clan::Vec2< double >::Vec2 ( const Vec2< int > &  copy)
inline

Member Function Documentation

template<typename Type>
Angle clan::Vec2< Type >::angle ( const Vec2< Type > &  vector) const

Calculate the angle between this vector and an other vector.

Parameters
vector= Second vector used to calculate angle.
Returns
The angle between the two vectors
template<typename Type>
Angle clan::Vec2< Type >::angle_line ( const Vec2< Type > &  point) const

Calculate the angle of the line joining this point and other point.

Parameters
point= Second point in the line
Returns
The angle
template<typename Type>
Angle clan::Vec2< Type >::angle_normed ( const Vec2< Type > &  vector) const

Calculate the angle between this vector and an other vector, where the vectors are unit vectors.

Parameters
vector= Second vector used to calculate angle.
Returns
The angle between the two vectors
template<typename Type>
static Pointx<Type> clan::Vec2< Type >::calc_origin ( Origin  origin,
const Sizex< Type > &  size 
)
static

Returns the anchor point for the origin within the dimensions of the size structure.

Parameters
origin= The origin
size= The size
Returns
The point

Referenced by clan::Rectx< int >::apply_alignment().

template<typename Type>
Type clan::Vec2< Type >::distance ( const Vec2< Type > &  vector) const

Calculate the distance between this vector and an other vector.

Parameters
vector= Second vector used to calculate distance.
Returns
The distance between the two vectors.

Referenced by clan::Circlex< int >::is_inside().

template<typename Type>
static Type clan::Vec2< Type >::dot ( const Vec2< Type > &  vector_1,
const Vec2< Type > &  vector_2 
)
inlinestatic

Dot products a vector with an other vector.

Operates in the native datatype

Parameters
vector_1= First vector used for the dot product.
vector_2= Second vector used for the dot product.
Returns
The resulting dot product of the two vectors.
template<typename Type>
Type clan::Vec2< Type >::dot ( const Vec2< Type > &  vector) const
inline

Dot products this vector with an other vector.

Operates in the native datatype

Parameters
vectorSecond vector used for the dot product.
Returns
The resulting dot product of the two vectors.
template<typename Type>
static bool clan::Vec2< Type >::is_equal ( const Vec2< Type > &  first,
const Vec2< Type > &  second,
Type  epsilon 
)
inlinestatic

Returns true if equal within the bounds of an epsilon.

Parameters
first= Value A
second= Value B
epsilon= The epsilon (eg FLT_EPSILON/2, DBL_EPSILON/2)

Referenced by clan::Vec2< int >::is_equal().

template<typename Type>
bool clan::Vec2< Type >::is_equal ( const Vec2< Type > &  other,
Type  epsilon 
) const
inline

Returns true if equal within the bounds of an epsilon.

Parameters
other= Other value
epsilon= The epsilon (eg FLT_EPSILON/2, DBL_EPSILON/2)
template<>
double clan::Vec2< double >::length ( ) const
inline

References clan::x, and clan::y.

template<>
float clan::Vec2< float >::length ( ) const
inline

References clan::x, and clan::y.

template<typename Type>
bool clan::Vec2< Type >::operator!= ( const Vec2< Type > &  vector) const
inline

!= operator.

template<typename Type>
void clan::Vec2< Type >::operator*= ( const Vec2< Type > &  vector)
inline

*= operator.

template<typename Type>
void clan::Vec2< Type >::operator*= ( Type  value)
inline

*= operator.

template<typename Type>
void clan::Vec2< Type >::operator+= ( const Vec2< Type > &  vector)
inline

+= operator.

template<typename Type>
void clan::Vec2< Type >::operator+= ( Type  value)
inline

+= operator.

template<typename Type>
Vec2<Type> clan::Vec2< Type >::operator- ( ) const
inline

  • operator.

template<typename Type>
void clan::Vec2< Type >::operator-= ( const Vec2< Type > &  vector)
inline

-= operator.

template<typename Type>
void clan::Vec2< Type >::operator-= ( Type  value)
inline

-= operator.

template<typename Type>
void clan::Vec2< Type >::operator/= ( const Vec2< Type > &  vector)
inline

/= operator.

template<typename Type>
void clan::Vec2< Type >::operator/= ( Type  value)
inline

/= operator.

template<typename Type>
bool clan::Vec2< Type >::operator< ( const Vec2< Type > &  vector) const
inline

< operator.

template<typename Type>
Vec2<Type>& clan::Vec2< Type >::operator= ( const Vec2< Type > &  vector)
inline

= operator.

template<typename Type>
bool clan::Vec2< Type >::operator== ( const Vec2< Type > &  vector) const
inline

== operator.

template<typename Type>
static Vec2<Type> clan::Vec2< Type >::rotate ( const Vec2< Type > &  vector,
const Vec2< Type > &  hotspot,
const Angle angle 
)
static

Rotate a vector around another point.

Parameters
vector= Vector to use
hotspotThe point around which to rotate.
angle= Angle to rotate.
template<typename Type>
Vec2<Type>& clan::Vec2< Type >::rotate ( const Vec2< Type > &  hotspot,
const Angle angle 
)

Rotate this vector around another point.

Parameters
hotspotThe point around which to rotate.
angle= Angle to rotate.
Returns
reference to this object
template<typename Type>
static Vec2<Type> clan::Vec2< Type >::round ( const Vec2< Type > &  vector)
static

Rounds all components on a vector.

Uses Asymmetric Arithmetic Rounding

Parameters
vector= Vector to use
Returns
The rounded vector
template<typename Type>
Vec2<Type>& clan::Vec2< Type >::round ( )

Rounds all components of this vector.

Uses Asymmetric Arithmetic Rounding

Returns
reference to this object
template<typename Type>
Type clan::Vec2< Type >::round_value ( float  value) const

Rounds a value for the datatype.

For doubles and floats, this function does not round.

Parameters
value= Value to round
Returns
The rounded value

Member Data Documentation

union { ... }
union { ... }
template<typename Type>
Type clan::Vec2< Type >::g
template<typename Type>
Type clan::Vec2< Type >::r
template<typename Type>
Type clan::Vec2< Type >::s
template<typename Type>
Type clan::Vec2< Type >::t

The documentation for this singleton was generated from the following files: