12_extrusionpathcollection.t 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 18;
  6. my $points = [
  7. [100, 100],
  8. [200, 100],
  9. [200, 200],
  10. ];
  11. my $path = Slic3r::ExtrusionPath->new(
  12. polyline => Slic3r::Polyline->new(@$points),
  13. role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
  14. mm3_per_mm => 1,
  15. );
  16. my $loop = Slic3r::ExtrusionLoop->new_from_paths(
  17. Slic3r::ExtrusionPath->new(
  18. polyline => Slic3r::Polygon->new(@$points)->split_at_first_point,
  19. role => Slic3r::ExtrusionPath::EXTR_ROLE_FILL,
  20. mm3_per_mm => 1,
  21. ),
  22. );
  23. my $collection = Slic3r::ExtrusionPath::Collection->new(
  24. $path,
  25. );
  26. isa_ok $collection, 'Slic3r::ExtrusionPath::Collection', 'collection object with items in constructor';
  27. ok !$collection->no_sort, 'no_sort is false by default';
  28. $collection->append($collection);
  29. is scalar(@$collection), 2, 'append ExtrusionPath::Collection';
  30. $collection->append($path);
  31. is scalar(@$collection), 3, 'append ExtrusionPath';
  32. $collection->append($loop);
  33. is scalar(@$collection), 4, 'append ExtrusionLoop';
  34. isa_ok $collection->[1], 'Slic3r::ExtrusionPath::Collection::Ref', 'correct object returned for collection';
  35. isa_ok $collection->[2], 'Slic3r::ExtrusionPath::Ref', 'correct object returned for path';
  36. isa_ok $collection->[3], 'Slic3r::ExtrusionLoop::Ref', 'correct object returned for loop';
  37. is ref($collection->[2]->clone), 'Slic3r::ExtrusionPath', 'correct object returned for cloned path';
  38. is ref($collection->[3]->clone), 'Slic3r::ExtrusionLoop', 'correct object returned for cloned loop';
  39. is scalar(@{$collection->[1]}), 1, 'appended collection was duplicated';
  40. {
  41. my $collection_loop = $collection->[3];
  42. $collection_loop->polygon->scale(2);
  43. is_deeply $collection->[3]->polygon->pp, $collection_loop->polygon->pp, 'items are returned by reference';
  44. }
  45. {
  46. my $collection = Slic3r::ExtrusionPath::Collection->new(
  47. map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
  48. Slic3r::Polyline->new([0,15], [0,18], [0,20]),
  49. Slic3r::Polyline->new([0,10], [0,8], [0,5]),
  50. );
  51. is_deeply
  52. [ map $_->y, map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(0,30), 0)} ],
  53. [20, 18, 15, 10, 8, 5],
  54. 'chained_path_from';
  55. is_deeply
  56. [ map $_->y, map @{$_->polyline}, @{$collection->chained_path(0)} ],
  57. [15, 18, 20, 10, 8, 5],
  58. 'chained_path';
  59. }
  60. {
  61. my $collection = Slic3r::ExtrusionPath::Collection->new(
  62. map Slic3r::ExtrusionPath->new(polyline => $_, role => 0, mm3_per_mm => 1),
  63. Slic3r::Polyline->new([15,0], [10,0], [4,0]),
  64. Slic3r::Polyline->new([10,5], [15,5], [20,5]),
  65. );
  66. is_deeply
  67. [ map $_->x, map @{$_->polyline}, @{$collection->chained_path_from(Slic3r::Point->new(30,0), 0)} ],
  68. [reverse 4, 10, 15, 10, 15, 20],
  69. 'chained_path_from';
  70. $collection->no_sort(1);
  71. my @foo = @{$collection->chained_path(0)};
  72. pass 'chained_path with no_sort';
  73. }
  74. {
  75. my $coll2 = $collection->clone;
  76. ok !$coll2->no_sort, 'expected no_sort value';
  77. $coll2->no_sort(1);
  78. ok $coll2->clone->no_sort, 'no_sort is kept after clone';
  79. }
  80. __END__