Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2015-01-19 20:53:04 +0300
committerAlessandro Ranellucci <aar@cpan.org>2015-01-19 20:53:04 +0300
commit8791f5a493d476c3e42a4d5c91f5a4b182fe2b18 (patch)
treec04dd0a73b8b30509791617539c7765d09307658 /xs/src/libslic3r/Geometry.cpp
parentc9cdae1a9659496f06066eb612e2baf55edfe4c4 (diff)
Cleanup of some method signatures and of XS return types
Diffstat (limited to 'xs/src/libslic3r/Geometry.cpp')
-rw-r--r--xs/src/libslic3r/Geometry.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp
index e30e73702..8169da5a3 100644
--- a/xs/src/libslic3r/Geometry.cpp
+++ b/xs/src/libslic3r/Geometry.cpp
@@ -25,42 +25,45 @@ sort_points (Point a, Point b)
}
/* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */
-void
-convex_hull(Points points, Polygon* hull)
+Polygon
+convex_hull(Points points)
{
assert(points.size() >= 3);
// sort input points
std::sort(points.begin(), points.end(), sort_points);
int n = points.size(), k = 0;
- hull->points.resize(2*n);
+ Polygon hull;
+ hull.points.resize(2*n);
// Build lower hull
for (int i = 0; i < n; i++) {
- while (k >= 2 && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
- hull->points[k++] = points[i];
+ while (k >= 2 && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
+ hull.points[k++] = points[i];
}
// Build upper hull
for (int i = n-2, t = k+1; i >= 0; i--) {
- while (k >= t && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
- hull->points[k++] = points[i];
+ while (k >= t && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
+ hull.points[k++] = points[i];
}
- hull->points.resize(k);
+ hull.points.resize(k);
+
+ assert( hull.points.front().coincides_with(hull.points.back()) );
+ hull.points.pop_back();
- assert( hull->points.front().coincides_with(hull->points.back()) );
- hull->points.pop_back();
+ return hull;
}
-void
-convex_hull(const Polygons &polygons, Polygon* hull)
+Polygon
+convex_hull(const Polygons &polygons)
{
Points pp;
for (Polygons::const_iterator p = polygons.begin(); p != polygons.end(); ++p) {
pp.insert(pp.end(), p->points.begin(), p->points.end());
}
- convex_hull(pp, hull);
+ return convex_hull(pp);
}
/* accepts an arrayref of points and returns a list of indices