dynamic.t 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan skip_all => 'variable-width paths are currently disabled';
  5. plan tests => 20;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. use local::lib "$FindBin::Bin/../local-lib";
  10. }
  11. use List::Util qw(first);
  12. use Slic3r;
  13. use Slic3r::Geometry qw(X Y scale epsilon);
  14. use Slic3r::Surface ':types';
  15. sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
  16. {
  17. my $square = Slic3r::ExPolygon->new([
  18. scale_points [0,0], [10,0], [10,10], [0,10],
  19. ]);
  20. my @offsets = @{$square->noncollapsing_offset_ex(- scale 5)};
  21. is scalar @offsets, 1, 'non-collapsing offset';
  22. }
  23. {
  24. local $Slic3r::Config = Slic3r::Config->new(
  25. perimeters => 3,
  26. );
  27. my $w = 0.7;
  28. my $perimeter_flow = Slic3r::Flow->new(
  29. nozzle_diameter => 0.5,
  30. layer_height => 0.4,
  31. width => $w,
  32. );
  33. my $print = Slic3r::Print->new;
  34. my $region = Slic3r::Print::Region->new(
  35. print => $print,
  36. flows => { perimeter => $perimeter_flow },
  37. );
  38. push @{$print->regions}, $region;
  39. my $object = Slic3r::Print::Object->new(
  40. print => $print,
  41. size => [1,1],
  42. );
  43. my $make_layer = sub {
  44. my ($width) = @_;
  45. my $layer = Slic3r::Layer->new(
  46. object => $object,
  47. id => 1,
  48. slices => [
  49. Slic3r::Surface->new(
  50. surface_type => S_TYPE_INTERNAL,
  51. expolygon => Slic3r::ExPolygon->new([ scale_points [0,0], [50,0], [50,$width], [0,$width] ]),
  52. ),
  53. ],
  54. thin_walls => [],
  55. );
  56. my $layerm = $layer->region(0);
  57. $layer->make_perimeters;
  58. return $layerm;
  59. };
  60. my %widths = (
  61. 1 * $w => { perimeters => 1, gaps => 0 },
  62. 1.3 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.2 * $w)->spacing },
  63. 1.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 0.5 * $w)->spacing },
  64. 2 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
  65. 2.5 * $w => { perimeters => 1, gaps => 1, gap_flow_spacing => $perimeter_flow->clone(width => 1.5 * $w)->spacing },
  66. 3 * $w => { perimeters => 2, gaps => 0 },
  67. 4 * $w => { perimeters => 2, gaps => 1, gap_flow_spacing => $perimeter_flow->spacing },
  68. );
  69. foreach my $width (sort keys %widths) {
  70. my $layerm = $make_layer->($width);
  71. is scalar @{$layerm->perimeters}, $widths{$width}{perimeters}, 'right number of perimeters';
  72. is scalar @{$layerm->thin_fills} ? 1 : 0, $widths{$width}{gaps},
  73. ($widths{$width}{gaps} ? 'gaps were filled' : 'no gaps detected'); # TODO: we should check the exact number of gaps, but we need a better medial axis algorithm
  74. my @gaps = map $_, @{$layerm->thin_fills};
  75. if (@gaps) {
  76. ok +(!first { abs($_->flow_spacing - $widths{$width}{gap_flow_spacing}) > epsilon } @gaps),
  77. 'flow spacing was dynamically adjusted';
  78. }
  79. }
  80. }
  81. __END__