-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector2.cpp
70 lines (59 loc) · 1.03 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
#include "Vector2.h"
#include <cmath>
#include <string>
Vector2::Vector2(double a, double b)
{
x = a;
y = b;
}
Vector2::Vector2()
{
x = 0;
y = 0;
}
Vector2 Vector2::operator+(const Vector2& v2)
{
Vector2 temp(x + v2.x, y + v2.y);
return temp;
}
Vector2 Vector2::operator-(const Vector2& v2)
{
Vector2 temp(x - v2.x, y - v2.y);
return temp;
}
Vector2 Vector2::operator*(const Vector2& v2)
{
Vector2 temp(x * v2.x, y * v2.y);
return temp;
}
Vector2 Vector2::operator*(const double& scalar)
{
Vector2 temp(x * scalar, y * scalar);
return temp;
}
Vector2 Vector2::operator/(const double& scalar)
{
Vector2 temp(x / scalar, y / scalar);
return temp;
}
double Vector2::operator++(int)
{
double mag = sqrt(x*x + y*y);
//Vector2 temp(mag, 0);
return mag;
}
Vector2 Vector2::operator--(int)
{
Vector2 temp(x, y);
double tempMag = (temp++);//.x;
temp = temp / tempMag;
return temp;
}
std::string Vector2::toString()
{
std::string temp = "X: " + std::to_string(x) + ", Y: " + std::to_string(y);
return temp;
}
Vector2::~Vector2()
{
}