Skip to content

Close the last bench cases: thin strokes on transparency, thin-stroke edges, half-turn symmetry - #28

Merged
Stefatorus merged 6 commits into
mainfrom
claude/vibrant-cerf-gfxg8x
Oct 9, 2026
Merged

Stefatorus merged 6 commits into
mainfrom
claude/vibrant-cerf-gfxg8x

Conversation

@Stefatorus

@Stefatorus Stefatorus commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

What changed

With these commits every bench/cases case passes in Quality (38 → 42), and Fast gains mirror_r (26 → 27). Each commit message has the full measurements.

1. native: thin strokes on a transparent ground keep their opaque ink (Quality only). Fixes sawtooth_diag and ribbon_w1.5.

  • Hairline: a 1–1.5 px line split across two rows has no fully covered pixel, so every colour in it was refused for having no interior and the line vanished. A colour refused only for that, and at least half opaque, is now weighed as its opaque version, through every gate.
  • Twin coverage: a 2 px diagonal's 0.83-coverage pixels outnumbered its core and were accepted first, so the stroke split into a translucent band plus opaque specks. After the walk, a translucent ink whose opaque version is also an ink is weighed again with every other ink in place, and dropped when the blend tests call it coverage. Accepting the opaque version early was tried instead and cost noto-emoji +0.45 %.
  • Thin faces: a face of an opaque ink with no interior pixel, where every pixel reads as partial coverage of the transparent background, is painted its ink rather than the ink diluted toward white.

2. planar: a stroke too thin to cover a pixel is read from its width and centre (all modes). Fixes ribbon_w1. When the coverage profile across a vertex rises from the ground and falls back without reaching 0.97, the edges are now the coverage centroid ± half the integrated coverage. Before, the edge was taken at the 0.5 crossing, which for such a stroke is its centre line.

3. symmetry: the half turn, and every symmetry confirmed by the refined boundary (all modes). Fixes mirror_r. The 0.08 px cut-off the reverted attempt needed is replaced by a measured test:

  • A symmetry the label map shows is enforced only if the 90th percentile of its paired points' disagreement, in standard deviations of their measured positions, is at most 3.
  • Genuine symmetries measure 0.3–1.2. junction_quad, which is symmetric only at pixel resolution, measures 7.6–8.2.
  • On 500 corpus traces, no Quality mirror is dropped. Fast drops 4 of 84, and dropping them improves two of those traces 1.8–4×.

4. Go: integer remainders rewritten as divisions, around a wazero arm64 compiler bug. The Go macOS job panicked in the symmetry pass (index 4294337216 into a 256-point boundary), as the first half-turn attempt had in 0.2.7. It is wazero's arm64 compiler (v1.12.0, the latest), not the tracer:

  • wazero lowers a remainder to udiv rd → division-by-zero exit → msub rd, rd, …, defining rd twice. When register pressure spills rd between the two, the spill is stored after the msub, so the msub reloads a quotient that was never stored. A 40-value module reproduces it: 1000 rem_u 256 returns 1000. Any of the module's 346 remainders could hit it.
  • tools/wasm_float_select.py becomes tools/wasm_wazero_fixes.py and also rewrites every remainder exactly (a - div(a, b) * b; for rem_s a divisor of −1 becomes 1, so rem_s(MIN, -1) stays 0 instead of trapping).
  • TestWazeroRemainder reports whether wazero still has the bug, like TestWazeroFloatSelect for the amd64 one.

Contract hashes: the seven tiny_* cases change with the ridge reading (2). The x86_64-linux-gnu hashes were re-recorded locally. The x86_64-windows-msvc ones come unchanged from CI's facade (windows-latest) artifact; the clear_* cases' Windows hashes equal main's.

How verified

  • cargo test passes locally for inkvec-trace and inkvec-cli, including 9 new tests. Each new test of a rule fails with that rule disabled; checked for the twin rule and the ridge rule.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets (-D clippy::correctness -D clippy::suspicious), RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps and cargo +1.88 check --workspace are clean. bench/quality.py passes: no new lint warnings, test_functions 1088 → 1096.
  • The regression gate passes, run locally on each step (--no-tighten). The baseline is from v0.2.4, so all builds show large gains against it. The steps compared with each other:
    • ridge rule: dE00 −1.6 % (Quality) and −0.6 % (Fast) at 128 px, level at 512 px;
    • symmetry change: Quality within ±0.1 %, Fast dE00 −0.21 % at 128 px.
  • Output that should not change: Fast is byte-identical through commit 1 (Quality-only). Speed is unchanged through the whole series (28 icons at 512 px: Fast 18.8 → 18.5 ms, Quality 544 → 546 ms).
  • Native-alpha corpus (bench/alpha_eval.py, all 1,386 icons) for commit 1: 90 traces change, and every family is level or better (dark ground −0.45 % overall).
  • wazero fix: the crash reproduced locally on linux/arm64 under QEMU (the same wazero backend as macOS) and is gone after; the full Go suite passes there and on amd64. On 1,323 edge cases the original and rewritten modules give the same results and traps, in wazero's interpreter and compiler on both architectures. Go module speed on amd64: Fast +1.9 %, Quality −1.1 % (noise), traces byte-identical.
  • docs/THIRD_PARTY.md: no dependency changes.
  • CHANGELOG.md updated under Unreleased.

🤖 Generated with Claude Code

https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry

claude added 4 commits October 9, 2026 20:53
…uality)

The native-alpha palette walks colours by pixel count, and a stroke under about two pixels
wide has more partly covered pixels than covered ones, or none covered at all:

- Hairline (ribbon_w1, ribbon_w1.5): every pixel of a 1-1.5 px line split across two rows
  is translucent with no interior, each was refused, and the line vanished. A candidate
  refused only for that, at least HAIRLINE_MIN_ALPHA (0.5) opaque, is now weighed as its
  opaque version (opaque_version: the straight colour, s = (W - (1 - a)) / a), through
  every gate.
- Twin coverage (sawtooth_diag): the 0.83-covered pixels of a 2 px diagonal came first,
  passed with an interior borrowed from the core they claimed, and the core followed as a
  second ink. After the walk, a translucent ink whose opaque version is an accepted
  opaque ink is weighed again with every other ink in place and dropped when the blend
  tests call it coverage (drop_twin_coverage). Accepting the opaque version early instead
  was tried and promoted rejected blend greys on noto-emoji (+0.45 %).
- Thin faces: a flat face of an opaque ink with no interior pixel, whose pixels read as
  that ink partly covering the clear ground (1 + a(k - 1) over white, per pixel), is
  painted its ink instead of the ink diluted towards white, which the boundary solve
  had widened to match (paint_thin_faces_their_ink). An opaque tint on the same line is
  told apart by its alpha.

The per-pixel reference walk mirrors both palette rules. The 1 px column at 0.5 in the
old hairline test sat exactly on the new threshold; it is restated at 0.6 (now an opaque
ink) and 0.3 (still dropped).

Measured against main (1b13418):
- bench/cases Quality 38 -> 40 (sawtooth_diag, ribbon_w1.5); Fast unchanged at 26.
- bench/alpha_eval.py, all 1386 icons: 90 traces change, 44 better and 46 worse, every
  family level or better (dark -0.45 % overall; simple-icons -0.79 %, openmoji -0.45 %,
  noto-emoji -0.23 %, twemoji -0.20 %, material-icons -0.08 %, lucide 0).
- Fast output byte-identical on 28 corpus icons at 512 px, 19.6 -> 19.3 ms; Quality
  580.6 -> 582.7 ms. Binding contract output unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry
… centre

A stroke narrower than about a pixel and a half cuts every pixel it touches with both of
its edges, so its coverage never reaches 1: a 1 px line between two rows reads 0.62 / 0.38.
The refinement read each edge at the profile's 0.5 crossing, which for such a line lies on
its centre line, and bench/cases ribbon_w1 came out half as wide (the boundary solve could
not recover it: it stalled at its 64-iteration cap). When the coverage across a vertex
starts and ends on the ground over +-2.5 px, has one peak below 0.97, and both faces are
flat, the edge is now the stroke's centre (the coverage centroid) plus or minus half its
width (coverage integrated along the normal, W = integral of a ds), on the vertex's own
side (ridge_offset). Every other vertex is read as before.

Measured against the build before it (the native palette commit):
- bench/cases: Quality 40 -> 41 (ribbon_w1); Fast's 26 unchanged.
- Regression gate, all six conditions, PASSED. dE00 quality-128ss -1.6 %, fast-128ss
  -0.6 %, level at 512 px (opaque too); parameters +0.2-0.4 % in Quality, -0.6-1.0 % in
  Fast; Fast turning -0.7-0.9 %.
- Speed unchanged (28 corpus icons at 512 px).
- New test: a 1 px line split 0.62 / 0.38 keeps both edges within 0.02 px (fails without
  the rule: top edge 4.806 for 4.88).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry
…boundary

The label map can be symmetric at pixel resolution while the drawing is not. Four colours
meeting 0.27 px off the image centre (bench/cases junction_quad) leave a label map that is
exactly its own half turn, and averaging the boundary with its image pulled the junction
onto the centre; that is why the half turn of 206a1dd needed a 0.08 px cut-off. Before a
symmetry is enforced now, the 90th percentile of its paired points' disagreement, in
standard deviations of their measured positions, must be at most AGREEMENT_Z (3);
otherwise it is dropped and its fits are not reflected either. This applies to the two
mirrors as well as to the half turn, which is detected when neither mirror holds.
mirror_fit (one side of an axis, reflected) keeps to axis mirrors.

Measured:
- bench/cases: Quality 41 -> 42 (mirror_r; junction_quad still passes), Fast 26 -> 27
  (mirror_r).
- Disagreement on the cases: symmetric figures 0.3-1.2 sd (0.03-0.09 px), junction_quad
  7.6-8.2 sd (0.54-0.58 px). On 500 corpus traces (5 families, 128 and 512 px, both
  modes): every Quality mirror at most 0.96 sd, none dropped. Fast drops 4 of 84; scored
  against the artist's file, dropping them improves twemoji 1f7eb 4x and the 1f1f2-1f1fb
  flag 1.8x and costs 271d 11 % of a 1e-4 error.
- Regression gate PASSED: against the build before it, Quality within +-0.1 %, Fast dE00
  -0.21 % at 128 px.
- Speed unchanged: Fast 18.8 -> 18.5 ms, Quality 544 -> 546 ms per 512 px icon.
- Tests: the half turn is found only when neither mirror holds; a symmetry contradicted
  by half a pixel at 0.05 px uncertainty is dropped and nothing moves; paths and
  primitives map onto their half-turn images.

The 0.2.7 crash this code shape once hit (wazero on macOS arm64, index out of bounds in
enforce) is to be checked by the Go job on this PR; it does not reproduce on x86-64.

bench/quality_budget.json: cases:quality 42, cases:fast 27, test_functions 1096.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry
…dges

The ridge reading (planar::ridge_offset) moves edges of the opaque tiny.png contract input,
so its seven cases trace to new SVGs; the white_on_clear cases are unchanged. Re-recorded
with `INKVEC_BLESS=1 cargo test -p inkvec --release --test contract`, which drops the other
targets' hashes; until the Windows ones are added from the facade job's artifact, Windows
is checked on everything but the exact bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry

Copy link
Copy Markdown
Member Author

CI status on 5037e79:

  • docker / build (linux/amd64) and run the HTTP contract failed before any build step ran: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 504 Gateway Timeout. That is Docker Hub's auth service, not this change (no Dockerfile or server code touched). I could not re-run it (403 for this integration); it re-runs with the next push, or a maintainer can re-run the failed job.
  • The red checks on the previous head c6cbdba (facade, wheel, C library, Swift system library, quality ratchet) were all the seven tiny_* contract hashes, which the thin-stroke edge reading changes on purpose; their "got" values are the hashes 5037e79 records for x86_64-linux-gnu. The x86_64-windows-msvc hashes will be added back from this run's facade (windows-latest) artifact.

Generated by Claude Code

claude added 2 commits October 9, 2026 22:33
…-stroke edges

Taken unchanged from the facade (windows-latest) job's INKVEC_BLESS=add artifact on 5037e79
(run 37995567892): 48 lines added, nothing else differs from the committed file. The
white_on_clear cases' Windows hashes equal the ones before this change, as their output
did not change; the tiny.png cases' are new, as on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry
…compiler bug

The Go package's macOS test panicked in the symmetry pass: an index of 4294337216 into a
256-point boundary, from `(shift + i) % n`. It is wazero's arm64 compiler (v1.12.0, the
latest), not the tracer: wazero's interpreter traces the same module correctly, and so does
its amd64 compiler. wazero lowers a remainder to `udiv rd, rn, rm`, a branch to the
division-by-zero exit, and `msub rd, rd, rm, rn`, defining rd twice. Its register allocator
stores a spilled value after the value's (last) defining instruction, so when the exit
path's temporary forces rd out between the two, msub reloads a quotient that was never
stored. A 40-value module reproduces it: `1000 rem_u 256` returns 1000. Any of the module's
346 remainders could hit it, so this is not specific to the new code (the 0.2.7 crash of
the first half-turn attempt was the same bug).

tools/wasm_float_select.py becomes tools/wasm_wazero_fixes.py and also rewrites every
remainder exactly: rem_u(a, b) -> a - div_u(a, b) * b, and rem_s with a divisor of -1
replaced by 1, which keeps rem_s(MIN, -1) = 0 where div_s would trap.

Checked:
- Reproduced and fixed on linux/arm64 under QEMU (the same wazero backend as macOS):
  TestWhiteDiscOnTransparent panicked before and passes after; the full Go suite passes on
  amd64.
- The rewrite is exact: on 1323 edge cases (MIN, MAX, -1, 0 divisors, i32 and i64) the
  original and rewritten modules give the same results and the same traps, in wazero's
  interpreter and compiler, amd64 and arm64. 12 corpus icons trace byte-identically.
- Speed: Fast 41.0 -> 41.8 ms/icon on amd64, measured interleaved while another job held
  1.5 of 4 cores.
- TestWazeroRemainder reports whether wazero still has the bug (it does on arm64, not on
  amd64), like TestWazeroFloatSelect for the amd64 select bug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013vmThm51KN5odxUsbS6Zry
@Stefatorus
Stefatorus merged commit 75801bf into main Oct 9, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants