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