diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 558f9fe21f..f3742d3c59 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -85,15 +85,7 @@ sub offset_ex { sub safety_offset { my $self = shift; - - # we're offsetting contour and holes separately - # because Clipper doesn't return polygons in the same order as - # we feed them to it - - return (ref $self)->new( - $self->contour->safety_offset, - @{ Slic3r::Geometry::Clipper::safety_offset([$self->holes]) }, - ); + return Slic3r::Geometry::Clipper::safety_offset_ex($self, @_); } sub noncollapsing_offset_ex { diff --git a/lib/Slic3r/Geometry/Clipper.pm b/lib/Slic3r/Geometry/Clipper.pm index 0196460fbc..68e3d7c0e7 100644 --- a/lib/Slic3r/Geometry/Clipper.pm +++ b/lib/Slic3r/Geometry/Clipper.pm @@ -4,7 +4,7 @@ use warnings; require Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(safety_offset offset offset_ex collapse_ex +our @EXPORT_OK = qw(safety_offset safety_offset_ex offset offset_ex collapse_ex diff_ex diff union_ex intersection_ex xor_ex PFT_EVENODD JT_MITER JT_ROUND JT_SQUARE is_counter_clockwise); @@ -17,6 +17,11 @@ sub safety_offset { return Math::Clipper::offset($polygons, $factor // (scale 1e-05), 100000, JT_MITER, 2); } +sub safety_offset_ex { + # offset polygons and then apply holes to the right contours + return @{ union_ex([ safety_offset(@_) ]) }; +} + sub offset { my ($polygons, $distance, $scale, $joinType, $miterLimit) = @_; $scale ||= 100000; diff --git a/lib/Slic3r/Polygon.pm b/lib/Slic3r/Polygon.pm index e9bfcf81ad..07f36d4f10 100644 --- a/lib/Slic3r/Polygon.pm +++ b/lib/Slic3r/Polygon.pm @@ -95,11 +95,6 @@ sub area { return Slic3r::Geometry::Clipper::area($self); } -sub safety_offset { - my $self = shift; - return (ref $self)->new(Slic3r::Geometry::Clipper::safety_offset([$self])->[0]); -} - sub offset { my $self = shift; return map Slic3r::Polygon->new($_), Slic3r::Geometry::Clipper::offset([$self], @_);