Fix last_pos shifting and add unit test

This commit is contained in:
Alessandro Ranellucci 2013-01-27 13:06:45 +01:00
parent 4c62c1b570
commit 50526dea5a
3 changed files with 24 additions and 2 deletions

View File

@ -58,6 +58,7 @@ t/collinear.t
t/custom_gcode.t t/custom_gcode.t
t/dynamic.t t/dynamic.t
t/fill.t t/fill.t
t/gcode.t
t/geometry.t t/geometry.t
t/layers.t t/layers.t
t/loops.t t/loops.t

View File

@ -57,9 +57,10 @@ sub set_shift {
my $self = shift; my $self = shift;
my @shift = @_; my @shift = @_;
# if shift increases (goes towards right), last_pos decreases because it goes towards left
$self->last_pos->translate( $self->last_pos->translate(
scale ($shift[X] - $self->shift_x), scale ($self->shift_x - $shift[X]),
scale ($shift[Y] - $self->shift_y), scale ($self->shift_x - $shift[Y]),
); );
$self->shift_x($shift[X]); $self->shift_x($shift[X]);

20
t/gcode.t Normal file
View File

@ -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__