=head1 NAME
Algorithm::Line::Bresenham - simple pixellated line-drawing algorithm
=head1 SYNOPSIS
use Algorithm::Line::Bresenham qw/line/;
my @points = line(3,3 => 5,0);
# returns the list: [3,3], [4,2], [4,1], [5,0]
my @points = circle(30,30,5);
# returns the points to draw a circle centered at 30,30, radius 5
=head1 DESCRIPTION
Bresenham is one of the canonical line drawing algorithms for pixellated grids.
Given a start and an end-point, Bresenham calculates which points on the grid
need to be filled to generate the line between them.
Googling for 'Bresenham', and 'line drawing algorithms' gives some good
overview. The code here are adapted from various sources, mainly from
C code at https://gist.github.com/bert/1085538
=head1 FUNCTIONS
=cut
=head2 C
line ($from_x, $from_y => $to_x, $to_y);
Generates a list of all the intermediate points. This is returned as a list
of array references. Previous versions used to include a callback parameter
as a CODE ref to act on each point in turn. This version omits that for
performance reasons
=cut
=head2 C
my @points = circle ($x, $y, $radius)
Returns the points to draw a circle centered on C<$x,$y> with
radius C<$radius>
=cut
=head2 C
my @points = ellipse_rect ($x0, $y0, $x1, $y1)
Returns the points to an ellipse bound within a rectangle defined by
the two coordinate pairs passed.
=cut
=head2 C
my @points = basic_bezier ($x0, $y0, $x1, $y1, $x2, $y2)
This is not usefull on its own. Iteturns the points to segment of a
bezier curve without a gradient sign change. It is a companion to
the C function that splits a bezier into segments
with each gradient direction and these segments are computed in
C
=cut
=head2 C
my @points = quad_bezier ($x0, $y0, $x1, $y1, $x2, $y2)
Draws a Bezier curve from C<($x0,$y0)> to C<($x2,$y2)> using control
point C<($x1,$y1)>
=cut
=head2 C
my @points = polyline ($x0, $y0, $x1, $y1, $x2, $y2)
Draws a polyline between points served as a list of x,y pairs
=cut
=head1 TODO and BUGS
polylines
nurbs
arc
line width
fills
pattern fills
=head1 THANKS
Patches for the circle algorithm and a float value bug contributed by Richard Clamp, thanks!
=head1 AUTHOR
osfameron, osfameron@cpan.org
saiftynet
=head1 LICENSE
Artistic (Perl)
=head1 INSTALLATION
Using C:
$ cpan Algorithm::Line::Bresenham
Manual install:
$ perl Makefile.PL
$ make
$ make install
Copyright (c) 2004-2022 saiftynet, osfameron. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
=cut