-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpoint.h
162 lines (127 loc) · 4.09 KB
/
tpoint.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef TPOINT_H
#define TPOINT_H
#include <cmath>
class TPoint {
public:
int x;
int y;
TPoint();
TPoint(int xpos, int ypos);
inline bool isCeroVector() const;
static inline int dotProduct(const TPoint &p1, const TPoint &p2) {
return p1.x * p2.x + p1.y * p2.y;
}
inline int &rx();
inline int &ry();
// Operadores:
TPoint &operator+=(const TPoint &p);
TPoint &operator-=(const TPoint &p);
TPoint &operator*=(float m);
TPoint &operator*=(double m);
TPoint &operator*=(int m);
TPoint &operator/=(float m);
friend inline bool operator==(const TPoint &, const TPoint &);
friend inline bool operator!=(const TPoint &, const TPoint &);
friend inline const TPoint operator+(const TPoint &,
const TPoint &);
friend inline const TPoint operator-(const TPoint &,
const TPoint &);
friend inline const TPoint operator*(const TPoint &, float);
friend inline const TPoint operator*(float, const TPoint &);
friend inline const TPoint operator*(const TPoint &, double);
friend inline const TPoint operator*(double, const TPoint &);
friend inline const TPoint operator*(const TPoint &, int);
friend inline const TPoint operator*(int, const TPoint &);
friend inline const TPoint operator+(const TPoint &);
friend inline const TPoint operator-(const TPoint &);
friend inline const TPoint operator/(const TPoint &, float);
private:
};
inline TPoint::TPoint() : x(0), y(0) {
}
inline TPoint::TPoint(int x, int y) : x(x), y(y) {
}
inline bool TPoint::isCeroVector() const {
return x == 0 && y == 0;
}
inline int &TPoint::rx() {
return x;
}
inline int &TPoint::ry() {
return y;
}
inline TPoint &TPoint::operator+=(const TPoint &p) {
x += p.x;
y += p.y;
return *this;
}
inline TPoint &TPoint::operator-=(const TPoint &p) {
x -= p.x;
y -= p.y;
return *this;
}
inline TPoint &TPoint::operator*=(float m) {
x = static_cast<int>(round(x * m));
y = static_cast<int>(round(y * m));
return *this;
}
inline TPoint &TPoint::operator*=(double m) {
x = static_cast<int>(round(x * m));
y = static_cast<int>(round(y * m));
return *this;
}
inline TPoint &TPoint::operator*=(int m) {
x = x * m;
y = y * m;
return *this;
}
inline TPoint &TPoint::operator/=(float c) {
x = static_cast<int>(round(x / c));
y = static_cast<int>(round(y / c));
return *this;
}
inline bool operator==(const TPoint &p1, const TPoint &p2) {
return p1.x == p2.x && p1.y == p2.y;
}
inline bool operator!=(const TPoint &p1, const TPoint &p2) {
return p1.x != p2.x || p1.y != p2.y;
}
inline const TPoint operator+(const TPoint &p1, const TPoint &p2) {
return TPoint(p1.x + p2.x, p1.y + p2.y);
}
inline const TPoint operator-(const TPoint &p1, const TPoint &p2) {
return TPoint(p1.x - p2.x, p1.y - p2.y);
}
inline const TPoint operator*(const TPoint &p, float m) {
return TPoint(static_cast<int>(round(p.x * m)),
static_cast<int>(round(p.y * m)));
}
inline const TPoint operator*(float m, const TPoint &p) {
return TPoint(static_cast<int>(round(p.x * m)),
static_cast<int>(round(p.y * m)));
}
inline const TPoint operator*(const TPoint &p, double m) {
return TPoint(static_cast<int>(round(p.x * m)),
static_cast<int>(round(p.y * m)));
}
inline const TPoint operator*(double m, const TPoint &p) {
return TPoint(static_cast<int>(round(p.x * m)),
static_cast<int>(round(p.y * m)));
}
inline const TPoint operator*(const TPoint &p, int m) {
return TPoint(p.x * m, p.y * m);
}
inline const TPoint operator*(int m, const TPoint &p) {
return TPoint(p.x * m, p.y * m);
}
inline const TPoint operator+(const TPoint &p) {
return p;
}
inline const TPoint operator-(const TPoint &p) {
return TPoint(-p.x, -p.y);
}
inline const TPoint operator/(const TPoint &p, float c) {
return TPoint(static_cast<int>(round(p.x / c)),
static_cast<int>(round(p.y / c)));
}
#endif // TPOINT_H