-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.h
104 lines (84 loc) · 2.35 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
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
#define ld long double
#define ll long long int
#define t1(x) cerr<<#x<<" : "<<x<<endl
#define t2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z) cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
extern const ld defaultAngle = 0.01;
typedef struct Point
{
ld x,y;
Point(): x(0), y(0) {}
Point(ld x, ld y): x(x), y(y) {}
Point(const Point &p): x(p.getX()), y(p.getY()) {}
ld length() const
{
return sqrtl(x*x + y*y);
}
ld length2() const
{
return x*x + y*y;
}
ld getX() const {return x;}
ld getY() const {return y;}
ld cross(Point lhs, Point rhs)
{
return (lhs-*this)*(rhs-*this);
}
Point operator + (Point rhs)
{
return Point(x+rhs.x, y+rhs.y);
}
Point operator - (Point rhs)
{
return Point(x-rhs.x, y-rhs.y);
}
ld operator * (Point rhs)
{
return x*rhs.y - y*rhs.x;
}
bool operator == (Point p)
{
return (p.getX() == x && p.getY() == y);
}
bool operator == (const Point &p) const
{
return (p.getX() == x && p.getY() == y);
}
bool operator < (const Point p) const
{
if(y < p.getY()) return true;
if(p.getY() == y) return x < p.getX();
return false;
}
void rotate(ld angle = defaultAngle)
{
if(angle > 0) y *= -1;
ld s = sin(angle);
ld c = cos(angle);
// rotate point
ld xnew = x * c - y * s;
ld ynew = x * s + y * c;
x = xnew;
y = ynew;
x = ((ll)(1e6*x))/1e6;
y = ((ll)(1e6*y))/1e6;
if(angle < 0) y*= -1;
}
std::pair<ld,ld> getPair()
{
return std::make_pair(x,y);
}
std::string to_string()
{
// this->rotate(-defaultAngle);
std::string tempString = "( " + std::to_string(x) + ", " + std::to_string(y) + " )";
// this->rotate(defaultAngle);
return tempString;
}
} Point;