From ddaeaa7591a196a967d24c93eb32e8e1d088addb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 27 Jan 2013 13:06:45 +0100 Subject: [PATCH] Fix last_pos shifting and add unit test --- MANIFEST | 1 + lib/Slic3r/GCode.pm | 1 + t/gcode.t | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 t/gcode.t diff --git a/MANIFEST b/MANIFEST index 6deab070bb..e48376de87 100644 --- a/MANIFEST +++ b/MANIFEST @@ -59,6 +59,7 @@ t/collinear.t t/custom_gcode.t t/dynamic.t t/fill.t +t/gcode.t t/geometry.t t/layers.t t/loops.t diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index d503db9919..3633c3c5bb 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -62,6 +62,7 @@ sub set_shift { my $self = shift; my @shift = @_; + # if shift increases (goes towards right), last_pos decreases because it goes towards left $self->last_pos->translate( scale ($self->shift_x - $shift[X]), scale ($self->shift_y - $shift[Y]), diff --git a/t/gcode.t b/t/gcode.t new file mode 100644 index 0000000000..c41307d4fc --- /dev/null +++ b/t/gcode.t @@ -0,0 +1,20 @@ +use Test::More tests => 1; +use strict; +use warnings; + +BEGIN { + use FindBin; + use lib "$FindBin::Bin/../lib"; +} + +use Slic3r; +use Slic3r::Geometry qw(scale); + +{ + local $Slic3r::Config = Slic3r::Config->new_from_defaults; + my $gcodegen = Slic3r::GCode->new(layer_count => 1); + $gcodegen->set_shift(10, 10); + is_deeply $gcodegen->last_pos, [scale -10, scale -10], 'last_pos is shifted correctly'; +} + +__END__