14_geometry.t 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 9;
  6. use constant PI => 4 * atan2(1, 1);
  7. {
  8. my @points = (
  9. Slic3r::Point->new(100,100),
  10. Slic3r::Point->new(100,200),
  11. Slic3r::Point->new(200,200),
  12. Slic3r::Point->new(200,100),
  13. Slic3r::Point->new(150,150),
  14. );
  15. my $hull = Slic3r::Geometry::convex_hull(\@points);
  16. isa_ok $hull, 'Slic3r::Polygon', 'convex_hull returns a Polygon';
  17. is scalar(@$hull), 4, 'convex_hull returns the correct number of points';
  18. }
  19. # directions_parallel() and directions_parallel_within() are tested
  20. # also with Slic3r::Line::parallel_to() tests in 10_line.t
  21. {
  22. ok Slic3r::Geometry::directions_parallel_within(0, 0, 0), 'directions_parallel_within';
  23. ok Slic3r::Geometry::directions_parallel_within(0, PI, 0), 'directions_parallel_within';
  24. ok Slic3r::Geometry::directions_parallel_within(0, 0, PI/180), 'directions_parallel_within';
  25. ok Slic3r::Geometry::directions_parallel_within(0, PI, PI/180), 'directions_parallel_within';
  26. ok !Slic3r::Geometry::directions_parallel_within(PI/2, PI, 0), 'directions_parallel_within';
  27. ok !Slic3r::Geometry::directions_parallel_within(PI/2, PI, PI/180), 'directions_parallel_within';
  28. }
  29. {
  30. my $positions = Slic3r::Geometry::arrange(4, Slic3r::Pointf->new(20, 20), 5);
  31. is scalar(@$positions), 4, 'arrange() returns expected number of positions';
  32. }
  33. __END__