diff --git a/lib/Slic3r/Surface.pm b/lib/Slic3r/Surface.pm index 998645a10..97a998b58 100644 --- a/lib/Slic3r/Surface.pm +++ b/lib/Slic3r/Surface.pm @@ -7,11 +7,6 @@ our @ISA = qw(Exporter); our @EXPORT_OK = qw(S_TYPE_TOP S_TYPE_BOTTOM S_TYPE_INTERNAL S_TYPE_INTERNALSOLID S_TYPE_INTERNALBRIDGE S_TYPE_INTERNALVOID); our %EXPORT_TAGS = (types => \@EXPORT_OK); -sub offset { - my $self = shift; - return [ map $self->clone(expolygon => $_), @{$self->expolygon->offset_ex(@_)} ]; -} - sub p { my $self = shift; return @{$self->polygons}; diff --git a/xs/src/ClipperUtils.cpp b/xs/src/ClipperUtils.cpp index 6dc3fb433..069822fc9 100644 --- a/xs/src/ClipperUtils.cpp +++ b/xs/src/ClipperUtils.cpp @@ -164,6 +164,24 @@ offset(const Slic3r::Polylines &polylines, Slic3r::Polygons &retval, const float delete output; } +void +offset(const Slic3r::Surface &surface, Slic3r::Surfaces &retval, const float delta, + double scale, ClipperLib::JoinType joinType, double miterLimit) +{ + // perform offset + Slic3r::ExPolygons expp; + offset_ex(surface.expolygon, expp, delta, scale, joinType, miterLimit); + + // clone the input surface for each expolygon we got + retval.clear(); + retval.reserve(expp.size()); + for (ExPolygons::iterator it = expp.begin(); it != expp.end(); ++it) { + Surface s = surface; // clone + s.expolygon = *it; + retval.push_back(s); + } +} + void offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float delta, double scale, ClipperLib::JoinType joinType, double miterLimit) diff --git a/xs/src/ClipperUtils.hpp b/xs/src/ClipperUtils.hpp index 918c5c1e1..6b090d08e 100644 --- a/xs/src/ClipperUtils.hpp +++ b/xs/src/ClipperUtils.hpp @@ -5,6 +5,7 @@ #include "clipper.hpp" #include "ExPolygon.hpp" #include "Polygon.hpp" +#include "Surface.hpp" // import these wherever we're included using ClipperLib::jtMiter; @@ -47,6 +48,9 @@ void offset(const Slic3r::Polylines &polylines, ClipperLib::Paths &retval, const void offset(const Slic3r::Polylines &polylines, Slic3r::Polygons &retval, const float delta, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3); +void offset(const Slic3r::Surface &surface, Slic3r::Surfaces &retval, const float delta, + double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtSquare, + double miterLimit = 3); void offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float delta, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter, diff --git a/xs/xsp/Surface.xsp b/xs/xsp/Surface.xsp index 868cc9833..b1128ac25 100644 --- a/xs/xsp/Surface.xsp +++ b/xs/xsp/Surface.xsp @@ -80,6 +80,17 @@ Surface::polygons() OUTPUT: RETVAL +Surfaces +Surface::offset(delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3) + const float delta + double scale + ClipperLib::JoinType joinType + double miterLimit + CODE: + offset(*THIS, RETVAL, delta, scale, joinType, miterLimit); + OUTPUT: + RETVAL + %} }; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index dbcdbe956..837c3eede 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -24,6 +24,7 @@ Lines T_ARRAYREF Polygons T_ARRAYREF Polylines T_ARRAYREF ExPolygons T_ARRAYREF +Surfaces T_ARRAYREF # we return these types whenever we want the items to be returned # by reference and marked ::Ref because they're contained in another diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 22659855a..559dba843 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -19,6 +19,7 @@ %typemap{Polygons}; %typemap{Polylines}; %typemap{ExPolygons}; +%typemap{Surfaces}; %typemap{Polygons*}; %typemap{TriangleMeshPtrs};