loops.t 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan skip_all => 'temporarily disabled';
  5. plan tests => 4;
  6. BEGIN {
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. }
  10. use Slic3r;
  11. use Slic3r::Test;
  12. {
  13. # We only need to slice at one height, so we'll build a non-manifold mesh
  14. # that still produces complete loops at that height. Triangular walls are
  15. # enough for this purpose.
  16. # Basically we want to check what happens when three concentric loops happen
  17. # to be at the same height, the two external ones being ccw and the other being
  18. # a hole, thus cw.
  19. my (@vertices, @facets) = ();
  20. Slic3r::Test::add_facet($_, \@vertices, \@facets) for
  21. # external surface below the slicing Z
  22. [ [0,0,0], [20,0,10], [0,0,10] ],
  23. [ [20,0,0], [20,20,10], [20,0,10] ],
  24. [ [20,20,0], [0,20,10], [20,20,10] ],
  25. [ [0,20,0], [0,0,10], [0,20,10] ],
  26. # external insetted surface above the slicing Z
  27. [ [2,2,10], [18,2,10], [2,2,20] ],
  28. [ [18,2,10], [18,18,10], [18,2,20] ],
  29. [ [18,18,10], [2,18,10], [18,18,20] ],
  30. [ [2,18,10], [2,2,10], [2,18,20] ],
  31. # insetted hole below the slicing Z
  32. [ [15,5,0], [5,5,10], [15,5,10] ],
  33. [ [15,15,0], [15,5,10], [15,15,10] ],
  34. [ [5,15,0], [15,15,10], [5,15,10] ],
  35. [ [5,5,0], [5,15,10], [5,5,10] ];
  36. my $mesh = Slic3r::TriangleMesh->new;
  37. $mesh->ReadFromPerl(\@vertices, \@facets);
  38. $mesh->analyze;
  39. my @lines = map $mesh->intersect_facet($_, 10), 0..$#facets;
  40. my $loops = Slic3r::TriangleMesh::make_loops(\@lines);
  41. is scalar(@$loops), 3, 'correct number of loops detected';
  42. is scalar(grep $_->is_counter_clockwise, @$loops), 2, 'correct number of ccw loops detected';
  43. my @surfaces = Slic3r::Layer::Region::_merge_loops($loops, 0);
  44. is scalar(@surfaces), 1, 'one surface detected';
  45. is scalar(@{$surfaces[0]->expolygon})-1, 1, 'surface has one hole';
  46. }
  47. __END__