NAME

Algorithm::Line::Lerp - 2D grid line drawing via linear interpolation

SYNOPSIS

use Algorithm::Line::Lerp 'line';

my $points = line( [0,0], [2,11] );
for my $p (@$points) { ...

DESCRIPTION

This module offers both Bresenham and linear interpolation line drawing algorithms. See eg/bench for a comparison.

Caveats of line include potential floating point portability problems or "aesthetic issues" depending on how lround in line behaves. bline is probably more predictable, but may be slower.

FUNCTIONS

These are not exported by default.

bline p1 p2

Same interface as line but uses the traditional Bresenham algorithm.

Since version 0.02.

line p1 p2

Given two points (array references of x, y values) returns an array reference of the points between the two points using linear interpolation. This may simply be a copy of point p1 (when p1 and p2 are equal) or a longer list of points.

SEE ALSO

Algorithm::Line::Bresenham - pure perl, plus support for other shapes.

Game::Xomb has a custom Bresenham implementation that deals with various gameplay elements.

https://www.redblobgames.com/grids/line-drawing.html

AUTHOR

Jeremy Mates, <jmates@thrig.me>

COPYRIGHT AND LICENSE

Copyright 2023 Jeremy Mates

This program is distributed under the (Revised) BSD License: https://opensource.org/licenses/BSD-3-Clause