]> git.imager.perl.org - imager.git/blob - t/t16matrix.t
get it right
[imager.git] / t / t16matrix.t
1 #!perl -w
2
3 use Imager;
4 my $loaded;
5 BEGIN { $|=1; print "1..6\n"; }
6 END { print "not ok 1\n" unless $loaded; }
7 use Imager::Matrix2d ':handy';
8 print "ok 1\n";
9 $loaded = 1;
10
11 my $id = Imager::Matrix2d->identity;
12
13 almost_equal($id, [ 1, 0, 0,
14                     0, 1, 0,
15                     0, 0, 1 ]) or print "not ";
16 print "ok 2\n";
17 my $trans = Imager::Matrix2d->translate('x'=>10, 'y'=>-11);
18 almost_equal($trans, [ 1, 0, 10,
19                        0, 1, -11,
20                        0, 0, 1 ]) or print "not ";
21 print "ok 3\n";
22 my $rotate = Imager::Matrix2d->rotate(degrees=>90);
23 almost_equal($rotate, [ 0, -1, 0,
24                         1, 0,  0,
25                         0, 0,  1 ]) or print "not ";
26 print "ok 4\n";
27
28 my $shear = Imager::Matrix2d->shear('x'=>0.2, 'y'=>0.3);
29 almost_equal($shear, [ 1,   0.2, 0,
30                        0.3, 1,   0,
31                        0,   0,   1 ]) or print "not ";
32 print "ok 5\n";
33
34 my $scale = Imager::Matrix2d->scale('x'=>1.2, 'y'=>0.8);
35 almost_equal($scale, [ 1.2, 0,   0,
36                        0,   0.8, 0,
37                        0,   0,   1 ]) or print "not ";
38 print "ok 6\n";
39
40 sub almost_equal {
41   my ($m1, $m2) = @_;
42
43   for my $i (0..8) {
44     abs($m1->[$i] - $m2->[$i]) < 0.00001 or return undef;
45   }
46   return 1;
47 }