Skip to content

Commit

Permalink
Updated convex hull code to remove duplicate points.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADJA committed Jun 11, 2014
1 parent 6fa69c0 commit 529b54b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Geometry/ConvexHull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Convex Hull [ Graham-Andrew method, O(NlogN) ]
Based on problem 638 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=638#1
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=638
Tested on problem 290 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=&chapterid=290
**********************************************************************************/

Expand Down Expand Up @@ -31,12 +34,17 @@ bool cmp(point a, point b) {
return (a.x < b.x || (a.x == b.x && a.y < b.y));
}

bool eq(point a, point b) {
return (a.x == b.x && a.y == b.y);
}

bool isCCW(point a, point b, point c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}

void setConvexHull(vector <point> p, vector <point> &h) {
sort(p.begin(), p.end(), cmp);
p.erase(unique(p.begin(), p.end(), eq), p.end());

vector <point> up, down;
point head = p[0], tail = p.back();
Expand Down

0 comments on commit 529b54b

Please sign in to comment.