53
|
1 |
#ifndef COOR_H
|
|
2 |
#define COOR_H
|
46
|
3 |
|
55
|
4 |
#include <iostream>
|
51
|
5 |
|
55
|
6 |
template <typename T>
|
|
7 |
class _Vector {
|
51
|
8 |
public:
|
55
|
9 |
T x;
|
|
10 |
T y;
|
|
11 |
|
|
12 |
_Vector() : x(0), y(0){}
|
|
13 |
_Vector(T x, T y) : x(x), y(y) {}
|
|
14 |
_Vector(const _Vector& v) : x(v.x), y(v.y) {}
|
|
15 |
|
|
16 |
void operator=(const _Vector& v) {
|
|
17 |
this->x = v.x;
|
|
18 |
this->y = v.y;
|
53
|
19 |
}
|
55
|
20 |
_Vector operator+(const _Vector& v) const {
|
|
21 |
return _Vector(this->x+v.x, this->y+v.y);
|
53
|
22 |
}
|
55
|
23 |
_Vector operator-(const _Vector& v) const {
|
|
24 |
return _Vector(this->x-v.x, this->y-v.y);
|
53
|
25 |
}
|
55
|
26 |
_Vector operator*(const T d) const {
|
|
27 |
return _Vector(this->x*d, this->y*d);
|
51
|
28 |
}
|
55
|
29 |
_Vector operator/(const T d) const {
|
|
30 |
return _Vector(this->x/d, this->y/d);
|
|
31 |
}
|
|
32 |
void operator+=(const _Vector& v) {
|
|
33 |
this->x += v.x;
|
|
34 |
this->y += v.y;
|
51
|
35 |
}
|
55
|
36 |
void operator*=(const T f) {
|
|
37 |
this->x *= f;
|
|
38 |
this->y *= f;
|
|
39 |
}
|
51
|
40 |
};
|
46
|
41 |
|
53
|
42 |
template<typename T>
|
55
|
43 |
bool operator==(const _Vector<T>& v1, const _Vector<T>& v2) {
|
|
44 |
return ((v1.x == v2.x) && (v1.y == v2.y));
|
53
|
45 |
}
|
|
46 |
|
55
|
47 |
template<typename T>
|
|
48 |
std::ostream& operator<<(std::ostream &s, _Vector<T> &v) {
|
|
49 |
return s<<"("<<v.x<<", "<<v.y<<")";
|
|
50 |
}
|
|
51 |
|
|
52 |
typedef _Vector<uint32_t> Vector;
|
|
53 |
|
46
|
54 |
#endif
|