-
Notifications
You must be signed in to change notification settings - Fork 1
/
Vector2.cpp
80 lines (65 loc) · 1.08 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
#include "Vector2.h"
float __forceinline __fastcall ssesqrt(float n);
Vector2::Vector2()
: x(0.0f), y(0.0f)
{
}
Vector2::Vector2(float x, float y)
: x(x), y(y)
{
}
Vector2::Vector2(float xy)
: x(xy), y(xy)
{
}
Vector2::Vector2(float* xy)
: x(xy[0]), y(xy[1])
{
}
Vector2::Vector2(const float* xy)
: x(xy[0]), y(xy[1])
{
}
//Vector2(POINT p)
// : x(p.x), y(p.y)
//{
//}
inline float Vector2::Length() const
{
return ssesqrt(x * x + y * y);
}
inline float Vector2::LengthSqr() const
{
return x * x + y * y;
}
inline Vector2& Vector2::Normalize()
{
float l = this->Length();
if (l != 0.0f)
{
*this /= l;
}
else
{
x = 0.0f;
y = 0.0f;
}
return *this;
}
inline float Vector2::Dot(const Vector2& v)
{
return x * v.x + y * v.y;
}
inline bool Vector2::IsZero() const
{
return (x == 0.0f && y == 0.0f);
}
inline bool Vector2::IsZeroTolerance(float tolerance) const
{
return (x > -tolerance && x < tolerance && y > -tolerance && y < tolerance);
}
inline std::ostream& operator<<(std::ostream& os, const Vector2& v)
{
os << "X: " << v.y << " Y: " << v.y << std::endl;
return os;
}