diff --git a/lib/Slic3r/Geometry/Clipper.pm b/lib/Slic3r/Geometry/Clipper.pm index c88500c91..8cb0069fe 100644 --- a/lib/Slic3r/Geometry/Clipper.pm +++ b/lib/Slic3r/Geometry/Clipper.pm @@ -5,7 +5,8 @@ use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(explode_expolygon explode_expolygons safety_offset offset - diff_ex diff union_ex intersection_ex PFT_EVENODD JT_MITER JT_ROUND); + diff_ex diff union_ex intersection_ex PFT_EVENODD JT_MITER JT_ROUND + is_counter_clockwise); use Math::Clipper 1.02 ':all'; our $clipper = Math::Clipper->new; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 6c6511986..9fe78fe7d 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -3,7 +3,7 @@ use Moo; use Math::Clipper ':all'; use Slic3r::Geometry qw(scale collinear X Y A B PI); -use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex PFT_EVENODD); +use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex is_counter_clockwise); use XXX; # a sequential number of layer, starting at 0 @@ -98,7 +98,15 @@ sub make_surfaces { my ($loops) = @_; { - my $expolygons = union_ex($loops, PFT_EVENODD); + # merge contours + my $expolygons = union_ex([ grep is_counter_clockwise($_), @$loops ]); + + # subtract holes + $expolygons = union_ex([ + (map @$_, @$expolygons), + (grep !is_counter_clockwise($_), @$loops) + ]); + Slic3r::debugf " %d surface(s) having %d holes detected from %d polylines\n", scalar(@$expolygons), scalar(map $_->holes, @$expolygons), scalar(@$loops);