From 852b542913a32866d0ca6ce76cb2a9221175b4f9 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 13 Dec 2016 21:30:56 +0100 Subject: [PATCH] Had troubles with the template instantiation on OSX, so I reverted them to overloaded functions. This is certainly easier to read and work with anyway. --- xs/src/libslic3r/ClipperUtils.cpp | 40 +++++++++++++++++++++---------- xs/src/libslic3r/ClipperUtils.hpp | 26 ++++++++++---------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index 4b6eb77ad..99df3b7d1 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -133,13 +133,21 @@ ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input) return retval; } -template -T -ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input) +Slic3r::Polygons ClipperPaths_to_Slic3rPolygons(const ClipperLib::Paths &input) { - T retval; + Slic3r::Polygons retval; + retval.reserve(input.size()); for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it) - retval.push_back(ClipperPath_to_Slic3rMultiPoint(*it)); + retval.push_back(ClipperPath_to_Slic3rMultiPoint(*it)); + return retval; +} + +Slic3r::Polylines ClipperPaths_to_Slic3rPolylines(const ClipperLib::Paths &input) +{ + Slic3r::Polylines retval; + retval.reserve(input.size()); + for (ClipperLib::Paths::const_iterator it = input.begin(); it != input.end(); ++it) + retval.push_back(ClipperPath_to_Slic3rMultiPoint(*it)); return retval; } @@ -178,12 +186,18 @@ Slic3rMultiPoint_to_ClipperPath_reversed(const Slic3r::MultiPoint &input) return output; } -template -ClipperLib::Paths -Slic3rMultiPoints_to_ClipperPaths(const T &input) +ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input) { ClipperLib::Paths retval; - for (typename T::const_iterator it = input.begin(); it != input.end(); ++it) + for (Polygons::const_iterator it = input.begin(); it != input.end(); ++it) + retval.push_back(Slic3rMultiPoint_to_ClipperPath(*it)); + return retval; +} + +ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input) +{ + ClipperLib::Paths retval; + for (Polylines::const_iterator it = input.begin(); it != input.end(); ++it) retval.push_back(Slic3rMultiPoint_to_ClipperPath(*it)); return retval; } @@ -380,7 +394,7 @@ offset2(const Polygons &polygons, const float delta1, const float delta2, ClipperLib::Paths output = _offset2(polygons, delta1, delta2, joinType, miterLimit); // convert into ExPolygons - return ClipperPaths_to_Slic3rMultiPoints(output); + return ClipperPaths_to_Slic3rPolygons(output); } ExPolygons @@ -456,7 +470,7 @@ Polygons _clipper(ClipperLib::ClipType clipType, const Polygons &subject, const Polygons &clip, bool safety_offset_) { - return ClipperPaths_to_Slic3rMultiPoints(_clipper_do(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_)); + return ClipperPaths_to_Slic3rPolygons(_clipper_do(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_)); } ExPolygons @@ -473,7 +487,7 @@ _clipper_pl(ClipperLib::ClipType clipType, const Polylines &subject, { ClipperLib::Paths output; ClipperLib::PolyTreeToPaths(_clipper_do(clipType, subject, clip, ClipperLib::pftNonZero, safety_offset_), output); - return ClipperPaths_to_Slic3rMultiPoints(output); + return ClipperPaths_to_Slic3rPolylines(output); } Polylines @@ -609,7 +623,7 @@ simplify_polygons(const Polygons &subject, bool preserve_collinear) } // convert into Slic3r polygons - return ClipperPaths_to_Slic3rMultiPoints(output); + return ClipperPaths_to_Slic3rPolygons(output); } ExPolygons diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index 6d3fe73ee..28d1a054b 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -20,36 +20,36 @@ void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, Slic3r::ExPoly void PolyTreeToExPolygons(ClipperLib::PolyTree& polytree, Slic3r::ExPolygons& expolygons); //----------------------------------------------------------- -ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const Slic3r::MultiPoint &input); -template -ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const T &input); -template -T ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input); -template -T ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input); +template T ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input); +ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const Slic3r::MultiPoint &input); +ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input); +ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input); +Slic3r::Polygon ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input); +Slic3r::Polygons ClipperPaths_to_Slic3rPolygons(const ClipperLib::Paths &input); +Slic3r::Polylines ClipperPaths_to_Slic3rPolylines(const ClipperLib::Paths &input); Slic3r::ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input); // offset Polygons ClipperLib::Paths _offset(ClipperLib::Path &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit); ClipperLib::Paths _offset(ClipperLib::Paths &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit); inline Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } inline Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } // offset Polylines inline Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(Slic3rMultiPoint_to_ClipperPath(polyline), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polyline), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } inline Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(Slic3rMultiPoints_to_ClipperPaths(polylines), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polylines), ClipperLib::etOpenButt, delta, joinType, miterLimit)); } // offset expolygons and surfaces ClipperLib::Paths _offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit); ClipperLib::Paths _offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit); inline Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(expolygon, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(expolygon, delta, joinType, miterLimit)); } inline Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) - { return ClipperPaths_to_Slic3rMultiPoints(_offset(expolygons, delta, joinType, miterLimit)); } + { return ClipperPaths_to_Slic3rPolygons(_offset(expolygons, delta, joinType, miterLimit)); } inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3) { return ClipperPaths_to_Slic3rExPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); } inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)