Skip to content

Commit

Permalink
Get rid of max_print_dimension in filler objects
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Oct 30, 2012
1 parent 6c97e58 commit 20e73fa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
5 changes: 5 additions & 0 deletions lib/Slic3r/ExPolygon.pm
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions lib/Slic3r/Fill.pm
Expand Up @@ -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 = (
Expand All @@ -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};
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/Slic3r/Fill/Base.pm
Expand Up @@ -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] }
Expand All @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions t/fill.t
Expand Up @@ -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] ]),
Expand Down

0 comments on commit 20e73fa

Please sign in to comment.