clan::Vec2< Type > Class Template Reference - ClanLib SDK
Description: clan::Vec2< Type > Class Template Reference

Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clan::Vec2< Type > Class Template Reference
clanCore Math

2D vector More...

`#include <vec2.h>`

Inheritance diagram for clan::Vec2< Type >:

## Public Types
typedef Type | datatype

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

## 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.
static Type | dot (const Vec2< Type > &vector_1, const Vec2< Type > &vector_2)
| Dot products a vector with an other vector.
static bool | is_equal (const Vec2< Type > &first, const Vec2< Type > &second, Type epsilon)
| Returns true if equal within the bounds of an epsilon.
static Vec2< Type > | normalize (const Vec2< Type > &vector)
| Normalizes a vector.
static Vec2< Type > | rotate (const Vec2< Type > &vector, const Vec2< Type > &hotspot, const Angle &angle)
| Rotate a vector around another point.
static Vec2< Type > | round (const Vec2< Type > &vector)
| Rounds all components on a vector.

## Public Attributes
union { |
Type g |
Type t |
Type y |
}; |
union { |
Type r |
Type s |
Type x |
}; |

## Detailed Description

template<typename Type>
class 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

## ◆ datatype

template<typename Type>

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

## Constructor & Destructor Documentation

## ◆ Vec2() [1/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( |  | ) |
| inline

Referenced by clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), normalize(), normalize(), and clan::Vec2< unsigned char >::operator-().

## ◆ Vec2() [2/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Type & | scalar | ) |
| inlineexplicit

## ◆ Vec2() [3/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Vec3< Type > & | copy | ) |
| inlineexplicit

## ◆ Vec2() [4/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Vec4< Type > & | copy | ) |
| inlineexplicit

## ◆ Vec2() [5/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Type & | p1,
|  | const Type & | p2 )
| inlineexplicit

## ◆ Vec2() [6/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Type * | array_xy | ) |
| inlineexplicit

## ◆ Vec2() [7/9]

template<typename Type>

clan::Vec2< Type >::Vec2 | ( | const Vec2< Type > & | copy | ) |
| default

## ◆ Vec2() [8/9]

template<typename Type>
template<typename OtherType, typename std::enable_if_t< std::is_integral< Type >::value &&!std::is_integral< OtherType >::value, int > = 0>

clan::Vec2< Type >::Vec2 | ( | const Vec2< OtherType > & | copy | ) |
| inline

## ◆ Vec2() [9/9]

template<typename Type>
template<typename OtherType, typename std::enable_if_t<!std::is_integral< Type >::value||std::is_integral< OtherType >::value, int > = 0>

clan::Vec2< Type >::Vec2 | ( | const Vec2< OtherType > & | copy | ) |
| inline

## Member Function Documentation

## ◆ angle()

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

## ◆ angle_line()

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

## ◆ angle_normed()

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

## ◆ calc_origin()

template<typename Type>

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< Type >::apply_alignment().

## ◆ distance()

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.

## ◆ dot() [1/2]

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

  vector | Second vector used for the dot product.

Returns
  The resulting dot product of the two vectors.

## ◆ dot() [2/2]

template<typename Type>

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.

## ◆ is_equal() [1/2]

template<typename Type>

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< unsigned char >::is_equal().

## ◆ is_equal() [2/2]

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)

## ◆ length() [1/2]

double clan::Vec2< double >::length | ( |  | ) | const
| inline

## ◆ length() [2/2]

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

## ◆ operator!=()

template<typename Type>

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

!= operator.

## ◆ operator*=() [1/2]

template<typename Type>

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

*= operator.

## ◆ operator*=() [2/2]

template<typename Type>

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

*= operator.

## ◆ operator+=() [1/2]

template<typename Type>

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

+= operator.

## ◆ operator+=() [2/2]

template<typename Type>

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

+= operator.

## ◆ operator-()

template<typename Type>

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

- operator.

## ◆ operator-=() [1/2]

template<typename Type>

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

-= operator.

## ◆ operator-=() [2/2]

template<typename Type>

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

-= operator.

## ◆ operator/=() [1/2]

template<typename Type>

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

/= operator.

## ◆ operator/=() [2/2]

template<typename Type>

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

/= operator.

## ◆ operator<()

template<typename Type>

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

< operator.

## ◆ operator=()

template<typename Type>

Vec2< Type > & clan::Vec2< Type >::operator= | ( | const Vec2< Type > & | vector | ) |
| default

= operator.

## ◆ operator==()

template<typename Type>

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

== operator.

## ◆ rotate() [1/2]

template<typename Type>

Vec2< Type > & clan::Vec2< Type >::rotate | ( | const Vec2< Type > & | hotspot,
|  | const Angle & | angle )

Rotate this vector around another point.

Parameters

  hotspot | The point around which to rotate.
  angle | = Angle to rotate.

Returns
  reference to this object

## ◆ rotate() [2/2]

template<typename Type>

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
  hotspot | The point around which to rotate.
  angle | = Angle to rotate.

## ◆ round() [1/2]

template<typename Type>

Vec2< Type > & clan::Vec2< Type >::round | ( |  | ) |

Rounds all components of this vector.

Uses Asymmetric Arithmetic Rounding

Returns
  reference to this object

## ◆ round() [2/2]

template<typename Type>

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

## ◆ round_value()

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 { ... } clan::Vec2< Type >

## ◆ [union]

union { ... } clan::Vec2< Type >

## ◆ g

template<typename Type>

Type clan::Vec2< Type >::g

## ◆ r

template<typename Type>

Type clan::Vec2< Type >::r

## ◆ s

template<typename Type>

Type clan::Vec2< Type >::s

## ◆ t

template<typename Type>

Type clan::Vec2< Type >::t

## ◆ x

template<typename Type>

Type clan::Vec2< Type >::x

Referenced by clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Rectx< Type >::apply_alignment(), clan::Vec2< unsigned char >::dot(), clan::Vec2< unsigned char >::dot(), clan::Vec2< unsigned char >::is_equal(), length(), normalize(), clan::Vec2< unsigned char >::operator!=(), clan::operator*(), clan::Vec2< unsigned char >::operator*=(), clan::operator+(), clan::Vec2< unsigned char >::operator+=(), clan::operator-(), clan::Vec2< unsigned char >::operator-=(), clan::operator/(), clan::Vec2< unsigned char >::operator/=(), clan::Vec2< unsigned char >::operator<(), clan::operator<<(), clan::Vec2< unsigned char >::operator==(), clan::ProgramObject::set_uniform2b(), clan::ProgramObject::set_uniform2f(), clan::ProgramObject::set_uniform2i(), clan::ProgramObject::set_uniform2s(), clan::ProgramObject::set_uniformfv(), clan::ProgramObject::set_uniformiv(), clan::Vec4< unsigned char >::set_xy(), clan::Vec4< unsigned char >::set_zw(), clan::step(), and clan::Mat3< int >::translate().

## ◆ y

template<typename Type>

Type clan::Vec2< Type >::y

Referenced by clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Pointx< Type >::Pointx(), clan::Rectx< Type >::apply_alignment(), clan::Vec2< unsigned char >::dot(), clan::Vec2< unsigned char >::dot(), clan::Vec2< unsigned char >::is_equal(), length(), normalize(), clan::Vec2< unsigned char >::operator!=(), clan::operator*(), clan::Vec2< unsigned char >::operator*=(), clan::operator+(), clan::Vec2< unsigned char >::operator+=(), clan::operator-(), clan::Vec2< unsigned char >::operator-=(), clan::operator/(), clan::Vec2< unsigned char >::operator/=(), clan::Vec2< unsigned char >::operator<(), clan::operator<<(), clan::Vec2< unsigned char >::operator==(), clan::ProgramObject::set_uniform2b(), clan::ProgramObject::set_uniform2f(), clan::ProgramObject::set_uniform2i(), clan::ProgramObject::set_uniform2s(), clan::Vec4< unsigned char >::set_xy(), clan::Vec4< unsigned char >::set_zw(), clan::step(), and clan::Mat3< int >::translate().

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

- line.h
- vec2.h