From 97c65bac90191f5d286fd3f24c31c486e76d5c12 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 23 Nov 2013 22:43:30 +0100 Subject: [PATCH] Do perimeters one island at time instead of doing all holes before all contours --- lib/Slic3r/Layer/Region.pm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 312dce32a..b10b2dac5 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -242,7 +242,21 @@ sub make_perimeters { )}; my @loops = (); + foreach my $polynode (@nodes) { + # if this is an external contour find all holes belonging to this contour(s) + # and prepend them + if ($is_contour && $depth == 0) { + # $polynode is the outermost loop of an island + my @holes = (); + for (my $i = 0; $i <= $#$holes_pt; $i++) { + if ($polynode->{outer}->encloses_point($holes_pt->[$i]{outer}->first_point)) { + push @holes, splice @$holes_pt, $i, 1; # remove from candidates to reduce complexity + $i--; + } + } + push @loops, reverse map $traverse->([$_], 0), @holes; + } push @loops, $traverse->($polynode->{children}, $depth+1, $is_contour); # return ccw contours and cw holes @@ -272,10 +286,7 @@ sub make_perimeters { }; # order loops from inner to outer (in terms of object slices) - my @loops = ( - (reverse $traverse->($holes_pt, 0)), - $traverse->($contours_pt, 0, 1), - ); + my @loops = $traverse->($contours_pt, 0, 1); # if brim will be printed, reverse the order of perimeters so that # we continue inwards after having finished the brim