-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeo.cpp
65 lines (58 loc) · 1.43 KB
/
geo.cpp
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
#ifdef DELETE_THIS_IN_CASE_OF_GEO
using _t=PUT_SMTH_HERE;
using pt=complex<_t>;
const dbl EPS = 1e-16;
#define x real()
#define y imag()
namespace std {
inline bool operator<(const pt& a, const pt& b) {
if (abs(a.x - b.x) > EPS) return a.x < b.x;
if (abs(a.y - b.y) > EPS) return a.y < b.y;
return false;
}
inline bool operator>(const pt& a, const pt& b) {
return b < a;
}
}
struct Line {
pt p1, p2;
Line() {
p1 = p2 = pt(0, 0);
}
Line(const pt& _p1, const pt& _p2) {
p1 = min(_p1, _p2);
p2 = max(_p1, _p2);
}
Line(const _t a, const _t b, const _t c, const _t d) {
p1 = pt(a, b);
p2 = pt(c, d);
if (p1 > p2) swap(p1, p2);
}
inline bool operator<(const Line& o) const {
return p1 < o.p1 || (p1 == o.p1 && p2 < o.p2);
}
};
namespace std {
inline bool operator<(const Line& a, const Line& b) {
return a.p1 < b.p1 || (a.p1 == b.p1 && a.p2 < b.p2);
}
}
istream& operator>>(istream& is, pt& p) {
_t a, b;
is >> a >> b;
p = pt(a, b);
return is;
}
istream& operator>>(istream& is, Line& p) {
_t a, b, c, d;
is >> a >> b >> c >> d;
p = Line(a, b, c, d);
return is;
}
string to_string(const complex<_t>& p) {
return "(" + to_string(p.x) + ", " + to_string(p.y) + ")";
}
string to_string(const Line& a) {
return "(" + to_string(a.p1) + "--" + to_string(a.p2) + ")";
}
#endif