CSEngine
Loading...
Searching...
No Matches
CSE::Vector2< T > Class Template Reference

Public Member Functions

 Vector2 (T x, T y)
 
void Set (T x, T y)
 
Dot (const Vector2 &v) const
 
Vector2 operator+ (const Vector2 &v) const
 
Vector2 operator- (const Vector2 &v) const
 
Vector2 operator- () const
 
void operator+= (const Vector2 &v)
 
void operator-= (const Vector2 &v)
 
Vector2 operator/ (T s) const
 
Vector2 operator* (float s) const
 
void operator/= (float s)
 
void operator*= (float s)
 
void Normalize ()
 
Vector2 Normalized () const
 
LengthSquared () const
 
Length () const
 
 operator Vector2< float > () const
 
bool operator== (const Vector2 &v) const
 
Vector2 Lerp (float t, const Vector2 &v) const
 
const T * Pointer () const
 
template<typename P >
P * Write (P *pData)
 

Static Public Member Functions

static float Distance (const Vector2 &a, const Vector2 &b)
 

Public Attributes

x
 
y
 

Detailed Description

template<typename T>
class CSE::Vector2< T >

Definition at line 11 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector2() [1/2]

template<typename T >
CSE::Vector2< T >::Vector2 ( )
inline

Definition at line 14 of file Vector.h.

14{}

◆ Vector2() [2/2]

template<typename T >
CSE::Vector2< T >::Vector2 ( x,
y 
)
inline

Definition at line 16 of file Vector.h.

16: x(x), y(y) {}

◆ ~Vector2()

template<typename T >
CSE::Vector2< T >::~Vector2 ( )
inline

Definition at line 18 of file Vector.h.

18{}

Member Function Documentation

◆ Distance()

template<typename T >
static float CSE::Vector2< T >::Distance ( const Vector2< T > &  a,
const Vector2< T > &  b 
)
inlinestatic

Definition at line 98 of file Vector.h.

98 {
99 return sqrtf(powf(a.x - b.x, 2) + powf(a.y - b.y, 2));
100 }

◆ Dot()

template<typename T >
T CSE::Vector2< T >::Dot ( const Vector2< T > &  v) const
inline

Definition at line 25 of file Vector.h.

25 {
26 return x * v.x + y * v.y;
27 }

◆ Length()

template<typename T >
T CSE::Vector2< T >::Length ( ) const
inline

Definition at line 81 of file Vector.h.

81 {
82 return sqrt(LengthSquared());
83 }

◆ LengthSquared()

template<typename T >
T CSE::Vector2< T >::LengthSquared ( ) const
inline

Definition at line 77 of file Vector.h.

77 {
78 return x * x + y * y;
79 }

◆ Lerp()

template<typename T >
Vector2 CSE::Vector2< T >::Lerp ( float  t,
const Vector2< T > &  v 
) const
inline

Definition at line 93 of file Vector.h.

93 {
94 return Vector2(x * (1 - t) + v.x * t,
95 y * (1 - t) + v.y * t);
96 }

◆ Normalize()

template<typename T >
void CSE::Vector2< T >::Normalize ( )
inline

Definition at line 65 of file Vector.h.

65 {
66 float s = 1.0f / Length();
67 x *= s;
68 y *= s;
69 }

◆ Normalized()

template<typename T >
Vector2 CSE::Vector2< T >::Normalized ( ) const
inline

Definition at line 71 of file Vector.h.

71 {
72 Vector2 v = *this;
73 v.Normalize();
74 return v;
75 }

◆ operator Vector2< float >()

template<typename T >
CSE::Vector2< T >::operator Vector2< float > ( ) const
inlineexplicit

Definition at line 85 of file Vector.h.

85 {
86 return Vector2<float>(x, y);
87 }

◆ operator*()

template<typename T >
Vector2 CSE::Vector2< T >::operator* ( float  s) const
inline

Definition at line 53 of file Vector.h.

53 {
54 return Vector2(x * s, y * s);
55 }

◆ operator*=()

template<typename T >
void CSE::Vector2< T >::operator*= ( float  s)
inline

Definition at line 61 of file Vector.h.

61 {
62 *this = Vector2(x * s, y * s);
63 }

◆ operator+()

template<typename T >
Vector2 CSE::Vector2< T >::operator+ ( const Vector2< T > &  v) const
inline

Definition at line 29 of file Vector.h.

29 {
30 return Vector2(x + v.x, y + v.y);
31 }

◆ operator+=()

template<typename T >
void CSE::Vector2< T >::operator+= ( const Vector2< T > &  v)
inline

Definition at line 41 of file Vector.h.

41 {
42 *this = Vector2(x + v.x, y + v.y);
43 }

◆ operator-() [1/2]

template<typename T >
Vector2 CSE::Vector2< T >::operator- ( ) const
inline

Definition at line 37 of file Vector.h.

37 {
38 return Vector2(-x, -y);
39 }

◆ operator-() [2/2]

template<typename T >
Vector2 CSE::Vector2< T >::operator- ( const Vector2< T > &  v) const
inline

Definition at line 33 of file Vector.h.

33 {
34 return Vector2(x - v.x, y - v.y);
35 }

◆ operator-=()

template<typename T >
void CSE::Vector2< T >::operator-= ( const Vector2< T > &  v)
inline

Definition at line 45 of file Vector.h.

45 {
46 *this = Vector2(x - v.x, y - v.y);
47 }

◆ operator/()

template<typename T >
Vector2 CSE::Vector2< T >::operator/ ( s) const
inline

Definition at line 49 of file Vector.h.

49 {
50 return Vector2(x / s, y / s);
51 }

◆ operator/=()

template<typename T >
void CSE::Vector2< T >::operator/= ( float  s)
inline

Definition at line 57 of file Vector.h.

57 {
58 *this = Vector2(x / s, y / s);
59 }

◆ operator==()

template<typename T >
bool CSE::Vector2< T >::operator== ( const Vector2< T > &  v) const
inline

Definition at line 89 of file Vector.h.

89 {
90 return x == v.x && y == v.y;
91 }

◆ Pointer()

template<typename T >
const T * CSE::Vector2< T >::Pointer ( ) const
inline

Definition at line 102 of file Vector.h.

102 {
103 return &x;
104 }

◆ Set()

template<typename T >
void CSE::Vector2< T >::Set ( x,
y 
)
inline

Definition at line 20 of file Vector.h.

20 {
21 this->x = x;
22 this->y = y;
23 }

◆ Write()

template<typename T >
template<typename P >
P * CSE::Vector2< T >::Write ( P *  pData)
inline

Definition at line 107 of file Vector.h.

107 {
108 Vector2* pVector = (Vector2*) pData;
109 *pVector++ = *this;
110 return (P*) pVector;
111 }

Member Data Documentation

◆ x

template<typename T >
T CSE::Vector2< T >::x

Definition at line 113 of file Vector.h.

◆ y

template<typename T >
T CSE::Vector2< T >::y

Definition at line 114 of file Vector.h.


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