From 022253327389a343abd029499b6040696f615e1d Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 14 Oct 2021 09:31:53 +0200 Subject: [PATCH] Fixed compilation on non MS systems --- src/libslic3r/ClipperUtils.cpp | 79 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/libslic3r/ClipperUtils.cpp b/src/libslic3r/ClipperUtils.cpp index 5e54da6843..ebf13bedfd 100644 --- a/src/libslic3r/ClipperUtils.cpp +++ b/src/libslic3r/ClipperUtils.cpp @@ -156,6 +156,45 @@ bool has_duplicate_points(const ClipperLib::PolyTree &polytree) } #endif +// Offset CCW contours outside, CW contours (holes) inside. +// Don't calculate union of the output paths. +template +static ClipperLib::Paths raw_offset(PathsProvider &&paths, float offset, ClipperLib::JoinType joinType, double miterLimit) +{ + ClipperLib::ClipperOffset co; + ClipperLib::Paths out; + out.reserve(paths.size()); + ClipperLib::Paths out_this; + if (joinType == jtRound) + co.ArcTolerance = miterLimit; + else + co.MiterLimit = miterLimit; + co.ShortestEdgeLength = double(std::abs(offset * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); + for (const ClipperLib::Path &path : paths) { + co.Clear(); + // Execute reorients the contours so that the outer most contour has a positive area. Thus the output + // contours will be CCW oriented even though the input paths are CW oriented. + // Offset is applied after contour reorientation, thus the signum of the offset value is reversed. + co.AddPath(path, joinType, endType); + bool ccw = endType == ClipperLib::etClosedPolygon ? ClipperLib::Orientation(path) : true; + co.Execute(out_this, ccw ? offset : - offset); + if (! ccw) { + // Reverse the resulting contours. + for (ClipperLib::Path &path : out_this) + std::reverse(path.begin(), path.end()); + } + append(out, std::move(out_this)); + } + return out; +} + +// Offset outside by 10um, one by one. +template +static ClipperLib::Paths safety_offset(PathsProvider &&paths) +{ + return raw_offset(std::forward(paths), ClipperSafetyOffset, DefaultJoinType, DefaultMiterLimit); +} + template TResult clipper_do( const ClipperLib::ClipType clipType, @@ -206,38 +245,6 @@ ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input, bool return PolyTreeToExPolygons(clipper_union(input, do_union ? ClipperLib::pftNonZero : ClipperLib::pftEvenOdd)); } -// Offset CCW contours outside, CW contours (holes) inside. -// Don't calculate union of the output paths. -template -static ClipperLib::Paths raw_offset(PathsProvider &&paths, float offset, ClipperLib::JoinType joinType, double miterLimit) -{ - ClipperLib::ClipperOffset co; - ClipperLib::Paths out; - out.reserve(paths.size()); - ClipperLib::Paths out_this; - if (joinType == jtRound) - co.ArcTolerance = miterLimit; - else - co.MiterLimit = miterLimit; - co.ShortestEdgeLength = double(std::abs(offset * CLIPPER_OFFSET_SHORTEST_EDGE_FACTOR)); - for (const ClipperLib::Path &path : paths) { - co.Clear(); - // Execute reorients the contours so that the outer most contour has a positive area. Thus the output - // contours will be CCW oriented even though the input paths are CW oriented. - // Offset is applied after contour reorientation, thus the signum of the offset value is reversed. - co.AddPath(path, joinType, endType); - bool ccw = endType == ClipperLib::etClosedPolygon ? ClipperLib::Orientation(path) : true; - co.Execute(out_this, ccw ? offset : - offset); - if (! ccw) { - // Reverse the resulting contours. - for (ClipperLib::Path &path : out_this) - std::reverse(path.begin(), path.end()); - } - append(out, std::move(out_this)); - } - return out; -} - template static ClipperLib::Paths raw_offset_polyline(PathsProvider &&paths, float offset, ClipperLib::JoinType joinType, double miterLimit) { @@ -245,13 +252,6 @@ static ClipperLib::Paths raw_offset_polyline(PathsProvider &&paths, float offset return raw_offset(std::forward(paths), offset, joinType, miterLimit); } -// Offset outside by 10um, one by one. -template -static ClipperLib::Paths safety_offset(PathsProvider &&paths) -{ - return raw_offset(std::forward(paths), ClipperSafetyOffset, DefaultJoinType, DefaultMiterLimit); -} - template static TResult expand_paths(PathsProvider &&paths, float offset, ClipperLib::JoinType joinType, double miterLimit) { @@ -259,6 +259,7 @@ static TResult expand_paths(PathsProvider &&paths, float offset, ClipperLib::Joi return clipper_union(raw_offset(std::forward(paths), offset, joinType, miterLimit)); } +// used by shrink_paths() template static void remove_outermost_polygon(Container & solution); template<> static void remove_outermost_polygon(ClipperLib::Paths &solution) { if (! solution.empty()) solution.erase(solution.begin()); }