GD
view release on metacpan or search on metacpan
lib/GD/Polygon.pm view on Meta::CPAN
package GD::Polygon;
use strict;
use Carp 'carp';
use GD;
use vars '$VERSION';
$VERSION = '2.82';
# old documentation error
*GD::Polygon::delete = \&deletePt;
=head1 NAME
GD::Polygon - Polygon class for the GD image library
=head1 SYNOPSIS
See L<GD>
=head1 DESCRIPTION
See L<GD>
=head1 AUTHOR
The GD.pm interface is copyright 1995-2005, Lincoln D. Stein. It is
distributed under the same terms as Perl itself. See the "Artistic
License" in the Perl source code distribution for licensing terms.
The latest versions of GD.pm are available on CPAN:
http://www.cpan.org
=head1 SEE ALSO
L<GD>
L<GD::Polyline>,
L<GD::SVG>,
L<GD::Simple>,
L<Image::Magick>
=cut
### The polygon object ###
# create a new polygon
sub new {
my $class = shift;
return bless { 'length'=>0,'points'=>[] },$class;
}
# automatic destruction of the polygon
sub DESTROY {
my $self = shift;
undef $self->{'points'};
}
sub clear {
my $self = shift;
$self->{'points'} = [];
$self->{'length'} = 0;
}
# add an x,y vertex to the polygon
sub addPt {
my($self,$x,$y) = @_;
push(@{$self->{'points'}},[$x,$y]);
$self->{'length'}++;
}
# get a vertex
sub getPt {
my($self,$index) = @_;
return () unless ($index >= 0) && ($index < $self->{'length'});
return @{$self->{'points'}->[$index]};
}
# change the value of a vertex
sub setPt {
my($self,$index,$x,$y) = @_;
unless (($index>=0) && ($index<$self->{'length'})) {
carp "Attempt to set an undefined polygon vertex";
return undef;
}
@{$self->{'points'}->[$index]} = ($x,$y);
1;
}
# return the total number of vertices
sub length {
shift->{'length'}
}
# return the array of vertices.
# each vertex is an two-member (x,y) array
sub vertices {
@{shift->{'points'}}
}
# return the bounding box of the polygon
# (smallest rectangle that contains it)
( run in 1.356 second using v1.01-cache-2.11-cpan-39bf76dae61 )