]> git.imager.perl.org - imager.git/commitdiff
- the straight edges of filled arcs weren't being drawn correctly,
authorTony Cook <tony@develop=help.com>
Tue, 29 Nov 2005 09:27:16 +0000 (09:27 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 29 Nov 2005 09:27:16 +0000 (09:27 +0000)
  causing minor artifacts at the inner and external corners

Changes
draw.c
t/t21draw.t

diff --git a/Changes b/Changes
index d0c1d8f461bd9469dece286324604c49bfe188f0..736f8332747341019e835182373e9121c1c13eb2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1191,6 +1191,8 @@ Revision history for Perl extension Imager.
 - add --nolog command-line switch to Makefile.PL to disable logging
 - filled polygons using a complex fill with combine != 0 (none) didn't
   correctly handle polygons that crossed a given scanline more than once.
+- the straight edges of filled arcs weren't being drawn correctly, 
+  causing minor artifacts at the inner and external corners
 
 =================================================================
 
diff --git a/draw.c b/draw.c
index c52d5a0b7a70a3326c529a6e27d5ba06a905bb46..d7426e2482dedc0bd49efae87be7da44bf46c7af 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -112,14 +112,14 @@ i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar) {
   double dsec;
   int temp;
   alpha=(double)(y2-y1)/(double)(x2-x1);
-  if (fabs(alpha)<1) 
+  if (fabs(alpha) <= 1) 
     {
       if (x2<x1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
       dsec=y1;
-      while(x1<x2)
+      while(x1<=x2)
        {
-         dsec+=alpha;
          i_mmarray_add(ar,x1,(int)(dsec+0.5));
+         dsec+=alpha;
          x1++;
        }
     }
@@ -128,10 +128,10 @@ i_arcdraw(int x1, int y1, int x2, int y2, i_mmarray *ar) {
       alpha=1/alpha;
       if (y2<y1) { temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; }
       dsec=x1;
-      while(y1<y2)
+      while(y1<=y2)
        {
-         dsec+=alpha;
          i_mmarray_add(ar,(int)(dsec+0.5),y1);
+         dsec+=alpha;
          y1++;
        }
     }
index 96ee18c17ba573772961271df2b2cce01ee99ef9..318ff9c38537bd3cc4eff6d46fd8f471a756d1bf 100644 (file)
@@ -7,7 +7,7 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
-use Test::More tests => 38;
+use Test::More tests => 43;
 my $loaded;
 
 BEGIN { use_ok(Imager=>':all'); }
@@ -21,7 +21,7 @@ my $blueobj = NC(0, 0, 255);
 my $blue = { hue=>240, saturation=>1, value=>1 };
 my $white = '#FFFFFF';
 
-my $img = Imager->new(xsize=>100, ysize=>300);
+my $img = Imager->new(xsize=>100, ysize=>500);
 
 ok($img->box(color=>$blueobj, xmin=>10, ymin=>10, xmax=>48, ymax=>18),
    "box with color obj");
@@ -102,20 +102,40 @@ ok($img->arc(x=>75, 'y'=>125, r=>20, d1=>315, d2=>45,
    "fill arc through angle 0");
 ok($img->arc(x=>25, 'y'=>175, r=>20, d1=>315, d2=>225, color=>$redobj),
    "concave color arc");
+angle_marker($img, 25, 175, 23, 315, 225);
 ok($img->arc(x=>75, 'y'=>175, r=>20, d1=>315, d2=>225,
             fill => { solid=>$greenobj, combine=>'diff' }),
    "concave fill arc");
+angle_marker($img, 75, 175, 23, 315, 225);
 ok($img->arc(x=>25, y=>225, r=>20, d1=>135, d2=>45, color=>$redobj),
    "another concave color arc");
+angle_marker($img, 25, 225, 23, 45, 135);
 ok($img->arc(x=>75, y=>225, r=>20, d1=>135, d2=>45, 
-            fille => { solid=>$blueobj, combine=>'diff' }),
+            fill => { solid=>$blueobj, combine=>'diff' }),
    "another concave fillarc");
+angle_marker($img, 75, 225, 23, 45, 135);
 ok($img->arc(x=>25, y=>275, r=>20, d1=>135, d2=>45, color=>$redobj, aa=>1),
    "concave color arc aa");
 ok($img->arc(x=>75, y=>275, r=>20, d1=>135, d2=>45, 
-            fille => { solid=>$blueobj, combine=>'diff' }, aa=>1),
+            fill => { solid=>$blueobj, combine=>'diff' }, aa=>1),
    "concave fill arc aa");
 
+ok($img->circle(x=>25, y=>325, r=>20, color=>$redobj),
+   "color circle no aa");
+ok($img->circle(x=>75, y=>325, r=>20, color=>$redobj, aa=>1),
+   "color circle aa");
+ok($img->circle(x=>25, 'y'=>375, r=>20, 
+               fill => { hatch=>'stipple', fg=>$blueobj, bg=>$redobj }),
+   "fill circle no aa");
+ok($img->circle(x=>75, 'y'=>375, r=>20, aa=>1,
+               fill => { hatch=>'stipple', fg=>$blueobj, bg=>$redobj }),
+   "fill circle aa");
+
+ok($img->arc(x=>50, y=>450, r=>45, d1=>135, d2=>45, 
+            fill => { solid=>$blueobj, combine=>'diff' }),
+   "another concave fillarc");
+angle_marker($img, 50, 450, 47, 45, 135);
+
 ok($img->write(file=>'testout/t21draw.ppm'),
    "saving output");
 
@@ -130,3 +150,18 @@ sub color_cmp {
     || $l[1] <=> $r[1]
       || $l[2] <=> $r[2];
 }
+
+use constant PI => 4 * atan2(1,1);
+
+sub angle_marker {
+  my ($img, $x, $y, $radius, @angles) = @_;
+
+  for my $angle (@angles) {
+    my $x1 = int($x + $radius * cos($angle * PI / 180) + 0.5);
+    my $y1 = int($y + $radius * sin($angle * PI / 180) + 0.5);
+    my $x2 = int($x + (5+$radius) * cos($angle * PI / 180) + 0.5);
+    my $y2 = int($y + (5+$radius) * sin($angle * PI / 180) + 0.5);
+    
+    $img->line(x1=>$x1, y1=>$y1, x2=>$x2, y2=>$y2, color=>'#FFF');
+  }
+}