flow.t 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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('over_bridge_flow_ratio', 1);
  42. $config->set('cooling', [ 0 ]); # to prevent speeds from being altered
  43. $config->set('first_layer_speed', '100%'); # to prevent speeds from being altered
  44. my $test = sub {
  45. my $print = Slic3r::Test::init_print('overhang', config => $config);
  46. my @E_per_mm = ();
  47. Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
  48. my ($self, $cmd, $args, $info) = @_;
  49. if ($info->{extruding} && $info->{dist_XY} > 0) {
  50. if (($args->{F} // $self->F) == $config->bridge_speed*60) {
  51. push @E_per_mm, $info->{dist_E} / $info->{dist_XY};
  52. }
  53. }
  54. });
  55. my $expected_mm3_per_mm = ($config->nozzle_diameter->[0]**2) * PI/4 * $config->bridge_flow_ratio;
  56. my $expected_E_per_mm = $expected_mm3_per_mm / ((($config->filament_diameter->[0]/2)**2)*PI);
  57. ok !(defined first { abs($_ - $expected_E_per_mm) > 0.01 } @E_per_mm),
  58. 'expected flow when using bridge_flow_ratio = ' . $config->bridge_flow_ratio;
  59. };
  60. $config->set('bridge_flow_ratio', 0.5);
  61. $test->();
  62. $config->set('bridge_flow_ratio', 2);
  63. $test->();
  64. $config->set('extrusion_width', 0.4);
  65. $config->set('bridge_flow_ratio', 1);
  66. $test->();
  67. $config->set('bridge_flow_ratio', 0.5);
  68. $test->();
  69. $config->set('bridge_flow_ratio', 2);
  70. $test->();
  71. }
  72. __END__