loops.t 2.0 KB

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