angles.t 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan tests => 26;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. }
  9. use Slic3r;
  10. use Slic3r::Geometry qw(line_atan line_direction rad2deg_dir angle3points PI);
  11. #==========================================================
  12. {
  13. is line_atan([ [0, 0], [10, 0] ]), (0), 'E atan2';
  14. is line_atan([ [10, 0], [0, 0] ]), (PI), 'W atan2';
  15. is line_atan([ [0, 0], [0, 10] ]), (PI/2), 'N atan2';
  16. is line_atan([ [0, 10], [0, 0] ]), -(PI/2), 'S atan2';
  17. is line_atan([ [10, 10], [0, 0] ]), -(PI*3/4), 'SW atan2';
  18. is line_atan([ [0, 0], [10, 10] ]), (PI*1/4), 'NE atan2';
  19. is line_atan([ [0, 10], [10, 0] ]), -(PI*1/4), 'SE atan2';
  20. is line_atan([ [10, 0], [0, 10] ]), (PI*3/4), 'NW atan2';
  21. }
  22. #==========================================================
  23. {
  24. is line_direction([ [0, 0], [10, 0] ]), (0), 'E direction';
  25. is line_direction([ [10, 0], [0, 0] ]), (0), 'W direction';
  26. is line_direction([ [0, 0], [0, 10] ]), (PI/2), 'N direction';
  27. is line_direction([ [0, 10], [0, 0] ]), (PI/2), 'S direction';
  28. is line_direction([ [10, 10], [0, 0] ]), (PI*1/4), 'SW direction';
  29. is line_direction([ [0, 0], [10, 10] ]), (PI*1/4), 'NE direction';
  30. is line_direction([ [0, 10], [10, 0] ]), (PI*3/4), 'SE direction';
  31. is line_direction([ [10, 0], [0, 10] ]), (PI*3/4), 'NW direction';
  32. }
  33. #==========================================================
  34. {
  35. is rad2deg_dir(0), 90, 'E (degrees)';
  36. is rad2deg_dir(PI), 270, 'W (degrees)';
  37. is rad2deg_dir(PI/2), 0, 'N (degrees)';
  38. is rad2deg_dir(-(PI/2)), 180, 'S (degrees)';
  39. is rad2deg_dir(PI*1/4), 45, 'NE (degrees)';
  40. is rad2deg_dir(PI*3/4), 135, 'NW (degrees)';
  41. is rad2deg_dir(PI/6), 60, '30°';
  42. is rad2deg_dir(PI/6*2), 30, '60°';
  43. }
  44. #==========================================================
  45. {
  46. is angle3points([0,0], [10,0], [0,10]), PI/2, 'CW angle3points';
  47. is angle3points([0,0], [0,10], [10,0]), PI/2*3, 'CCW angle3points';
  48. }
  49. #==========================================================