05_surface.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 15;
  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::Ref', 'expolygon';
  25. is_deeply [ @{$surface->expolygon->pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
  26. is scalar(@{$surface->polygons}), 2, 'polygons roundtrip';
  27. is $surface->surface_type, Slic3r::Surface::S_TYPE_INTERNAL, 'surface_type';
  28. $surface->surface_type(Slic3r::Surface::S_TYPE_BOTTOM);
  29. is $surface->surface_type, Slic3r::Surface::S_TYPE_BOTTOM, 'modify surface_type';
  30. $surface->bridge_angle(30);
  31. is $surface->bridge_angle, 30, 'bridge_angle';
  32. $surface->extra_perimeters(2);
  33. is $surface->extra_perimeters, 2, 'extra_perimeters';
  34. {
  35. my $surface2 = $surface->clone;
  36. $surface2->expolygon->scale(2);
  37. isnt $surface2->expolygon->area, $expolygon->area, 'expolygon is returned by reference';
  38. }
  39. {
  40. my $collection = Slic3r::Surface::Collection->new;
  41. $collection->append($_) for $surface, $surface->clone;
  42. is scalar(@$collection), 2, 'collection has the right number of items';
  43. is_deeply $collection->[0]->expolygon->pp, [$square, $hole_in_square],
  44. 'collection returns a correct surface expolygon';
  45. $collection->clear;
  46. is scalar(@$collection), 0, 'clear collection';
  47. $collection->append($surface);
  48. is scalar(@$collection), 1, 'append to collection';
  49. my $item = $collection->[0];
  50. isa_ok $item, 'Slic3r::Surface::Ref';
  51. $item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL);
  52. is $item->surface_type, $collection->[0]->surface_type, 'collection returns items by reference';
  53. }
  54. {
  55. my $collection = Slic3r::Surface::Collection->new;
  56. $collection->append($_) for
  57. Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
  58. Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM),
  59. Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_TOP);
  60. is scalar(@{$collection->group}), 2, 'group() returns correct number of groups';
  61. }
  62. __END__