diff --git a/lib/Slic3r/Fill/Base.pm b/lib/Slic3r/Fill/Base.pm index 0ca81c3f7f..5dc47d8faa 100644 --- a/lib/Slic3r/Fill/Base.pm +++ b/lib/Slic3r/Fill/Base.pm @@ -58,4 +58,15 @@ sub rotate_points_back { } } +sub adjust_solid_spacing { + my $self = shift; + my %params = @_; + + my $number_of_lines = int($params{width} / $params{distance}) + 1; + return $params{distance} if $number_of_lines <= 1; + + my $extra_space = $params{width} % $params{distance}; + return $params{distance} + $extra_space / ($number_of_lines - 1); +} + 1; diff --git a/lib/Slic3r/Fill/Concentric.pm b/lib/Slic3r/Fill/Concentric.pm index f62f9d24b2..549e333242 100644 --- a/lib/Slic3r/Fill/Concentric.pm +++ b/lib/Slic3r/Fill/Concentric.pm @@ -3,7 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; -use Slic3r::Geometry qw(scale X1 Y1 X2 Y2); +use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2); use XXX; sub fill_surface { @@ -12,21 +12,25 @@ sub fill_surface { # no rotation is supported for this infill pattern - my $bounding_box = [ $surface->expolygon->bounding_box ]; + my $expolygon = $surface->expolygon; + my $bounding_box = [ $expolygon->bounding_box ]; - my $scaled_flow_spacing = scale $params{flow_spacing}; - my $distance = $scaled_flow_spacing / $params{density}; - # TODO: adjust distance and flow width for solid surfaces - # using the same logic as Rectilinear infill - # (factor it out to parent class) + my $min_spacing = scale $params{flow_spacing}; + my $distance = $min_spacing / $params{density}; + + $distance = $self->adjust_solid_spacing( + width => $bounding_box->[X2] - $bounding_box->[X1], + distance => $distance, + ) if $params{density} == 1; + my $flow_spacing = unscale $distance; my @contour_loops = (); my @hole_loops = (); - my @last_offsets = ($surface->expolygon->offset_ex($distance)); + my @last_offsets = ($expolygon->offset_ex($distance)); while (@last_offsets) { my @new_offsets = (); - foreach my $expolygon (@last_offsets) { - my @offsets = $expolygon->offset_ex(-$distance); + foreach my $last_expolygon (@last_offsets) { + my @offsets = $last_expolygon->offset_ex(-$distance); foreach my $offset (@offsets) { push @new_offsets, $offset; push @contour_loops, $offset->contour; @@ -57,7 +61,7 @@ sub fill_surface { push @paths, $path->p if @{$path->points}; } - return {}, @paths; + return { flow_spacing => $flow_spacing }, @paths; } 1; diff --git a/lib/Slic3r/Fill/Rectilinear.pm b/lib/Slic3r/Fill/Rectilinear.pm index 3c38b0df05..5f4441933b 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -23,19 +23,18 @@ sub fill_surface { my $distance_between_lines = $min_spacing / $params{density}; my $line_oscillation = $distance_between_lines - $min_spacing; - my $number_of_lines = int(($bounding_box->[X2] - $bounding_box->[X1]) / $distance_between_lines) + 1; - my $flow_spacing = undef; - if ($params{density} == 1) { - my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines; - $distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1; - $flow_spacing = unscale $distance_between_lines; - } + $distance_between_lines = $self->adjust_solid_spacing( + width => $bounding_box->[X2] - $bounding_box->[X1], + distance => $distance_between_lines, + ) if $params{density} == 1; + my $flow_spacing = unscale $distance_between_lines; + my $overlap_distance = $Slic3r::nozzle_diameter * 0.20; my @paths = (); my $x = $bounding_box->[X1]; my $is_line_pattern = $self->isa('Slic3r::Fill::Line'); - for (my $i = 0; $i < $number_of_lines; $i++) { + for (my $i = 0; $x <= $bounding_box->[X2]; $i++) { my $vertical_line = [ [$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]] ]; if ($is_line_pattern && $i % 2) { $vertical_line->[A][X] -= $line_oscillation;