From 159a009f96ec2bcdbd5af6f4f71c1b50f3a3e10f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 15 Jul 2013 15:26:56 +0200 Subject: [PATCH] Fix tests here and there --- lib/Slic3r/ExtrusionPath.pm | 2 +- lib/Slic3r/Layer/Region.pm | 2 +- lib/Slic3r/Polyline.pm | 2 +- lib/Slic3r/Print.pm | 4 ++-- lib/Slic3r/Print/Object.pm | 18 ++++++++++-------- t/shells.t | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/Slic3r/ExtrusionPath.pm b/lib/Slic3r/ExtrusionPath.pm index 2234aa9e..620a1787 100644 --- a/lib/Slic3r/ExtrusionPath.pm +++ b/lib/Slic3r/ExtrusionPath.pm @@ -40,7 +40,7 @@ sub clip_with_expolygon { my ($expolygon) = @_; return map $self->clone(polyline => $_), - $self->polyline->clip_with_expolygon($expolygon); + $self->as_polyline->clip_with_expolygon($expolygon); } sub intersect_expolygons { diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm index 60247553..daef53ba 100644 --- a/lib/Slic3r/Layer/Region.pm +++ b/lib/Slic3r/Layer/Region.pm @@ -450,7 +450,7 @@ sub process_external_surfaces { # subtract the new top surfaces from the other non-top surfaces and re-add them my @other = grep $_->surface_type != S_TYPE_TOP && $_->surface_type != S_TYPE_BOTTOM, @{$self->fill_surfaces}; foreach my $group (Slic3r::Surface->group(@other)) { - push @new_surfaces, map $group->[0]->clone(expolygon => $_), @{diff_ex( + push @new_surfaces, map $_->clone, map $group->[0]->clone(expolygon => $_), @{diff_ex( [ map $_->p, @$group ], [ map $_->p, @new_surfaces ], )}; diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 39a93637..70516376 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -113,7 +113,7 @@ sub clip_with_expolygon { my $self = shift; my ($expolygon) = @_; - my $result = Boost::Geometry::Utils::polygon_multi_linestring_intersection($expolygon->arrayref, [$self]); + my $result = Boost::Geometry::Utils::polygon_multi_linestring_intersection($expolygon->arrayref, [$self->arrayref]); bless $_, 'Slic3r::Polyline' for @$result; bless $_, 'Slic3r::Point' for map @$_, @$result; return @$result; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index b067b6ed..3088b67e 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -305,11 +305,11 @@ sub _simplify_slices { my ($distance) = @_; foreach my $layer (map @{$_->layers}, @{$self->objects}) { - my @new = map $_->simplify($distance), @{$layer->slices}; + my @new = map $_->simplify($distance), map $_->clone, @{$layer->slices}; $layer->slices->clear; $layer->slices->append(@new); foreach my $layerm (@{$layer->regions}) { - my @new = map $_->simplify($distance), @{$layerm->slices}; + my @new = map $_->simplify($distance), map $_->clone, @{$layerm->slices}; $layerm->slices->clear; $layerm->slices->append(@new); } diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 8e56673c..9ed110f4 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -383,7 +383,8 @@ sub detect_surfaces_type { ); } else { # if no upper layer, all surfaces of this one are solid - @top = @{$layerm->slices}; + # we clone surfaces because we're going to clear the slices collection + @top = map $_->clone, @{$layerm->slices}; $_->surface_type(S_TYPE_TOP) for @top; } @@ -399,7 +400,8 @@ sub detect_surfaces_type { ); } else { # if no lower layer, all surfaces of this one are solid - @bottom = @{$layerm->slices}; + # we clone surfaces because we're going to clear the slices collection + @bottom = map $_->clone, @{$layerm->slices}; $_->surface_type(S_TYPE_BOTTOM) for @bottom; } @@ -431,7 +433,7 @@ sub detect_surfaces_type { # clip surfaces to the fill boundaries foreach my $layer (@{$self->layers}) { my $layerm = $layer->regions->[$region_id]; - my $fill_boundaries = [ map $_->p, @{$layerm->fill_surfaces} ]; + my $fill_boundaries = [ map $_->clone->p, @{$layerm->fill_surfaces} ]; $layerm->fill_surfaces->clear; foreach my $surface (@{$layerm->slices}) { my $intersection = intersection_ex( @@ -471,7 +473,7 @@ sub clip_fill_surfaces { )}; my @new_surfaces = ( @new_internal, - (grep $_->surface_type != S_TYPE_INTERNAL, @{$layerm->fill_surfaces}), + (map $_->clone, grep $_->surface_type != S_TYPE_INTERNAL, @{$layerm->fill_surfaces}), ); $layerm->fill_surfaces->clear; $layerm->fill_surfaces->append(@new_surfaces); @@ -516,7 +518,7 @@ sub bridge_over_infill { # build the new collection of fill_surfaces { - my @new_surfaces = grep $_->surface_type != S_TYPE_INTERNALSOLID, @{$layerm->fill_surfaces}; + my @new_surfaces = map $_->clone, grep $_->surface_type != S_TYPE_INTERNALSOLID, @{$layerm->fill_surfaces}; push @new_surfaces, map Slic3r::Surface->new( expolygon => $_, surface_type => S_TYPE_INTERNALBRIDGE, @@ -756,7 +758,7 @@ sub combine_infill { foreach my $layerm (@layerms) { my @this_type = grep $_->surface_type == $type, @{$layerm->fill_surfaces}; - my @other_types = grep $_->surface_type != $type, @{$layerm->fill_surfaces}; + my @other_types = map $_->clone, grep $_->surface_type != $type, @{$layerm->fill_surfaces}; my @new_this_type = map Slic3r::Surface->new(expolygon => $_, surface_type => $type), @{diff_ex( @@ -919,7 +921,7 @@ sub generate_support_material { my ($expolygon, $density) = @_; my @paths = $filler->fill_surface( - Slic3r::Surface->new(expolygon => $expolygon), + Slic3r::Surface->new(expolygon => $expolygon, surface_type => S_TYPE_INTERNAL), density => $density, flow_spacing => $flow->spacing, ); @@ -1003,7 +1005,7 @@ sub generate_support_material { $filler->angle($Slic3r::Config->support_material_angle + 90); foreach my $expolygon (@$islands) { my @paths = $filler->fill_surface( - Slic3r::Surface->new(expolygon => $expolygon), + Slic3r::Surface->new(expolygon => $expolygon, surface_type => S_TYPE_INTERNAL), density => 0.5, flow_spacing => $self->print->first_layer_support_material_flow->spacing, ); diff --git a/t/shells.t b/t/shells.t index 7abca9b1..c2486725 100644 --- a/t/shells.t +++ b/t/shells.t @@ -42,11 +42,11 @@ use Slic3r::Test; fail "insufficient number of bottom solid layers" unless !defined(first { !$_ } @shells[0..$config->bottom_solid_layers-1]); fail "excessive number of bottom solid layers" - unless scalar(grep $_, @shells[0 .. $#shells/2]) != $config->bottom_solid_layers; + unless scalar(grep $_, @shells[0 .. $#shells/2]) == $config->bottom_solid_layers; fail "insufficient number of top solid layers" unless !defined(first { !$_ } @shells[-$config->top_solid_layers..-1]); fail "excessive number of top solid layers" - unless scalar(grep $_, @shells[($#shells/2)..$#shells]) != $config->top_solid_layers; + unless scalar(grep $_, @shells[($#shells/2)..$#shells]) == $config->top_solid_layers; 1; };