]> git.imager.perl.org - imager.git/commitdiff
- Imager::Matrix2d->rotate() would only rotate around the supplied
authorTony Cook <tony@develop=help.com>
Wed, 27 Apr 2005 07:59:43 +0000 (07:59 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 27 Apr 2005 07:59:43 +0000 (07:59 +0000)
  centre point if both 'x' and 'y' were non-zero.

Changes
TODO
lib/Imager/Matrix2d.pm
t/t16matrix.t

diff --git a/Changes b/Changes
index daec8e3785870f5e21c11d8d259687d56b40d831..0844dea2dc99eaa34c47a72b0ce2e509a794cdfe 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1072,6 +1072,8 @@ Revision history for Perl extension Imager.
   Implemented for all four font drivers.
 - Win32 font bounding_box() method now supports the advance width
   and right bearing values.
+- Imager::Matrix2d->rotate() would only rotate around the supplied 
+  centre point if both 'x' and 'y' were non-zero.
 
 =================================================================
 
diff --git a/TODO b/TODO
index fd16eb8d9bcd62f47ecccfe24ec8a1b4c96f55df..9cc26ef77515d51a22d99911904d0a75cef1f747 100644 (file)
--- a/TODO
+++ b/TODO
@@ -28,7 +28,7 @@ not commitments.
   function (done for all drivers)
 - capture TIFF read warnings (i_warnings tag?) (done)
 - Imager::Matrix2d rotate method only applies offset if both x and y
-  are non-zero, it should do it if either is non-zero
+  are non-zero, it should do it if either is non-zero (done)
 - add Imager::Cookbook with at least 5 recipes (done)
 - store floating point tags in an appropriate precision (done)
 - allow image creation to fail on malloc() failure for the image data
index 4f67f701acd1b57f9a1f01c5306bf3e6bd5e21da..6aca2f9ecf76e45d01efebd2fa2402c9ef083523 100644 (file)
@@ -91,7 +91,9 @@ sub rotate {
     return undef;
   }
 
-  if ($opts{'x'} && $opts{'y'}) {
+  if ($opts{'x'} || $opts{'y'}) {
+    $opts{'x'} ||= 0;
+    $opts{'y'} ||= 0;
     return $class->translate('x'=>-$opts{'x'}, 'y'=>-$opts{'y'})
       * $class->rotate(radians=>$angle)
         * $class->translate('x'=>$opts{'x'}, 'y'=>$opts{'y'});
index 9a2760302ef3fb0c522eb943b4df59ff830f352a..7cedd34e2422b76ef89f5071cd51e49ca29dbbf1 100644 (file)
@@ -1,41 +1,43 @@
 #!perl -w
-
+use strict;
+use lib 't';
+use Test::More tests => 8;
 use Imager;
-my $loaded;
-BEGIN { $|=1; print "1..6\n"; }
-END { print "not ok 1\n" unless $loaded; }
-use Imager::Matrix2d ':handy';
-print "ok 1\n";
-$loaded = 1;
+
+BEGIN { use_ok('Imager::Matrix2d', ':handy') }
 
 my $id = Imager::Matrix2d->identity;
 
-almost_equal($id, [ 1, 0, 0,
-                    0, 1, 0,
-                    0, 0, 1 ]) or print "not ";
-print "ok 2\n";
+ok(almost_equal($id, [ 1, 0, 0,
+                       0, 1, 0,
+                       0, 0, 1 ]), "identity matrix");
 my $trans = Imager::Matrix2d->translate('x'=>10, 'y'=>-11);
-almost_equal($trans, [ 1, 0, 10,
-                       0, 1, -11,
-                       0, 0, 1 ]) or print "not ";
-print "ok 3\n";
+ok(almost_equal($trans, [ 1, 0, 10,
+                          0, 1, -11,
+                          0, 0, 1 ]), "translate matrix");
+
 my $rotate = Imager::Matrix2d->rotate(degrees=>90);
-almost_equal($rotate, [ 0, -1, 0,
-                        1, 0,  0,
-                        0, 0,  1 ]) or print "not ";
-print "ok 4\n";
+ok(almost_equal($rotate, [ 0, -1, 0,
+                           1, 0,  0,
+                           0, 0,  1 ]), "rotate matrix");
 
 my $shear = Imager::Matrix2d->shear('x'=>0.2, 'y'=>0.3);
-almost_equal($shear, [ 1,   0.2, 0,
-                       0.3, 1,   0,
-                       0,   0,   1 ]) or print "not ";
-print "ok 5\n";
+ok(almost_equal($shear, [ 1,   0.2, 0,
+                          0.3, 1,   0,
+                          0,   0,   1 ]), "shear matrix");
 
 my $scale = Imager::Matrix2d->scale('x'=>1.2, 'y'=>0.8);
-almost_equal($scale, [ 1.2, 0,   0,
-                       0,   0.8, 0,
-                       0,   0,   1 ]) or print "not ";
-print "ok 6\n";
+ok(almost_equal($scale, [ 1.2, 0,   0,
+                          0,   0.8, 0,
+                          0,   0,   1 ]), "scale matrix");
+
+my $trans_called;
+$rotate = Imager::Matrix2d::Test->rotate(degrees=>90, x=>50);
+ok($trans_called, "translate called on rotate with just x");
+
+$trans_called = 0;
+$rotate = Imager::Matrix2d::Test->rotate(degrees=>90, 'y'=>50);
+ok($trans_called, "translate called on rotate with just y");
 
 sub almost_equal {
   my ($m1, $m2) = @_;
@@ -45,3 +47,15 @@ sub almost_equal {
   }
   return 1;
 }
+
+# this is used to ensure translate() is called correctly by rotate
+package Imager::Matrix2d::Test;
+use vars qw(@ISA);
+BEGIN { @ISA = qw(Imager::Matrix2d); }
+
+sub translate {
+  my ($class, %opts) = @_;
+
+  ++$trans_called;
+  return $class->SUPER::translate(%opts);
+}