layers.t 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use Test::More tests => 4;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. }
  8. use List::Util qw(first);
  9. use Slic3r;
  10. use Slic3r::Test qw(_eq);
  11. my $config = Slic3r::Config->new_from_defaults;
  12. my $test = sub {
  13. my ($conf) = @_;
  14. $conf ||= $config;
  15. my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
  16. my @z = ();
  17. my @increments = ();
  18. Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
  19. my ($self, $cmd, $args, $info) = @_;
  20. if ($info->{dist_Z}) {
  21. push @z, 1*$args->{Z};
  22. push @increments, $info->{dist_Z};
  23. }
  24. });
  25. fail 'wrong first layer height'
  26. if $z[0] ne $config->get_value('first_layer_height') + $config->z_offset;
  27. fail 'wrong second layer height'
  28. if $z[1] ne $config->get_value('first_layer_height') + $config->get_value('layer_height') + $config->z_offset;
  29. fail 'wrong layer height'
  30. if first { !_eq($_, $config->layer_height) } @increments[1..$#increments];
  31. 1;
  32. };
  33. $config->set('layer_height', 0.3);
  34. $config->set('first_layer_height', 0.2);
  35. ok $test->(), "absolute first layer height";
  36. $config->set('first_layer_height', '60%');
  37. ok $test->(), "relative first layer height";
  38. $config->set('z_offset', 0.9);
  39. ok $test->(), "positive Z offset";
  40. $config->set('z_offset', -0.8);
  41. ok $test->(), "negative Z offset";
  42. __END__