-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2D.cpp
More file actions
124 lines (96 loc) · 2.17 KB
/
Copy pathVector2D.cpp
File metadata and controls
124 lines (96 loc) · 2.17 KB
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
118
119
120
121
122
123
124
#include "Vector2D.h"
#include <iostream>
#pragma region constructors_destructors
Vector2D::Vector2D() {
x = 0.0f;
y = 0.0f;
//std::cout << "Vector 2D created (0,0) constructor" << std::endl;
}
Vector2D::Vector2D(float xp, float yp) {
x = xp;
y = yp;
//std::cout << "Vector 2D created (x,y) constructor" << std::endl;
}
Vector2D::~Vector2D() {}
#pragma endregion
#pragma region operations
Vector2D& Vector2D::add(const Vector2D& v2) {
this->x += v2.x;
this->y += v2.y;
return *this;
}
Vector2D& Vector2D::subtract(const Vector2D& v2) {
this->x -= v2.x;
this->y -= v2.y;
return *this;
}
Vector2D& Vector2D::multiply(const Vector2D& v2) {
this->x *= v2.x;
this->y *= v2.y;
return *this;
}
Vector2D& Vector2D::divide(const Vector2D& v2) {
this->x /= v2.x;
this->y /= v2.y;
return *this;
}
#pragma endregion
#pragma region operators_overloading
Vector2D& Vector2D::operator+(const Vector2D& v2) {
return this->add(v2);
}
Vector2D& Vector2D::operator-(const Vector2D& v2) {
return this->subtract(v2);
}
Vector2D& Vector2D::operator*(const Vector2D& v2) {
return this->multiply(v2);
}
Vector2D& Vector2D::operator/(const Vector2D& v2) {
return this->divide(v2);
}
Vector2D& Vector2D::operator=(const Vector2D& v2) {
this->x = v2.x;
this->y = v2.y;
return *this;
}
#pragma endregion
#pragma region operations_overloading_=
Vector2D& Vector2D::operator+=(const Vector2D& v2) {
return this->add(v2);
}
Vector2D& Vector2D::operator-=(const Vector2D& v2) {
return this->subtract(v2);
}
Vector2D& Vector2D::operator*=(const Vector2D& v2) {
return this->multiply(v2);
}
Vector2D& Vector2D::operator/=(const Vector2D& v2) {
return this->divide(v2);
}
#pragma endregion
#pragma region operations_(int)
Vector2D Vector2D::operator+(int x) {
Vector2D temp;
temp.x = this->x + x;
temp.y = this->y + x;
return temp;
}
Vector2D Vector2D::operator-(int x) {
Vector2D temp;
temp.x = this->x - x;
temp.y = this->y - x;
return temp;
}
Vector2D Vector2D::operator*(int x) {
Vector2D temp;
temp.x = this->x * x;
temp.y = this->y * x;
return temp;
}
Vector2D Vector2D::operator/(int x) {
Vector2D temp;
temp.x = this->x / x;
temp.y = this->y / x;
return temp;
}
#pragma endregion