]> git.imager.perl.org - imager.git/commitdiff
improve error reporting for the polygon method
authorTony Cook <tony@develop-help.com>
Sat, 24 Nov 2018 01:32:41 +0000 (12:32 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 24 Nov 2018 01:32:41 +0000 (12:32 +1100)
Imager.pm
t/250-draw/050-polyaa.t

index c8d24365fd266baa052ac5278dfc63be84b76ee5..d3caaf4cb951523b6b79bab51492828c81848b64 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -3106,16 +3106,20 @@ sub polygon {
         return undef;
       }
     }
-    i_poly_aa_cfill_m($self->{IMG}, $opts{'x'}, $opts{'y'}, 
-                    $mode, $opts{'fill'}{'fill'});
+    unless (i_poly_aa_cfill_m($self->{IMG}, $opts{'x'}, $opts{'y'},
+                             $mode, $opts{'fill'}{'fill'})) {
+      return $self->_set_error($self->_error_as_msg);
+    }
   }
   else {
     my $color = _color($opts{'color'});
     unless ($color) { 
       $self->{ERRSTR} = $Imager::ERRSTR; 
-      return; 
+      return;
+    }
+    unless (i_poly_aa_m($self->{IMG}, $opts{'x'}, $opts{'y'}, $mode, $color)) {
+      return $self->_set_error($self->_error_as_msg);
     }
-    i_poly_aa_m($self->{IMG}, $opts{'x'}, $opts{'y'}, $mode, $color);
   }
 
   return $self;
index 5992b54781b7dc7c427214851d92bb04864c9700..705d5cb347a35d7c21709e750c7b8c67292dff0c 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 
 use strict;
-use Test::More tests => 24;
+use Test::More tests => 28;
 
 use Imager qw/NC/;
 use Imager::Test qw(is_image is_color3);
@@ -249,6 +249,20 @@ my $black = Imager::Color->new(0, 0, 0);
      "save to file");
 }
 
+{
+  # fail 2 point polygon
+  my $im = Imager->new(xsize => 10, ysize => 10);
+  ok(!$im->polygon(x => [ 0, 5 ], y => [ 0, 5 ]),
+     "fail to draw poly with only two points");
+  like($im->errstr, qr/polygons must have at least 3 points/,
+       "check error message");
+  my $im2 = Imager->new(xsize => 10, ysize => 10);
+  ok(!$im2->polygon(x => [ 0, 5 ], y => [ 0, 5 ], fill => { solid => "#FFFFFF" }),
+     "fail to draw poly with only two points (fill)");
+  like($im2->errstr, qr/polygons must have at least 3 points/,
+       "check error message");
+}
+
 Imager->close_log;
 
 Imager::malloc_state();