-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.h
101 lines (77 loc) · 1.67 KB
/
point.h
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
/*!
* @file Point.h v1.0
* @Copyright © 2018 Kazushi Kurasawa
* @date 2018.11.16
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#ifndef NEWZUZUMOUSE_POINT_H
#define NEWZUZUMOUSE_POINT_H
#include <cmath>
#include <inttypes.h>
template <typename T>
struct Point{
public:
Point():x(0),y(0){}
Point(T _x, T _y):x(_x),y(_y){}
T x;
T y;
};
struct Position : public Point<double_t>{
public:
Position():rad(0.0){
x = 0.0;
y = 0.0;
}
Position(const Position& _p): Point(), rad(_p.rad) {
x = _p.x;
y = _p.y;
}
double_t rad;
Position operator -(const Position& p){
Position v;
v.x = x - p.x;
v.y = y - p.y;
v.rad = rad - p.rad;
return v;
}
Position operator +(const Position& p){
Position v;
v.x = x + p.x;
v.y = y + p.y;
v.rad = rad + p.rad;
return v;
}
Position operator /(const Position& p){
Position v;
v.x = x / p.x;
v.y = y / p.y;
v.rad = rad / p.rad;
return v;
}
Position operator *(const Position& p){
Position v;
v.x = x * p.x;
v.y = y * p.y;
v.rad = rad * p.rad;
return v;
}
};
struct MapPosition : public Point<uint8_t>{
public:
uint8_t direction;
explicit operator Point<uint8_t>(){
Point<uint8_t> p;
p.x = x;
p.y = y;
return p;
}
bool operator==(const MapPosition& _p)const{
return ((x ==_p.x) && (y == _p.y));
}
bool operator!=(const MapPosition& _p)const{
return !operator==(_p);
}
};
#endif //NEWZUZUMOUSE_POINT_H