-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.h
78 lines (63 loc) · 1.59 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
#pragma once
#include <ostream>
#include <algorithm>
struct point
{
int x, y;
point() { x = y = 0; }
point(int i) { x = y = i; }
constexpr point(int x, int y) { this->x = x; this->y = y; }
};
inline point operator -(point p) { return { -p.x, -p.y }; }
inline constexpr point operator ~(point p) { return { p.y, p.x }; }
inline bool operator ^=(point a, point b) { return a.x == b.x || a.y == b.y; }
inline void swap_point_if(point& s, point& b)
{
if (s.x > b.x) std::swap(s.x, b.x);
if (s.y > b.y) std::swap(s.y, b.y);
}
inline void operator |(point& s, point& b) { swap_point_if(s, b); }
inline void clamp_point(point& p, point s, point b)
{
p.x = std::clamp(p.x, s.x, b.x);
p.y = std::clamp(p.y, s.y, b.y);
}
inline std::ostream& operator <<(std::ostream& os, point p)
{
os << '(' << p.x << ',' << ' ' << p.y << ')';
return os;
}
#define OPA(S) inline point operator S(point a, point b) { return { a.x S b.x, a.y S b.y }; }
#define OIA(S) inline point operator S(point a, int b) { return { a.x S b, a.y S b }; }
#define OB(S, J) inline bool operator S(point a, point b) { return a.x S b.x J a.y S b.y; }
#define OPV(S) inline void operator S(point& a, point b) { a.x S b.x; a.y S b.y; }
#define OIV(S) inline void operator S(point& a, int b) { a.x S b; a.y S b; }
OPA(+)
OPA(-)
OPA(*)
OPA(/)
OPA(%)
OIA(+)
constexpr OIA(-)
OIA(*)
OIA(/)
OIA(%)
OIA(&)
OIA(|)
OIA(<<)
constexpr OIA(>>)
OB(==, &&)
OB(!=, ||)
OB(<, &&)
OB(>, &&)
OB(<=, &&)
OB(>=, &&)
OPV(+=)
OPV(-=)
OIV(+=)
OIV(-=)
OIV(%=)
OIV(*=)
OIV(/=)
OIV(<<=)
OIV(>>=)