flow.t 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. use Test::More tests => 6;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. use local::lib "$FindBin::Bin/../local-lib";
  8. }
  9. use List::Util qw(first sum);
  10. use Slic3r;
  11. use Slic3r::Geometry qw(scale PI);
  12. use Slic3r::Test;
  13. {
  14. my $config = Slic3r::Config->new_from_defaults;
  15. $config->set('skirts', 1);
  16. $config->set('brim_width', 2);
  17. $config->set('perimeters', 3);
  18. $config->set('fill_density', 0.4);
  19. $config->set('bottom_solid_layers', 1);
  20. $config->set('first_layer_extrusion_width', 2);
  21. $config->set('first_layer_height', '100%');
  22. my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
  23. my @E_per_mm = ();
  24. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  25. my ($self, $cmd, $args, $info) = @_;
  26. if ($self->Z == $config->layer_height) { # only consider first layer
  27. if ($info->{extruding} && $info->{dist_XY} > 0) {
  28. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  29. }
  30. }
  31. });
  32. my $E_per_mm_avg = sum(@E_per_mm) / @E_per_mm;
  33. # allow some tolerance because solid rectilinear infill might be adjusted/stretched
  34. ok !(defined first { abs($_ - $E_per_mm_avg) > 0.015 } @E_per_mm),
  35. 'first_layer_extrusion_width applies to everything on first layer';
  36. }
  37. {
  38. my $config = Slic3r::Config->new_from_defaults;
  39. $config->set('bridge_speed', 99);
  40. $config->set('bridge_flow_ratio', 1);
  41. $config->set('cooling', [ 0 ]); # to prevent speeds from being altered
  42. $config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
  43. my $test = sub {
  44. my $print = Slic3r::Test::init_print('overhang', config => $config);
  45. my @E_per_mm = ();
  46. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  47. my ($self, $cmd, $args, $info) = @_;
  48. if ($info->{extruding} && $info->{dist_XY} > 0) {
  49. if (($args->{F} // $self->F) == $config->bridge_speed*60) {
  50. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  51. }
  52. }
  53. });
  54. my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio;
  55. my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI);
  56. ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm),
  57. 'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio;
  58. };
  59. $config->set('bridge_flow_ratio', 0.5);
  60. $test->();
  61. $config->set('bridge_flow_ratio', 2);
  62. $test->();
  63. $config->set('extrusion_width', 0.4);
  64. $config->set('bridge_flow_ratio', 1);
  65. $test->();
  66. $config->set('bridge_flow_ratio', 0.5);
  67. $test->();
  68. $config->set('bridge_flow_ratio', 2);
  69. $test->();
  70. }
  71. __END__