From 7534c1e6d9333940ba9917bdd6217338e4148a85 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 14 Jul 2013 15:03:45 +0200 Subject: [PATCH] Use Slic3r::Surface::Collection for Layer::Region->slices --- lib/Slic3r/Layer/Region.pm | 5 +++-- lib/Slic3r/Print.pm | 8 ++++++-- lib/Slic3r/Print/Object.pm | 12 ++++++++---- t/combineinfill.t | 4 ---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index fb6ba3450..5771316c4 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -25,7 +25,7 @@ has 'overhang_width' => (is => 'lazy'); # collection of surfaces generated by slicing the original geometry # divided by type top/bottom/internal -has 'slices' => (is => 'rw', default => sub { [] }); +has 'slices' => (is => 'rw', default => sub { Slic3r::Surface::Collection->new }); # collection of polygons or polylines representing thin walls contained # in the original geometry @@ -89,7 +89,8 @@ sub make_surfaces { my ($loops) = @_; return if !@$loops; - $self->slices([ _merge_loops($loops) ]); + $self->slices->clear; + $self->slices->append(_merge_loops($loops)); # detect thin walls by offsetting slices by half extrusion inwards if ($Slic3r::Config->thin_walls) { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index e443f595b..67ba0c00c 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -305,8 +305,12 @@ sub _simplify_slices { my ($distance) = @_; foreach my $layer (map @{$_->layers}, @{$self->objects}) { - @$_ = map $_->simplify($distance), @$_ - for $layer->slices, (map $_->slices, @{$layer->regions}); + $layer->slices([ map $_->simplify($distance), @{$layer->slices} ]); + foreach my $layerm (@{$layer->regions}) { + my @new = map $_->simplify($distance), @{$layerm->slices}; + $layerm->slices->clear; + $layerm->slices->append(@new); + } } } diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index c2b3cafd4..240c4d3dc 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -232,9 +232,12 @@ sub slice { [ map $_->expolygon->holes, @upper_surfaces, @lower_surfaces, ], ); - @{$layerm->slices} = map Slic3r::Surface->new - (expolygon => $_, surface_type => S_TYPE_INTERNAL), - @$diff; + $layerm->slices->clear; + $layerm->slices->append( + map Slic3r::Surface->new + (expolygon => $_, surface_type => S_TYPE_INTERNAL), + @$diff + ); } # update layer slices after repairing the single regions @@ -418,7 +421,8 @@ sub detect_surfaces_type { ); # save surfaces to layer - @{$layerm->slices} = (@bottom, @top, @internal); + $layerm->slices->clear; + $layerm->slices->append(@bottom, @top, @internal); Slic3r::debugf " layer %d has %d bottom, %d top and %d internal surfaces\n", $layerm->id, scalar(@bottom), scalar(@top), scalar(@internal); diff --git a/t/combineinfill.t b/t/combineinfill.t index 77eabcc02..d73c5d45d 100644 --- a/t/combineinfill.t +++ b/t/combineinfill.t @@ -42,10 +42,6 @@ use Slic3r::Test; $self->init_extruders; $_->slice for @{$self->objects}; $_->make_perimeters for @{$self->objects}; - foreach my $layer (map @{$_->layers}, @{$self->objects}) { - @$_ = map $_->simplify(&Slic3r::SCALED_RESOLUTION), @$_ - for $layer->slices, (map $_->slices, @{$layer->regions}); - } $_->detect_surfaces_type for @{$self->objects}; $_->prepare_fill_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects}; $_->process_external_surfaces for map @{$_->regions}, map @{$_->layers}, @{$self->objects};