NAME
Graphics::Penplotter::GcodeXY::Hatch - Scanline hatch-fill for GcodeXY paths
SYNOPSIS
$g->sethatchsep(2); # 2-unit spacing between hatch lines
$g->sethatchangle(45); # 45-degree hatch lines (default: 0 = horizontal)
$g->polygon(0,0, 10,0, 10,10, 0,10, 0,0);
$g->strokefill(); # hatch-fill the polygon and stroke it
DESCRIPTION
A Role::Tiny role providing scanline hatch-fill at any angle for Graphics::Penplotter::GcodeXY.
The entry points are sethatchsep, sethatchangle, and strokefill. The internal method _dohatching is also composed in so that Graphics::Penplotter::GcodeXY::Font's _doglyphs can call it via $self->_dohatching() when rendering filled text.
Algorithm
_dohatching works in a rotated hatch space where the scanlines are always horizontal, regardless of the requested hatchangle:
All
psegmentsendpoints are rotated by -hatchangle into hatch space and stored in a temporary array, which is swapped into$self->{psegments}.The bounding box, scanline sweep, intersection tests (
_getsegintersect), and vertex deduplication (_identical,_sameside) all run unchanged on the rotated copy, they always see horizontal scanlines and need no modification.Before each hatch segment is recorded via
_addhsegmentpath, its endpoints are rotated back by +hatchangle into drawing space.The original
psegmentsare restored before_flushHsegmentswrites the gcode.
METHODS
- sethatchsep($sep)
-
Set the spacing between hatch lines in the current drawing unit.
- sethatchangle($degrees)
-
Set the angle of the hatch lines in degrees.
0(the default) gives horizontal lines;90gives vertical lines;45gives diagonal lines. Positive angles rotate the lines counter-clockwise. - strokefill()
-
Hatch-fill the current path at the current angle and spacing, then flush the segment queue and clear the path.
REQUIRED METHODS
_croak, gsave, grestore, _getsegintersect, _addtopage, _flushPsegments, newpath.
AUTHOR
Albert Koelmans (albert.koelmans@googlemail.com)
LICENSE
Same terms as Perl itself.