Finished porting convex_hull() to XS and removed dependency on Math::ConvexHull::MonotoneChain

This commit is contained in:
Alessandro Ranellucci 2013-11-22 22:48:07 +01:00
parent 5309e3ef22
commit de9d5403e8
5 changed files with 21 additions and 7 deletions

View file

@ -9,6 +9,9 @@ sort_points (Point a, Point b)
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}
/* This implementation is based on Steffen Mueller's work for
the Perl module Math::ConvexHull::MonotoneChain (available
on CPAN under the GPL terms) */
void
convex_hull(Points points, Polygon &hull)
{
@ -40,6 +43,10 @@ convex_hull(Points points, Polygon &hull)
hull.points.push_back(*(out_hull[i]));
}
// not sure why this happens randomly
if (hull.points.front().coincides_with(hull.points.back()))
hull.points.pop_back();
free(out_hull);
}