Ported Surface->offset() to XS

This commit is contained in:
Alessandro Ranellucci 2013-11-23 18:29:25 +01:00
parent a331f4d27a
commit 46e3b3180e
6 changed files with 35 additions and 5 deletions

View file

@ -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_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); our %EXPORT_TAGS = (types => \@EXPORT_OK);
sub offset {
my $self = shift;
return [ map $self->clone(expolygon => $_), @{$self->expolygon->offset_ex(@_)} ];
}
sub p { sub p {
my $self = shift; my $self = shift;
return @{$self->polygons}; return @{$self->polygons};

View file

@ -164,6 +164,24 @@ offset(const Slic3r::Polylines &polylines, Slic3r::Polygons &retval, const float
delete output; 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 void
offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float delta, offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float delta,
double scale, ClipperLib::JoinType joinType, double miterLimit) double scale, ClipperLib::JoinType joinType, double miterLimit)

View file

@ -5,6 +5,7 @@
#include "clipper.hpp" #include "clipper.hpp"
#include "ExPolygon.hpp" #include "ExPolygon.hpp"
#include "Polygon.hpp" #include "Polygon.hpp"
#include "Surface.hpp"
// import these wherever we're included // import these wherever we're included
using ClipperLib::jtMiter; 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, void offset(const Slic3r::Polylines &polylines, Slic3r::Polygons &retval, const float delta,
double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtSquare,
double miterLimit = 3); 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, void offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const float delta,
double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double scale = 100000, ClipperLib::JoinType joinType = ClipperLib::jtMiter,

View file

@ -80,6 +80,17 @@ Surface::polygons()
OUTPUT: OUTPUT:
RETVAL 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
%} %}
}; };

View file

@ -24,6 +24,7 @@ Lines T_ARRAYREF
Polygons T_ARRAYREF Polygons T_ARRAYREF
Polylines T_ARRAYREF Polylines T_ARRAYREF
ExPolygons T_ARRAYREF ExPolygons T_ARRAYREF
Surfaces T_ARRAYREF
# we return these types whenever we want the items to be returned # we return these types whenever we want the items to be returned
# by reference and marked ::Ref because they're contained in another # by reference and marked ::Ref because they're contained in another

View file

@ -19,6 +19,7 @@
%typemap{Polygons}; %typemap{Polygons};
%typemap{Polylines}; %typemap{Polylines};
%typemap{ExPolygons}; %typemap{ExPolygons};
%typemap{Surfaces};
%typemap{Polygons*}; %typemap{Polygons*};
%typemap{TriangleMeshPtrs}; %typemap{TriangleMeshPtrs};