angles.t 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. use Test::More;
  2. use strict;
  3. use warnings;
  4. plan tests => 34;
  5. BEGIN {
  6. use FindBin;
  7. use lib "$FindBin::Bin/../lib";
  8. use lib "$FindBin::Bin/../lib";
  9. use lib "$FindBin::Bin/../lib";
  10. use local::lib "$FindBin::Bin/../local-lib";
  11. }
  12. use Slic3r;
  13. use Slic3r::Geometry qw(rad2deg_dir angle3points PI);
  14. #==========================================================
  15. {
  16. is line_atan([ [0, 0], [10, 0] ]), (0), 'E atan2';
  17. is line_atan([ [10, 0], [0, 0] ]), (PI), 'W atan2';
  18. is line_atan([ [0, 0], [0, 10] ]), (PI/2), 'N atan2';
  19. is line_atan([ [0, 10], [0, 0] ]), -(PI/2), 'S atan2';
  20. is line_atan([ [10, 10], [0, 0] ]), -(PI*3/4), 'SW atan2';
  21. is line_atan([ [0, 0], [10, 10] ]), (PI*1/4), 'NE atan2';
  22. is line_atan([ [0, 10], [10, 0] ]), -(PI*1/4), 'SE atan2';
  23. is line_atan([ [10, 0], [0, 10] ]), (PI*3/4), 'NW atan2';
  24. }
  25. #==========================================================
  26. {
  27. is line_orientation([ [0, 0], [10, 0] ]), (0), 'E orientation';
  28. is line_orientation([ [0, 0], [0, 10] ]), (PI/2), 'N orientation';
  29. is line_orientation([ [10, 0], [0, 0] ]), (PI), 'W orientation';
  30. is line_orientation([ [0, 10], [0, 0] ]), (PI*3/2), 'S orientation';
  31. is line_orientation([ [0, 0], [10, 10] ]), (PI*1/4), 'NE orientation';
  32. is line_orientation([ [10, 0], [0, 10] ]), (PI*3/4), 'NW orientation';
  33. is line_orientation([ [10, 10], [0, 0] ]), (PI*5/4), 'SW orientation';
  34. is line_orientation([ [0, 10], [10, 0] ]), (PI*7/4), 'SE orientation';
  35. }
  36. #==========================================================
  37. {
  38. is line_direction([ [0, 0], [10, 0] ]), (0), 'E direction';
  39. is line_direction([ [10, 0], [0, 0] ]), (0), 'W direction';
  40. is line_direction([ [0, 0], [0, 10] ]), (PI/2), 'N direction';
  41. is line_direction([ [0, 10], [0, 0] ]), (PI/2), 'S direction';
  42. is line_direction([ [10, 10], [0, 0] ]), (PI*1/4), 'SW direction';
  43. is line_direction([ [0, 0], [10, 10] ]), (PI*1/4), 'NE direction';
  44. is line_direction([ [0, 10], [10, 0] ]), (PI*3/4), 'SE direction';
  45. is line_direction([ [10, 0], [0, 10] ]), (PI*3/4), 'NW direction';
  46. }
  47. #==========================================================
  48. {
  49. is rad2deg_dir(0), 90, 'E (degrees)';
  50. is rad2deg_dir(PI), 270, 'W (degrees)';
  51. is rad2deg_dir(PI/2), 0, 'N (degrees)';
  52. is rad2deg_dir(-(PI/2)), 180, 'S (degrees)';
  53. is rad2deg_dir(PI*1/4), 45, 'NE (degrees)';
  54. is rad2deg_dir(PI*3/4), 135, 'NW (degrees)';
  55. is rad2deg_dir(PI/6), 60, '30°';
  56. is rad2deg_dir(PI/6*2), 30, '60°';
  57. }
  58. #==========================================================
  59. {
  60. is angle3points([0,0], [10,0], [0,10]), PI/2, 'CW angle3points';
  61. is angle3points([0,0], [0,10], [10,0]), PI/2*3, 'CCW angle3points';
  62. }
  63. #==========================================================
  64. sub line_atan {
  65. my ($l) = @_;
  66. return Slic3r::Line->new(@$l)->atan2_;
  67. }
  68. sub line_orientation {
  69. my ($l) = @_;
  70. return Slic3r::Line->new(@$l)->orientation;
  71. }
  72. sub line_direction {
  73. my ($l) = @_;
  74. return Slic3r::Line->new(@$l)->direction;
  75. }