-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathVector2.cpp
117 lines (97 loc) · 2.21 KB
/
Vector2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "Vector2.h"
#include <math.h>
namespace Engine
{
Vector2::Vector2(void)
: X(0.0f), Y(0.0f)
{ }
Vector2::Vector2(float x, float y)
: X(x), Y(y)
{ }
float Vector2::GetLength(void) const
{
return sqrt(X * X + Y * Y);
}
float Vector2::GetLengthSquared(void) const
{
return (X * X + Y * Y);
}
void Vector2::Normalize(void)
{
float length = this->GetLength();
X /= length;
Y /= length;
}
Vector2 Vector2::operator+(const Vector2 &other) const
{
return Vector2(this->X + other.X,
this->Y + other.Y);
}
Vector2 Vector2::operator+=(const Vector2 &other)
{
this->X += other.X;
this->Y += other.Y;
return *this;
}
Vector2 Vector2::operator-(const Vector2 &other) const
{
return Vector2(this->X - other.X,
this->Y - other.Y);
}
Vector2 Vector2::operator-=(const Vector2 &other)
{
this->X -= other.X;
this->Y -= other.Y;
return *this;
}
Vector2 Vector2::operator*(float scalar) const
{
return Vector2(this->X * scalar,
this->Y * scalar);
}
Vector2 Vector2::operator*=(float scalar)
{
this->X *= scalar;
this->Y *= scalar;
return *this;
}
float Vector2::operator*(const Vector2 &other) const
{
return (this->X * other.X +
this->Y * other.Y);
}
bool Vector2::operator<(const Vector2 &other) const
{
return (this->X < other.X) && (this->Y < other.Y);
}
bool Vector2::operator<=(const Vector2 &other) const
{
return (this->X <= other.X) && (this->Y <= other.Y);
}
bool Vector2::operator>(const Vector2 &other) const
{
return (this->X > other.X) && (this->Y > other.Y);
}
bool Vector2::operator>=(const Vector2 &other) const
{
return (this->X >= other.X) && (this->Y >= other.Y);
}
bool Vector2::operator==(const Vector2 &other) const
{
return (this->X == other.X) && (this->Y == other.Y);
}
bool Vector2::operator!=(const Vector2 &other) const
{
return (this->X != other.X) || (this->Y != other.Y);
}
float Vector2::Dot(const Vector2 &left, const Vector2 &right)
{
return left * right;
}
Vector2 Vector2::Normalize(const Vector2 &vector)
{
Vector2 result(vector);
result.Normalize();
return result;
}
}