diff --git a/lib/Slic3r/ExPolygon.pm b/lib/Slic3r/ExPolygon.pm index 6a3e946c1..9a82ba0e7 100644 --- a/lib/Slic3r/ExPolygon.pm +++ b/lib/Slic3r/ExPolygon.pm @@ -144,6 +144,11 @@ sub bounding_box_polygon { ]); } +sub bounding_box_center { + my $self = shift; + return Slic3r::Geometry::bounding_box_center($self->contour); +} + sub clip_line { my $self = shift; my ($line) = @_; # line must be a Slic3r::Line object diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 0449a68b2..b44d9dcf0 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -18,7 +18,6 @@ use Slic3r::Surface ':types'; has 'print' => (is => 'ro', required => 1); -has 'max_print_dimension' => (is => 'rw'); has 'fillers' => (is => 'rw', default => sub { {} }); our %FillTypes = ( @@ -32,26 +31,13 @@ our %FillTypes = ( honeycomb => 'Slic3r::Fill::Honeycomb', ); -sub BUILD { - my $self = shift; - - my $print_size = $self->print->size; - my $max_print_dimension = ($print_size->[X] > $print_size->[Y] ? $print_size->[X] : $print_size->[Y]) * sqrt(2); - $self->max_print_dimension($max_print_dimension); - - $self->filler($_) for ('rectilinear', $Slic3r::Config->fill_pattern, $Slic3r::Config->solid_fill_pattern); -} - sub filler { my $self = shift; my ($filler) = @_; if (!$self->fillers->{$filler}) { - my $f = $FillTypes{$filler}->new( - max_print_dimension => $self->max_print_dimension - ); + my $f = $self->fillers->{$filler} = $FillTypes{$filler}->new; $f->bounding_box([ $self->print->bounding_box ]) if $filler->can('bounding_box'); - $self->fillers->{$filler} = $f; } return $self->fillers->{$filler}; } @@ -155,7 +141,7 @@ sub make_fill { next SURFACE unless $density > 0; } - my @paths = $self->fillers->{$filler}->fill_surface( + my @paths = $self->filler($filler)->fill_surface( $surface, density => $density, flow_spacing => $flow_spacing, diff --git a/lib/Slic3r/Fill/Base.pm b/lib/Slic3r/Fill/Base.pm index aa68e2989..93af733d4 100644 --- a/lib/Slic3r/Fill/Base.pm +++ b/lib/Slic3r/Fill/Base.pm @@ -3,9 +3,7 @@ use Moo; use Slic3r::Geometry qw(PI); -has 'print' => (is => 'rw'); has 'layer_id' => (is => 'rw'); -has 'max_print_dimension' => (is => 'rw'); has 'angle' => (is => 'rw', default => sub { $Slic3r::Config->fill_angle }); sub angles () { [0, PI/2] } @@ -17,7 +15,7 @@ sub infill_direction { # set infill angle my (@rotate, @shift); $rotate[0] = Slic3r::Geometry::deg2rad($self->angle); - $rotate[1] = [ $self->max_print_dimension * sqrt(2) / 2, $self->max_print_dimension * sqrt(2) / 2 ]; + $rotate[1] = $surface->expolygon->bounding_box_center; @shift = @{$rotate[1]}; if (defined $self->layer_id) { diff --git a/t/fill.t b/t/fill.t index 27b9da41d..28d3b9cb7 100644 --- a/t/fill.t +++ b/t/fill.t @@ -29,10 +29,7 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } } { - my $filler = Slic3r::Fill::Rectilinear->new( - print => Slic3r::Print->new, - max_print_dimension => scale 100, - ); + my $filler = Slic3r::Fill::Rectilinear->new; my $surface = Slic3r::Surface->new( surface_type => S_TYPE_TOP, expolygon => Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,50], [0,50] ]),