[rt #87650] change setpixel()'s return value
authorTony Cook <tony@develop-help.com>
Tue, 1 Oct 2013 06:37:32 +0000 (16:37 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 1 Oct 2013 06:37:32 +0000 (16:37 +1000)
Imager.pm
lib/Imager/Draw.pod
lib/Imager/Test.pm
t/100-base/010-introvert.t
t/150-type/100-masked.t

index 9475e401e0b10cbd77e3313508a0e7b6e0d76771..7754e28b53d9e3f76d2299a3ec26f21dd1a2c4f7 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -3242,15 +3242,15 @@ sub setpixel {
   else {
     if ($color->isa('Imager::Color')) {
       i_ppix($self->{IMG}, $x, $y, $color)
-       and return;
+       and return "0 but true";
     }
     else {
       i_ppixf($self->{IMG}, $x, $y, $color)
-       and return;
+       and return "0 but true";
     }
-  }
 
-  return $self;
+    return 1;
+  }
 }
 
 sub getpixel {
index da6d8427126351bc2d5bf6d75b1e135009de113a..057a129c59acddbec2491e43ba7681deea3c15ee 100644 (file)
@@ -527,11 +527,10 @@ Default: white.
 
 =back
 
-When called with an array reference in either C<x> or C<y>, returns
-the number of pixels successfully set, or false if none.
+Returns the number of pixels drawn, if no pixels were drawn, but none
+of the errors below occur, returns C<"0 but true">.
 
-When called with scalars for x and y, return $img on success, false on
-failure.
+For other errors, setpixel() returns an empty list and sets errstr().
 
 Possible errors conditions include:
 
@@ -548,9 +547,6 @@ color.
 
 =back
 
-On any of these errors, setpixel() returns an empty list and sets
-errstr().
-
 =item getpixel()
 
   my $color = $img->getpixel(x=>50, y=>70); my @colors =
index 5c4f58e1b56f6ca0dbec1db44524eaa78c1676d0..1c3837af19e80c8111270670bc32d135951775df 100644 (file)
@@ -7,7 +7,7 @@ use vars qw(@ISA @EXPORT_OK $VERSION);
 use Carp qw(croak carp);
 use Config;
 
-$VERSION = "1.002";
+$VERSION = "1.003";
 
 @ISA = qw(Exporter);
 @EXPORT_OK = 
@@ -572,14 +572,22 @@ sub image_bounds_checks {
   my $black = Imager::Color->new(0, 0, 0);
   require Imager::Color::Float;
   my $blackf = Imager::Color::Float->new(0, 0, 0);
-  $builder->ok(!$im->setpixel(x => -1, y => 0, color => $black), 'bounds check set (-1, 0)');
-  $builder->ok(!$im->setpixel(x => 10, y => 0, color => $black), 'bounds check set (10, 0)');
-  $builder->ok(!$im->setpixel(x => 0, y => -1, color => $black), 'bounds check set (0, -1)');
-  $builder->ok(!$im->setpixel(x => 0, y => 10, color => $black), 'bounds check set (0, 10)');
-  $builder->ok(!$im->setpixel(x => -1, y => 0, color => $blackf), 'bounds check set (-1, 0) float');
-  $builder->ok(!$im->setpixel(x => 10, y => 0, color => $blackf), 'bounds check set (10, 0) float');
-  $builder->ok(!$im->setpixel(x => 0, y => -1, color => $blackf), 'bounds check set (0, -1) float');
-  $builder->ok(!$im->setpixel(x => 0, y => 10, color => $blackf), 'bounds check set (0, 10) float');
+  $builder->ok($im->setpixel(x => -1, y => 0, color => $black) == 0,
+              'bounds check set (-1, 0)');
+  $builder->ok($im->setpixel(x => 10, y => 0, color => $black) == 0,
+              'bounds check set (10, 0)');
+  $builder->ok($im->setpixel(x => 0, y => -1, color => $black) == 0,
+              'bounds check set (0, -1)');
+  $builder->ok($im->setpixel(x => 0, y => 10, color => $black) == 0,
+              'bounds check set (0, 10)');
+  $builder->ok($im->setpixel(x => -1, y => 0, color => $blackf) == 0,
+              'bounds check set (-1, 0) float');
+  $builder->ok($im->setpixel(x => 10, y => 0, color => $blackf) == 0,
+              'bounds check set (10, 0) float');
+  $builder->ok($im->setpixel(x => 0, y => -1, color => $blackf) == 0,
+              'bounds check set (0, -1) float');
+  $builder->ok($im->setpixel(x => 0, y => 10, color => $blackf) == 0,
+              'bounds check set (0, 10) float');
 }
 
 sub test_colorf_gpix {
index d040eafb3762306192e6ba3794f79ca0ed1acf0b..e13d57b646f58c8c6bcb463285e02b9efe2be24c 100644 (file)
@@ -1007,45 +1007,47 @@ my $psamp_outside_error = "Image position outside of image";
   my $im = Imager->new(xsize => 10, ysize => 10);
   { # errors
     my $empty = Imager->new;
-    ok(!$empty->setpixel(x => 0, y => 0, color => $red),
+    is_deeply([ $empty->setpixel(x => 0, y => 0, color => $red) ], [],
        "setpixel on empty image");
     is($empty->errstr, "setpixel: empty input image", "check message");
 
-    ok(!$im->setpixel(y => 0, color => $red), "missing x");
+    is_deeply([ $im->setpixel(y => 0, color => $red) ], [], "missing x");
     is($im->errstr, "setpixel: missing x or y parameter", "check message");
 
     $im->_set_error("something different");
-    ok(!$im->setpixel(x => 0, color => $red), "missing y");
+    is_deeply([$im->setpixel(x => 0, color => $red)], [], "missing y");
     is($im->errstr, "setpixel: missing x or y parameter", "check message");
 
-    ok(!$im->setpixel(x => [], y => 0, color => $red), "empty x array ref");
+    is_deeply([ $im->setpixel(x => [], y => 0, color => $red) ], [],
+             "empty x array ref");
     is($im->errstr, "setpixel: x is a reference to an empty array",
        "check message");
 
-    ok(!$im->setpixel(x => 0, y => [], color => $red), "empty y array ref");
+    is_deeply([$im->setpixel(x => 0, y => [], color => $red)], [],
+             "empty y array ref");
     is($im->errstr, "setpixel: y is a reference to an empty array",
        "check message");
 
-    ok(!$im->setpixel(x => 0, y => 0, color => "not really a color"),
+    is_deeply([ $im->setpixel(x => 0, y => 0, color => "not really a color") ], [],
        "color not a color");
     is($im->errstr, "setpixel: No color named not really a color found",
        "check message");
   }
 
   # simple set
-  is($im->setpixel(x => 0, y => 0, color => $red), $im,
+  is($im->setpixel(x => 0, y => 0, color => $red), 1,
      "simple setpixel")
     or diag "simple set float: ", $im->errstr;
   is_color3($im->getpixel(x => 0, y => 0), 255, 0, 0, "check stored pixel");
 
-  is($im->setpixel(x => 1, y => 2, color => $f_red), $im,
+  is($im->setpixel(x => 1, y => 2, color => $f_red), 1,
      "simple setpixel (float)")
     or diag "simple set float: ", $im->errstr;
   is_color3($im->getpixel(x => 1, y => 2), 255, 0, 0, "check stored pixel");
 
-  is($im->setpixel(x => -1, y => 0, color => $red), undef,
+  is($im->setpixel(x => -1, y => 0, color => $red), "0 but true",
      "simple setpixel outside of image");
-  is($im->setpixel(x => 0, y => -1, color => $f_red), undef,
+  is($im->setpixel(x => 0, y => -1, color => $f_red), "0 but true",
      "simple setpixel (float) outside of image");
 
   # simple arrayrefs
@@ -1094,7 +1096,7 @@ my $psamp_outside_error = "Image position outside of image";
     is_color3($colors[2], 0, 255, 0, "check third color");
   }
   { # default color
-    is($im->setpixel(x => 0, y => 9), $im, "setpixel() default color")
+    is($im->setpixel(x => 0, y => 9), 1, "setpixel() default color")
       or diag "setpixel default color: ", $im->errstr;
     is_color3($im->getpixel(x => 0, y => 9), 255, 255, 255,
              "check color set");
index 95d5f1a089e87a054f34862f541ab2064f8b4481..690dd3b718c8ad5ead6fb5287747845c752c7ab6 100644 (file)
@@ -204,9 +204,9 @@ $mask->box(fill => { hatch => "check1x1" }, ymin => 40, xmax => 39);
     }
     {
       # write out of range should fail
-      ok(!$masked->setpixel(x => 80, y => 0, color => $green),
+      is($masked->setpixel(x => 80, y => 0, color => $green), "0 but true",
         "write 8-bit color out of range");
-      ok(!$masked->setpixel(x => 0, y => 80, color => $greenf),
+      is($masked->setpixel(x => 0, y => 80, color => $greenf), "0 but true",
         "write float color out of range");
     }
   }