feat(hatch): rasterise PAT pattern lines for paper canvas + PDF

Both the on-screen paper canvas and the PDF / print pipeline only knew how
to draw the boundary outline of pattern hatches (ANSI31, ANSI37, dotted
brick, etc.) — the actual hatch lines were a GPU-only feature, so any
paper-space view or PDF export showed a hollow polygon where there should
be ruled fill.

Add a CPU rasteriser as `HatchModel::pattern_segments()`:

- builds an edge list from the boundary, splitting at NaN sentinels and
  closing each sub-path so even-odd inside tests handle islands / holes;
- for every PAT family computes the world-space step vector
  (`(dx,dy)` rotated into the family's frame, scaled by `model.scale`)
  and the inclusive k-range bounded by the boundary AABB plus a 4096-
  line safety cap;
- intersects each line with every boundary edge, sorts the hit
  parameters, walks them in pairs (even-odd) and emits one segment per
  in/out interval. Dash patterns are walked along each clipped span with
  phase preserved via `t mod period`, matching the GPU shader's
  absolute-t dash evaluation;
- pattern origin (`family.x0 / y0`) is rotated by `angle_offset` and
  scaled the same way as `hatch_batched.wgsl`, so PAT patterns with
  non-zero origins (brick / offset herringbone) line up with the GPU
  render.

`paper_canvas::draw_hatch` and `pdf_export::emit_hatch` now route
pattern hatches through this rasteriser; solid / gradient hatches keep
their existing fast paths. The previous outline-only behaviour was a
visible regression on every layout containing a ruled fill.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 4.7 committed 2026-05-22 06:52:20 +03:00
1 parent c2f3844cb6
commit 30f7ad0918
3 files changed
+285 -24

No files matched your search

+18 -9
View File
@@ -188,15 +188,24 @@ fn draw_hatch(frame: &mut canvas::Frame, hatch: &HatchModel, to_px: &impl Fn(f32
frame.fill(&path, color);
}
HatchPattern::Pattern(_) => {
// Pattern hatches: draw just the boundary outline for now.
frame.stroke(
&path,
canvas::Stroke {
style: canvas::Style::Solid(color),
width: 1.0,
..Default::default()
},
);
// Rasterise the PAT line families clipped to the boundary so
// the paper canvas shows the actual hatch lines (ANSI31, etc.)
// instead of just the outline. Matches the GPU shader output
// for model-space hatches.
for [a, b] in hatch.pattern_segments() {
let seg = canvas::Path::new(|builder| {
builder.move_to(to_px(a[0], a[1]));
builder.line_to(to_px(b[0], b[1]));
});
frame.stroke(
&seg,
canvas::Stroke {
style: canvas::Style::Solid(color),
width: 1.0,
..Default::default()
},
);
}
}
HatchPattern::Gradient { color2, .. } => {
// Gradient: average the two colours as a solid fill.