mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
Finished porting convex_hull() to XS and removed dependency on Math::ConvexHull::MonotoneChain
This commit is contained in:
parent
5309e3ef22
commit
de9d5403e8
5 changed files with 21 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,13 @@ Point::rotate(double angle, Point* center)
|
|||
bool
|
||||
Point::coincides_with(const Point* point) const
|
||||
{
|
||||
return this->x == point->x && this->y == point->y;
|
||||
return this->coincides_with(*point);
|
||||
}
|
||||
|
||||
bool
|
||||
Point::coincides_with(const Point &point) const
|
||||
{
|
||||
return this->x == point.x && this->y == point.y;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -20,6 +20,7 @@ class Point
|
|||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void rotate(double angle, Point* center);
|
||||
bool coincides_with(const Point &point) const;
|
||||
bool coincides_with(const Point* point) const;
|
||||
int nearest_point_index(const Points points) const;
|
||||
Point* nearest_point(Points points) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue