From 4dd12b57a1cf308d500264550f9868b1b43a23a6 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 6 Sep 2013 19:14:06 +0200 Subject: [PATCH] Fixed wipe (includes regression test). #1421 --- lib/Slic3r/GCode.pm | 5 +++-- lib/Slic3r/Polyline.pm | 13 +++++++------ t/gcode.t | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index c7fa122d..4173907e 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -244,7 +244,7 @@ sub extrude_loop { # extrude along the path my $gcode = join '', map $self->extrude_path($_, $description, %params), @paths; - $self->wipe_path($extrusion_path->polyline) if $self->enable_wipe; + $self->wipe_path($extrusion_path->polyline->clone) if $self->enable_wipe; # make a little move inwards before leaving loop if ($loop->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->layer->object->config->perimeters > 1) { @@ -351,7 +351,7 @@ sub extrude_path { $local_F = 0; } if ($self->enable_wipe) { - $self->wipe_path($path->polyline); + $self->wipe_path($path->polyline->clone); $self->wipe_path->reverse; } } @@ -468,6 +468,7 @@ sub retract { # wipe my $wipe_path; if ($self->extruder->wipe && $self->wipe_path) { + my @points = @{$self->wipe_path}; $wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]) ->clip_start($self->extruder->scaled_wipe_distance); } diff --git a/lib/Slic3r/Polyline.pm b/lib/Slic3r/Polyline.pm index 5478c865..2f14806f 100644 --- a/lib/Slic3r/Polyline.pm +++ b/lib/Slic3r/Polyline.pm @@ -112,23 +112,24 @@ sub clip_start { my $self = shift; my ($distance) = @_; + my @points = @$self; my $points = [ $self->[0] ]; - for (my $i = 1; $distance > 0 && $i <= $#$self; $i++) { - my $point = $self->[$i]; - my $segment_length = $point->distance_to($self->[$i-1]); + for (my $i = 1; $distance > 0 && $i <= $#points; $i++) { + my $point = $points[$i]; + my $segment_length = $point->distance_to($points[$i-1]); if ($segment_length <= $distance) { $distance -= $segment_length; push @$points, $point; next; } - my $new_point = Slic3r::Geometry::point_along_segment($self->[$i-1], $point, $distance); - push @$points, Slic3r::Point->new($new_point); + my $new_point = Slic3r::Geometry::point_along_segment($points[$i-1], $point, $distance); + push @$points, Slic3r::Point->new(@$new_point); $distance = 0; } - return __PACKAGE__->new($points); + return __PACKAGE__->new(@$points); } # this method returns a collection of points picked on the polygon contour diff --git a/t/gcode.t b/t/gcode.t index 9504bdbd..495d90ea 100644 --- a/t/gcode.t +++ b/t/gcode.t @@ -1,4 +1,4 @@ -use Test::More tests => 1; +use Test::More tests => 2; use strict; use warnings; @@ -9,6 +9,7 @@ BEGIN { use Slic3r; use Slic3r::Geometry qw(scale); +use Slic3r::Test; { my $gcodegen = Slic3r::GCode->new( @@ -20,4 +21,18 @@ use Slic3r::Geometry qw(scale); is_deeply $gcodegen->last_pos->arrayref, [scale -10, scale -10], 'last_pos is shifted correctly'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('wipe', [1]); + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my $have_wipe = 0; + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + $have_wipe = 1 if $info->{retracting} && $info->{dist_XY} > 0; + }); + + ok $have_wipe, "wipe"; +} + __END__