From c99b9d91db583d6ebe81bd751be411d44e273ee7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 11 Jan 2014 21:34:26 +0100 Subject: [PATCH] Fix bug in regression infill causing bad clipping at very low layer heights. Includes regression test. #1669 Conflicts: lib/Slic3r/Fill/Rectilinear.pm --- lib/Slic3r/Fill/Rectilinear.pm | 4 ++-- t/fill.t | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/Fill/Rectilinear.pm b/lib/Slic3r/Fill/Rectilinear.pm index 854d15fe..d8ba2870 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -60,12 +60,12 @@ sub fill_surface { $x += $line_spacing; } - # clip paths against a slightly offsetted expolygon, so that the first and last paths + # clip paths against a slightly larger expolygon, so that the first and last paths # are kept even if the expolygon has vertical sides # the minimum offset for preventing edge lines from being clipped is scaled_epsilon; # however we use a larger offset to support expolygons with slightly skewed sides and # not perfectly straight - my @polylines = @{intersection_pl(\@vertical_lines, $expolygon->offset($line_spacing*0.05))}; + my @polylines = @{intersection_pl(\@vertical_lines, $expolygon->offset(scale 0.02))}; # connect lines unless ($params{dont_connect} || !@polylines) { # prevent calling leftmost_point() on empty collections diff --git a/t/fill.t b/t/fill.t index 8e112484..717afced 100644 --- a/t/fill.t +++ b/t/fill.t @@ -2,15 +2,16 @@ use Test::More; use strict; use warnings; -plan tests => 34; +plan tests => 40; BEGIN { use FindBin; use lib "$FindBin::Bin/../lib"; } +use List::Util qw(first); use Slic3r; -use Slic3r::Geometry qw(scale X Y); +use Slic3r::Geometry qw(scale X Y convex_hull); use Slic3r::Geometry::Clipper qw(diff_ex); use Slic3r::Surface qw(:types); use Slic3r::Test; @@ -166,11 +167,34 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ } 'chained path'; } -for my $pattern (qw(hilbertcurve concentric)) { +for my $pattern (qw(rectilinear honeycomb hilbertcurve concentric)) { my $config = Slic3r::Config->new_from_defaults; $config->set('fill_pattern', $pattern); - my $print = Slic3r::Test::init_print('20mm_cube', config => $config); - ok Slic3r::Test::gcode($print), "successful $pattern infill generation"; + $config->set('perimeters', 1); + $config->set('skirts', 0); + $config->set('fill_density', 0.2); + $config->set('layer_height', 0.05); + $config->set('perimeter_extruder', 1); + $config->set('infill_extruder', 2); + my $print = Slic3r::Test::init_print('20mm_cube', config => $config, scale => 2); + ok my $gcode = Slic3r::Test::gcode($print), "successful $pattern infill generation"; + my $tool = undef; + my @perimeter_points = my @infill_points = (); + Slic3r::GCode::Reader->new->parse($gcode, sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd =~ /^T(\d+)/) { + $tool = $1; + } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) { + if ($tool == $config->perimeter_extruder-1) { + push @perimeter_points, Slic3r::Point->new_scale($args->{X}, $args->{Y}); + } elsif ($tool == $config->infill_extruder-1) { + push @infill_points, Slic3r::Point->new_scale($args->{X}, $args->{Y}); + } + } + }); + my $convex_hull = convex_hull(\@perimeter_points); + ok !(defined first { !$convex_hull->contains_point($_) } @infill_points), "infill does not exceed perimeters ($pattern)"; } {