03_point.t 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Slic3r::XS;
  5. use Test::More tests => 16;
  6. my $point = Slic3r::Point->new(10, 15);
  7. my $point2 = $point->clone;
  8. $point2->scale(2);
  9. is_deeply [ @$point2 ], [20, 30], 'scale';
  10. $point2->translate(10, -15);
  11. is_deeply [ @$point2 ], [30, 15], 'translate';
  12. {
  13. my $point3 = Slic3r::Point->new(4300000, -9880845);
  14. is $point->[0], $point->x, 'x accessor';
  15. is $point->[1], $point->y, 'y accessor'; #,,
  16. }
  17. {
  18. my $nearest = $point->nearest_point([ $point2, Slic3r::Point->new(100, 200) ]);
  19. ok $nearest->coincides_with($point2), 'nearest_point';
  20. }
  21. {
  22. my $line = Slic3r::Line->new([0,0], [100,0]);
  23. is +Slic3r::Point->new(0,0) ->distance_to_line($line), 0, 'distance_to_line()';
  24. is +Slic3r::Point->new(100,0)->distance_to_line($line), 0, 'distance_to_line()';
  25. is +Slic3r::Point->new(50,0) ->distance_to_line($line), 0, 'distance_to_line()';
  26. is +Slic3r::Point->new(150,0)->distance_to_line($line), 50, 'distance_to_line()';
  27. is +Slic3r::Point->new(0,50) ->distance_to_line($line), 50, 'distance_to_line()';
  28. is +Slic3r::Point->new(50,50)->distance_to_line($line), 50, 'distance_to_line()';
  29. is +Slic3r::Point->new(50,50) ->perp_distance_to_line($line), 50, 'perp_distance_to_line()';
  30. is +Slic3r::Point->new(150,50)->perp_distance_to_line($line), 50, 'perp_distance_to_line()';
  31. }
  32. {
  33. my $line = Slic3r::Line->new([50,50], [125,-25]);
  34. cmp_ok(abs(Slic3r::Point->new(100,0)->distance_to_line($line)), '<=', 4e-15, 'distance_to_line()');
  35. }
  36. {
  37. my $line = Slic3r::Line->new(
  38. [18335846,18335845],
  39. [18335846,1664160],
  40. );
  41. $point = Slic3r::Point->new(1664161,18335848);
  42. is $point->perp_distance_to_line($line), 16671685, 'perp_distance_to_line() does not overflow';
  43. }
  44. {
  45. my $p0 = Slic3r::Point->new(76975850,89989996);
  46. my $p1 = Slic3r::Point->new(76989990,109989991);
  47. my $p2 = Slic3r::Point->new(76989987,89989994);
  48. ok $p0->ccw($p1, $p2) < 0, 'ccw() does not overflow';
  49. }
  50. __END__