Do perimeters one island at time instead of doing all holes before all contours

This commit is contained in:
Alessandro Ranellucci 2013-11-23 22:43:30 +01:00
parent 3a5e4931cc
commit fc4483d09c

View File

@ -241,7 +241,21 @@ sub make_perimeters {
my @nodes = @$polynodes[@{chained_path(\@ordering_points)}];
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
@ -271,10 +285,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