angles.t 3.0 KB

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