-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.h
73 lines (44 loc) · 2.12 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
#pragma once
#include "Util.h"
class Point {
public:
int x = 0;
int y = 0;
Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) { }
Point(const POINT& p);
inline operator POINT () const { return asPOINT(); }
inline POINT asPOINT() const { return POINT{ x, y }; }
inline Vector2D asVector2D() const { return Vector2D(x, y); }
inline operator Vector2D () const { return asVector2D(); }
// operator POINT* () const { return &asPOINT(); } // does it work?
inline void operator=(const POINT& p) { *this = Point(p); }
inline Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
inline Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
inline Point operator*(const Point& p) const { return Point(x * p.x, y * p.y); }
inline Point operator/(const Point& p) const { return Point(x / p.x, y / p.y); }
inline void operator+=(const Point& p) { x += p.x; y += p.y; }
inline void operator-=(const Point& p) { x -= p.x; y -= p.y; }
inline void operator*=(const Point& p) { x *= p.x; y *= p.y; }
inline void operator/=(const Point& p) { x /= p.x; y /= p.y; }
inline Point operator*(int v) const { return Point(x * v, y * v); }
inline Point operator/(int v) const { return Point(x / v, y / v); }
inline void operator*=(int v) { x *= v; y *= v; }
inline void operator/=(int v) { x /= v; y /= v; }
inline Point operator*(float v) const { return Point(x * v, y * v); }
inline Point operator/(float v) const { return Point(x / v, y / v); }
inline Point operator*(double v) const { return Point(x * v, y * v); }
inline Point operator/(double v) const { return Point(x / v, y / v); }
inline bool operator!=(const Point& p) const { return p.x != x || p.y != y; }
inline bool operator==(const Point& p) const { return !operator!=(p); }
bool inRange(const Point& p, int range = 3) const;
bool sanp(Point& p) {
if (!p.inRange(*this, 12))
return false;
p = *this;
return true;
}
void draw(HDC hdc_, int size, bool isHover = false) const;
void draw(HDC hdc_, int size, HPEN hpen, HBRUSH) const;
void save(std::ofstream& f);
static void load(std::ifstream& f, Point& p);
};