-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tvector.cpp
68 lines (57 loc) · 1.32 KB
/
Tvector.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
#include "Tvector.h"
Vector2D::Vector2D() {
x = 0.0f;
y = 0.0f;
}
Vector2D::Vector2D(float x, float y) {
this->x = x;
this->y = y;
}
Vector2D& Vector2D::Sestej(const Vector2D& vec) {
this->x += vec.x;
this->y += vec.y;
return *this;
}
Vector2D& Vector2D::Odstej(const Vector2D& vec) {
this->x -= vec.x;
this->y -= vec.y;
return *this;
}
Vector2D& Vector2D::Mnozi(const Vector2D& vec) {
this->x *= vec.x;
this->y *= vec.y;
return *this;
}
Vector2D& Vector2D::Deli(const Vector2D& vec) {
this->x /= vec.x;
this->y /= vec.y;
return *this;
}
Vector2D operator+(Vector2D& v1, const Vector2D& v2) {
return v1.Sestej(v2);
}
Vector2D operator-(Vector2D& v1, const Vector2D& v2) {
return v1.Odstej(v2);
}
Vector2D operator*(Vector2D& v1, const Vector2D& v2) {
return v1.Mnozi(v2);
}
Vector2D operator/(Vector2D& v1, const Vector2D& v2) {
return v1.Deli(v2);
}
Vector2D& Vector2D::operator+=(const Vector2D& vec) {
return this->Sestej(vec);
}
Vector2D& Vector2D::operator-=(const Vector2D& vec) {
return this->Odstej(vec);
}
Vector2D& Vector2D::operator*=(const Vector2D& vec) {
return this->Mnozi(vec);
}
Vector2D& Vector2D::operator/=(const Vector2D& vec) {
return this->Deli(vec);
}
std::ostream& operator<<(std::ostream& stream, const Vector2D& vec) {
stream << "(" << vec.x << "," << vec.y << ")";
return stream;
}