diff options
author | Anthony Wang | 2020-08-12 09:29:40 -0500 |
---|---|---|
committer | Anthony Wang | 2020-08-12 09:29:40 -0500 |
commit | ee5f54689c71cffdc9547bba660db58c4e9e3961 (patch) | |
tree | 052898ed4e041f2736851e9a2beb6c1ac33c9754 /Geometry | |
parent | 3b88ee3957257cd307aa6436ccc71c7509e2d3b4 (diff) |
Cleaned up geometry libraries
Diffstat (limited to 'Geometry')
-rw-r--r-- | Geometry/points_lines_vectors.cpp | 4 | ||||
-rw-r--r-- | Geometry/polygons.cpp | 8 |
2 files changed, 6 insertions, 6 deletions
diff --git a/Geometry/points_lines_vectors.cpp b/Geometry/points_lines_vectors.cpp index f381ea8..0a7bfea 100644 --- a/Geometry/points_lines_vectors.cpp +++ b/Geometry/points_lines_vectors.cpp @@ -27,7 +27,7 @@ double angle(point a, point o, point b) { return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob))); } -// (q.x - p.x) * (r.y - p.y) - (r.x - p.x) * (q.y - p.y) +// bool ccw(pl p, pl q, pl r) { return (q.f - p.f) * (r.s - p.s) - (r.f - p.f) * (q.s - p.s) > 0; } bool ccw(point p, point q, point r) { return cross(vec(p, q), vec(p, r)) > 0; } struct line { @@ -71,4 +71,4 @@ double point_to_seg(point p, seg s) { bool seg_isect(seg a, seg b) { return ccw(a.p1, a.p2, b.p1) * ccw(a.p1, a.p2, b.p2) <= 0 && ccw(b.p1, b.p2, a.p1) * ccw(b.p1, b.p2, a.p2) <= 0); -}
\ No newline at end of file +} diff --git a/Geometry/polygons.cpp b/Geometry/polygons.cpp index 12359d9..d714418 100644 --- a/Geometry/polygons.cpp +++ b/Geometry/polygons.cpp @@ -1,5 +1,5 @@ struct point { - ll x, y; // long long to avoid overflow problems + ll x, y; point() { x = y = 0; } point(ll _x, ll _y) : x(_x), y(_y) {} bool operator < (point p) const { return (x == p.x && y < p.y) || x < p.x; } @@ -27,7 +27,7 @@ double angle(point a, point o, point b) { bool ccw(point p, point q, point r) { return cross(vec(p, q), vec(p, r)) > 0; } -bool in_polygon(point pt, const vector<point>& P) { +bool in_polygon(point pt, const vector<point> & P) { double sum = 0; for (int i = 0; i < P.size() - 1; i++) { if (pt == P[i]) return true; @@ -36,14 +36,14 @@ bool in_polygon(point pt, const vector<point>& P) { return fabs(sum) > acos(-1.0); } -ll area(const vector<point>& P) { +ll area(const vector<point> & P) { ll res = 0; for (int i = 0; i < (int)P.size() - 1; i++) res += (P[i].x * P[i + 1].y - P[i + 1].x * P[i].y); return res; // return res / 2.0; } -vector<point> convex_hull(vector<point>& P) { +vector<point> convex_hull(vector<point> & P) { int n = P.size(), k = 0; vector<point> H(2 * n); sort(P.begin(), P.end()); |