-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint_structure.cpp
More file actions
32 lines (25 loc) · 875 Bytes
/
point_structure.cpp
File metadata and controls
32 lines (25 loc) · 875 Bytes
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
struct Point {
int x, y;
Point() {}
Point(int _x, int _y) : x(_x), y(_y) {}
Point operator-(const Point &p) const { // vector
return Point(x - p.x, y - p.y);
}
int operator*(const Point &p) const { // cross product
return x * p.y - y * p.x;
}
int operator^(const Point &p) const { // dot product
return x * p.x + y * p.y;
}
int dis(const Point &p) const { // distance
return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);
}
};
bool cw(Point &a, Point &b, Point &c) { // clockwise orientation
int area = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
return area < 0;
}
bool ccw(Point &a, Point &b, Point &c) { // counter-clockwise orientation
int area = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
return area > 0;
}