1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
4 ######################### We start with some black magic to print on failure.
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
9 BEGIN { $| = 1; print "1..9\n"; }
10 END {print "not ok 1\n" unless $loaded;}
13 sub PI () { 3.14159265358979323846 }
18 init_log("testout/t75aapolyaa.log",1);
20 $red = Imager::Color->new(255,0,0);
21 $green = Imager::Color->new(0,255,0);
22 $blue = Imager::Color->new(0,0,255);
23 $white = Imager::Color->new(255,255,255);
26 $img = Imager->new(xsize=>20, ysize=>10);
27 @data = translate(5.5,5,
30 get_polygon(n_gon => 5)
36 my ($x, $y) = array_to_refpair(@data);
37 i_poly_aa($img->{IMG}, $x, $y, $white);
44 $img->write(file=>"testout/t75.ppm") or die $img->errstr;
48 $zoom = make_zoom($img, 8, \@data, $red);
49 $zoom->write(file=>"testout/t75zoom.ppm") or die $zoom->errstr;
53 $img = Imager->new(xsize=>300, ysize=>100);
56 @data = translate(20+20*($n%14),18+20*int($n/14),
63 my ($x, $y) = array_to_refpair(@data);
64 i_poly_aa($img->{IMG}, $x, $y, NC(rand(255), rand(255), rand(255)));
67 $img->write(file=>"testout/t75big.ppm") or die $img->errstr;
71 $img = Imager->new(xsize => 300, ysize => 300);
72 $img -> polygon(color=>$white,
77 get_polygon('wavycircle', 32*8, sub { 1.2+1*cos(4*$_) }))))
79 ) or die $img->errstr();
81 $img->write(file=>"testout/t75wave.ppm") or die $img->errstr;
86 $img = Imager->new(xsize=>10,ysize=>6);
87 @data = translate(165,5,
89 get_polygon('wavycircle', 32*8, sub { 1+1*cos(4*$_) })));
92 $img -> polygon(color=>$white,
96 get_polygon('wavycircle', 32*8, sub { 1+1*cos(4*$_) })))
98 ) or die $img->errstr();
100 make_zoom($img,20,\@data, $blue)->write(file=>"testout/t75wavebug.ppm") or die $img->errstr;
105 $img = Imager->new(xsize=>300, ysize=>300);
106 $img->polygon(fill=>{ hatch=>'cross1', fg=>'00FF00', bg=>'0000FF', dx=>3 },
110 get_polygon('wavycircle', 32*8, sub { 1+1*cos(4*$_) })))
112 ) or die $img->errstr();
113 $img->write(file=>"testout/t75wave_fill.ppm") or die $img->errstr;
117 $img = Imager->new(xsize=>300, ysize=>300, bits=>16);
118 $img->polygon(fill=>{ hatch=>'cross1', fg=>'00FF00', bg=>'0000FF' },
122 get_polygon('wavycircle', 32*8, sub { 1+1*cos(5*$_) })))
124 ) or die $img->errstr();
125 $img->write(file=>"testout/t75wave_fill16.ppm") or die $img->errstr;
135 if (exists $primitives{$name}) {
136 return @{$primitives{$name}};
139 if (exists $polygens{$name}) {
140 return $polygens{$name}->(@_);
143 die "polygon spec: $name unknown\n";
148 my ($img, $sc, $polydata, $linecolor) = @_;
150 # scale with nearest neighboor sampling
151 my $timg = $img->scale(scalefactor=>$sc, qtype=>'preview');
154 for($lx=0; $lx<$timg->getwidth(); $lx+=$sc) {
155 $timg->line(color=>$green, x1=>$lx, x2=>$lx, y1=>0, y2=>$timg->getheight(), antialias=>0);
158 for($ly=0; $ly<$timg->getheight(); $ly+=$sc) {
159 $timg->line(color=>$green, y1=>$ly, y2=>$ly, x1=>0, x2=>$timg->getwidth(), antialias=>0);
161 my @data = scale($sc, $sc, @$polydata);
162 push(@data, $data[0]);
163 my ($x, $y) = array_to_refpair(@data);
165 $timg->polyline(color=>$linecolor, 'x'=>$x, 'y'=>$y, antialias=>0);
169 # utility functions to manipulate point data
172 my ($x, $y, @data) = @_;
173 return map { [ $_->[0]*$x , $_->[1]*$y ] } @data;
177 my ($x, $y, @data) = @_;
178 map { [ $_->[0]+$x , $_->[1]+$y ] } @data;
182 my ($rad, @data) = @_;
183 map { [ $_->[0]*cos($rad)+$_->[1]*sin($rad) , $_->[1]*cos($rad)-$_->[0]*sin($rad) ] } @data;
186 sub array_to_refpair {
199 box => [ [-0.5,-0.5], [0.5,-0.5], [0.5,0.5], [-0.5,0.5] ],
200 triangle => [ [0,0], [1,0], [1,1] ],
207 my @radians = map { $_*2*PI/$numv } 0..$numv-1;
208 my @radius = map { $radfunc->($_) } @radians;
210 [ $radius[$_] * cos($radians[$_]), $radius[$_] * sin($radians[$_]) ]
216 [ cos($_*2*PI/$N), sin($_*2*PI/$N) ]