]> git.imager.perl.org - imager.git/commitdiff
[rt.cpan.org #29938] add matrix() method to Imager::Matrix2d
authorTony Cook <tony@develop-help.com>
Sun, 23 Jan 2011 12:12:34 +0000 (23:12 +1100)
committerTony Cook <tony@develop-help.com>
Sun, 23 Jan 2011 12:12:34 +0000 (23:12 +1100)
Changes
lib/Imager/Matrix2d.pm
t/t16matrix.t

diff --git a/Changes b/Changes
index 0dad68e01e551a0647621bc9cd39d5bd37c0e0d3..29363106b3c5279c82071da73e36f9d718947f73 100644 (file)
--- a/Changes
+++ b/Changes
@@ -13,6 +13,10 @@ Bug fixes:
  - update the filter plugin documentation.
    https://rt.cpan.org/Ticket/Display.html?id=56513
 
+ - add the matrix() method to Imager::Matrix2d to allow creation of a
+   matrix with specified co-efficients.
+   https://rt.cpan.org/Ticket/Display.html?id=29938
+
 Imager 0.80 - 17 Jan 2011
 ===========
 
index a0c0dbab18ca2b3fc52efd746fabd5e8885e1be8..49984c5cfe677c3ba74f2834b21e358fafe34a84 100644 (file)
@@ -17,6 +17,9 @@ $VERSION = "1.009";
   $m4 = Imager::Matrix2d->shear(x=>$sx, y=>$sy);
   $m5 = Imager::Matrix2d->reflect(axis=>$axis);
   $m6 = Imager::Matrix2d->scale(x=>$xratio, y=>$yratio);
+  $m8 = Imager::Matric2d->matrix($v11, $v12, $v13,
+                                 $v21, $v22, $v23,
+                                 $v31, $v32, $v33);
   $m6 = $m1 * $m2;
   $m7 = $m1 + $m2;
   use Imager::Matrix2d qw(:handy);
@@ -235,6 +238,24 @@ sub scale {
   }
 }
 
+=item matrix($v11, $v12, $v13, $v21, $v22, $v23, $v31, $v32, $v33)
+
+Create a matrix with custom co-efficients.
+
+=cut
+
+sub matrix {
+  my ($class, @self) = @_;
+
+  if (@self == 9) {
+    return bless \@self, $class;
+  }
+  else {
+    $Imager::ERRSTR = "9 co-efficients required";
+    return;
+  }
+}
+
 =item _mult()
 
 Implements the overloaded '*' operator.  Internal use.
index 4359d19ed40daa6878155e0d6fd321b433abd5c6..e6c23e2508da2a18ee3d858277de22c1de57a2dc 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 10;
+use Test::More tests => 13;
 use Imager;
 
 BEGIN { use_ok('Imager::Matrix2d', ':handy') }
@@ -38,6 +38,11 @@ ok(almost_equal($scale, [ 1.2, 0,   0,
                           0,   0.8, 0,
                           0,   0,   1 ]), "scale matrix");
 
+my $custom = Imager::Matrix2d->matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
+ok(almost_equal($custom, [ 1, 0, 0,
+                       0, 1, 0,
+                       0, 0, 1 ]), "custom matrix");
+
 my $trans_called;
 $rotate = Imager::Matrix2d::Test->rotate(degrees=>90, x=>50);
 ok($trans_called, "translate called on rotate with just x");
@@ -46,6 +51,9 @@ $trans_called = 0;
 $rotate = Imager::Matrix2d::Test->rotate(degrees=>90, 'y'=>50);
 ok($trans_called, "translate called on rotate with just y");
 
+ok(!Imager::Matrix2d->matrix(), "bad custom matrix");
+is(Imager->errstr, "9 co-efficients required", "check error");
+
 sub almost_equal {
   my ($m1, $m2) = @_;
 
@@ -66,3 +74,4 @@ sub translate {
   ++$trans_called;
   return $class->SUPER::translate(%opts);
 }
+