loops.t 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan tests => 4;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. use local::lib "$FindBin::Bin/../local-lib";
  9. }
  10. use Slic3r;
  11. use Slic3r::Geometry qw(Z epsilon scale);
  12. use Slic3r::Test;
  13. {
  14. # We want to check what happens when three concentric loops happen
  15. # to be at the same height, the two external ones being ccw and the other being
  16. # a hole, thus cw. So we create three cubes, centered around origin, the internal
  17. # one having reversed normals.
  18. my $mesh1 = Slic3r::Test::mesh('20mm_cube');
  19. # center around origin
  20. my $bb = $mesh1->bounding_box;
  21. $mesh1->translate(
  22. -($bb->x_min + $bb->size->x/2),
  23. -($bb->y_min + $bb->size->y/2), #//
  24. -($bb->z_min + $bb->size->z/2),
  25. );
  26. my $mesh2 = $mesh1->clone;
  27. $mesh2->scale(1.2);
  28. my $mesh3 = $mesh2->clone;
  29. $mesh3->scale(1.2);
  30. $mesh1->reverse_normals;
  31. ok $mesh1->volume < 0, 'reverse_normals';
  32. my $all_meshes = Slic3r::TriangleMesh->new;
  33. $all_meshes->merge($_) for $mesh1, $mesh2, $mesh3;
  34. my $loops = $all_meshes->slice_at(Z, 0);
  35. is scalar(@$loops), 1, 'one expolygon returned';
  36. is scalar(@{$loops->[0]->holes}), 1, 'expolygon has one hole';
  37. ok abs(-$loops->[0]->holes->[0]->area - scale($bb->size->x)*scale($bb->size->y)) < epsilon, #))
  38. 'hole has expected size';
  39. }
  40. __END__