05_surface.t 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 11;
  6. my $square = [ # ccw
  7. [100, 100],
  8. [200, 100],
  9. [200, 200],
  10. [100, 200],
  11. ];
  12. my $hole_in_square = [ # cw
  13. [140, 140],
  14. [140, 160],
  15. [160, 160],
  16. [160, 140],
  17. ];
  18. my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square);
  19. my $surface = Slic3r::Surface->new(
  20. expolygon => $expolygon,
  21. surface_type => Slic3r::Surface::S_TYPE_INTERNAL,
  22. );
  23. $surface = $surface->clone;
  24. isa_ok $surface->expolygon, 'Slic3r::ExPolygon', 'expolygon';
  25. is_deeply [ @{$surface->expolygon->pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
  26. is $surface->surface_type, Slic3r::Surface::S_TYPE_INTERNAL, 'surface_type';
  27. $surface->surface_type(Slic3r::Surface::S_TYPE_BOTTOM);
  28. is $surface->surface_type, Slic3r::Surface::S_TYPE_BOTTOM, 'modify surface_type';
  29. $surface->bridge_angle(30);
  30. is $surface->bridge_angle, 30, 'bridge_angle';
  31. $surface->extra_perimeters(2);
  32. is $surface->extra_perimeters, 2, 'extra_perimeters';
  33. {
  34. my $collection = Slic3r::Surface::Collection->new($surface, $surface->clone);
  35. is scalar(@$collection), 2, 'collection has the right number of items';
  36. is_deeply $collection->[0]->expolygon->pp, [$square, $hole_in_square],
  37. 'collection returns a correct surface expolygon';
  38. $collection->clear;
  39. is scalar(@$collection), 0, 'clear collection';
  40. $collection->append($surface);
  41. is scalar(@$collection), 1, 'append to collection';
  42. my $item = $collection->[0];
  43. $item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL);
  44. is $item->surface_type, $collection->[0]->surface_type, 'changing item affects actual item';
  45. }
  46. __END__