File: 42rotate.t

package info (click to toggle)
libmath-polygon-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 1,598; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More tests => 6;

use lib '../lib';
use Math::Polygon::Transform  qw/polygon_rotate/;
use Math::Polygon::Calc       qw/polygon_string polygon_format/;

my @p = ([0,0], [1,1], [-2,1], [-2,-2], [0,0]);

# format fights rounding errors
sub round($) { my $x = sprintf "%.4f", $_[0]; $x =~ s/\.?0+$//; $x }
sub rotate(@) { polygon_format \&round, polygon_rotate @_ }

is( polygon_string(rotate degrees => 0, @p)
  , "[0,0], [1,1], [-2,1], [-2,-2], [0,0]"
  , 'identity'
  );

is( polygon_string(rotate radians => 0, @p)
  , "[0,0], [1,1], [-2,1], [-2,-2], [0,0]"
  , 'identity'
  );

is( polygon_string(rotate degrees => 0, center => [0,0], @p)
  , "[0,0], [1,1], [-2,1], [-2,-2], [0,0]"
  , 'identity'
  );

is( polygon_string(rotate degrees => +90, @p)
  , "[0,0], [1,-1], [1,2], [-2,2], [0,0]"
  , 'rotate +90'
  );

is( polygon_string(rotate degrees => -90, @p)
  , "[0,0], [-1,1], [-1,-2], [2,-2], [0,0]"
  , 'rotate -90'
  );

is( polygon_string(rotate degrees => -90, center => [3,4], @p)
  , "[7,1], [6,2], [6,-1], [9,-1], [7,1]"
  , 'rotate 90 around [3,4]'
  );