ledgerHatchRect function
The source's engraving primitives, drawn on a canvas in the
source's own units: every stroke width, dash and opacity is the one its
SVG writes. Plumbing of the engravings.
art.hatch_rect: strokes at angle degrees rising to the right,
spacing apart across x, clipped exactly to the box x0, y0, x1,
y1 (gauges, bars, a card's chip). A box thinner than .4 is left bare.
Implementation
/// `art.hatch_rect`: strokes at [angle] degrees rising to the right,
/// [spacing] apart across x, clipped exactly to the box [x0], [y0], [x1],
/// [y1] (gauges, bars, a card's chip). A box thinner than .4 is left bare.
Path ledgerHatchRect(
double x0,
double y0,
double x1,
double y1,
double spacing, {
double angle = 60,
}) {
final path = Path();
if (x1 - x0 < .4 || y1 - y0 < .4) return path;
final a = angle * math.pi / 180;
final k = 1 / math.tan(a);
final h = y1 - y0;
var c = x0 - h * k - spacing;
while (c <= x1 + spacing) {
var px = c, py = y1, qx = c + h * k, qy = y0;
final at = c;
double atX(double x) => y1 - (x - at) / k;
if (px < x0) {
px = x0;
py = atX(x0);
}
if (qx > x1) {
qx = x1;
qy = atX(x1);
}
if (qx - px > .3 && py > qy) {
path
..moveTo(px, py)
..lineTo(qx, qy);
}
c += spacing;
}
return path;
}