-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdefinition.cpp
46 lines (46 loc) · 1.39 KB
/
definition.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
typedef long double ld;
const ld eps = 1e-8;
int dcmp(ld x) {
if(abs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
struct Pt {
ld x, y;
Pt(ld _x=0, ld _y=0):x(_x), y(_y) {}
Pt operator+(const Pt &a) const {
return Pt(x+a.x, y+a.y); }
Pt operator-(const Pt &a) const {
return Pt(x-a.x, y-a.y); }
Pt operator*(const ld &a) const {
return Pt(x*a, y*a); }
Pt operator/(const ld &a) const {
return Pt(x/a, y/a); }
ld operator*(const Pt &a) const {
return x*a.x + y*a.y; }
ld operator^(const Pt &a) const {
return x*a.y - y*a.x; }
bool operator<(const Pt &a) const {
return x < a.x || (x == a.x && y < a.y); }
//return dcmp(x-a.x) < 0 || (dcmp(x-a.x) == 0 && dcmp(y-a.y) < 0); }
bool operator==(const Pt &a) const {
return dcmp(x-a.x) == 0 && dcmp(y-a.y) == 0; }
};
ld norm2(const Pt &a) {
return a*a; }
ld norm(const Pt &a) {
return sqrt(norm2(a)); }
Pt perp(const Pt &a) {
return Pt(-a.y, a.x); }
Pt rotate(const Pt &a, ld ang) {
return Pt(a.x*cos(ang)-a.y*sin(ang), a.x*sin(ang)+a.y*cos(ang)); }
struct Line {
Pt s, e, v; // start, end, end-start
ld ang;
Line(Pt _s=Pt(0, 0), Pt _e=Pt(0, 0)):s(_s), e(_e) { v = e-s; ang = atan2(v.y, v.x); }
bool operator<(const Line &L) const {
return ang < L.ang;
} };
struct Circle {
Pt o; ld r;
Circle(Pt _o=Pt(0, 0), ld _r=0):o(_o), r(_r) {}
};