Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ API in particular should be treated as unstable release to release).

## [Unreleased]

### Fixed

- **Thin strokes on a transparent ground keep their ink (Quality).** A stroke narrower than about two pixels covers few or no pixels completely, so the palette met its anti-aliasing before its ink, or never met the ink at all:
- A 1-1.5 px line split across two rows (every pixel translucent) was dropped entirely. Such a colour, at least half opaque and refused only for having no interior, is now read as a hairline of its opaque version.
- A 2 px diagonal came out as a translucent band around opaque specks, because its 0.83-covered pixels outnumbered its core and were accepted first. After the walk, a translucent ink whose opaque version is also an ink is weighed again as a blend of the two and dropped when it is coverage; a translucent wash with an interior of its own stays.
- A thin face of an opaque ink whose pixels are all partial coverage of the ground is painted its ink, not the ink diluted towards white, so the boundary solve places its edges by coverage instead of widening it.
- `bench/cases` `sawtooth_diag` and `ribbon_w1.5` pass. On all 1386 icons of `bench/alpha_eval.py` 90 traces change and every family's mean error is level or lower (dark ground −0.45 % overall; simple-icons −0.79 %, openmoji −0.45 %, noto-emoji −0.23 %, twemoji −0.20 %). Fast output and the speed of both modes are unchanged.
- **A line too thin to cover a pixel keeps both of its edges (all modes).** Where coverage across a boundary rises from the ground and falls back without reaching 1, the edge was read at the profile's 0.5 crossing, which for such a line is its centre line: a 1 px line between two rows came out half as wide. The edges are now the line's centre (the coverage centroid) plus or minus half its width (the coverage integrated along the normal). Regression gate: dE00 −1.6 % (Quality) and −0.6 % (Fast) at 128 px, level at 512 px. `ribbon_w1` passes.
- **Symmetry the drawing does not have is no longer imposed (all modes).** The label map can be symmetric at pixel resolution while the drawing is not, such as four colours meeting 0.27 px off the image centre. Each symmetry is now enforced only when the refined boundary confirms it: the 90th percentile of the paired points' disagreement must be within 3 standard deviations of their measured positions. Genuine mirrors measure 0.3-1.2 and contradicted ones 7.6-20. In Fast this drops four misleading symmetries out of 84 on a 500-trace sample, improving twemoji 1f7eb 4x and a flag 1.8x.
- **Go: integer remainders are right on arm64 (Apple silicon, Linux arm64).** wazero's arm64 compiler (v1.12.0, the latest) defines a remainder's register twice, a division and then a multiply-subtract, and when register pressure spills it in between, the multiply-subtract reads a quotient that was never stored. Any of the module's 346 remainders could come out wrong; in this release's symmetry pass one became an index of 4294337216 into a 256-point boundary and the trace stopped (the 0.2.7 crash the first half-turn attempt hit was the same bug). The build now rewrites every remainder as `a - div(a, b) * b` (`tools/wasm_wazero_fixes.py`, formerly `wasm_float_select.py`), exactly: same results and same traps on 1323 edge cases, both architectures. `TestWazeroRemainder` reports whether wazero still has the bug (a 40-value module where `1000 rem_u 256` returns 1000).

### Added

- **Half-turn symmetry.** A drawing that is its own 180° rotation about the image centre, and no mirror image, now comes back exactly so (`bench/cases` `mirror_r`, Quality and Fast), through the same pairing, confirmation and averaging as the mirrors.

## [0.2.7] - 2026-10-08

### Fixed
Expand Down
30 changes: 22 additions & 8 deletions HANDOFF.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Why the half-turn was reverted rather than fixed:
* With it, the Go package's test on macOS (wazero, arm64) panicked in `symmetry::enforce`
with an index of 2147484096 into a 256-point edge. The same input traces identically before
and after natively, so this is the runtime miscompiling the new code shape, like the float
`select` bug `tools/wasm_float_select.py` works around on amd64. The revert restores the
`select` bug `tools/wasm_wazero_fixes.py` works around on amd64. The revert restores the
code that passed there.

## Tests
Expand Down Expand Up @@ -73,10 +73,24 @@ Made to run on every CI platform:
`bench/quality_budget.json`: `cases:quality` 38 (37 + `glyph_ring_bar`), `cases:fast` 26
(unchanged). The coverage floors raised in `b267edf` and `test_functions` 1088 stand.

## Open

* `mirror_r`: half-turn symmetry, validated for every mirror against the boundary
uncertainty rather than with a fixed cut-off, and checked under wazero on arm64.
* `sawtooth_diag`: a fix local to thin diagonal strokes, not a global palette reordering.
* `ribbon_w1`, `ribbon_w1.5`: off-grid hairlines on a transparent ground (Quality), which
have no interior at all; Fast keeps them through its paired-pixel scan.
## Since: the open cases closed

On `main` after this handoff, every `bench/cases` case passes in Quality (42/42) and Fast
gains `mirror_r` (27/42):

* `sawtooth_diag`, `ribbon_w1.5`: the native palette reads a hairline as its opaque ink and
drops a translucent ink that is only the coverage of its opaque twin
(`native/palette.rs`), and a thin face of coverage is painted its ink (`native.rs`).
* `ribbon_w1`: the sub-pixel refinement reads a stroke too thin to cover a pixel from its
coverage centroid and width (`planar::ridge_offset`).
* `mirror_r`: the half turn is a symmetry, and every symmetry is enforced only when the
refined boundary confirms it (`symmetry::AGREEMENT_Z`) -- which is what had made the
first half-turn attempt pull `junction_quad`'s junction onto the centre.
* The Go package's macOS crash (above) came back with this code, and is now understood: wazero's
arm64 compiler can compute an integer remainder from a quotient it never stored, which any
remainder in the module could hit, not only this code shape. The build rewrites every
remainder as a division (`tools/wasm_wazero_fixes.py` has the mechanism), and
`TestWazeroRemainder` reports when wazero fixes it. Reproduced and checked on linux/arm64
under QEMU, which runs the same wazero backend as macOS.

See `CHANGELOG.md` `[Unreleased]` for the measurements.
7 changes: 6 additions & 1 deletion bench/quality_budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"junction_quad",
"junction_tri",
"mirror_h",
"mirror_r",
"mirror_v",
"real_single_ink",
"ribbon_w1",
Expand Down Expand Up @@ -54,13 +55,17 @@
"junction_quad",
"junction_tri",
"mirror_h",
"mirror_r",
"mirror_v",
"real_glyph_counters",
"real_single_ink",
"real_symmetry",
"ribbon_w1",
"ribbon_w1.5",
"ribbon_w2",
"ribbon_w3",
"rings_concentric",
"sawtooth_diag",
"square_r1",
"square_r1.5",
"square_r2",
Expand Down Expand Up @@ -97,7 +102,7 @@
"mutation:inkvec-trace/gradient": 67,
"mutation:inkvec-trace/native": 68,
"rustfmt_hunks": 0,
"test_functions": 1088,
"test_functions": 1096,
"untested_modules": [
"crates/inkvec-cli/src/alpha.rs",
"crates/inkvec-cli/src/rings.rs",
Expand Down
104 changes: 52 additions & 52 deletions bindings/contract/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 8930,
"sha256": "61d21e85eb7243faa863d8203ed3effc00dfcdc5651983f8fb6f65d231839327"
},
"x86_64-linux-gnu": {
"bytes": 8942,
"sha256": "29616e966673e2c029037a872df8d74bae22c4d6c8a9b1578d5e7377309abe2b"
"bytes": 8826,
"sha256": "b605367c0ca15ff23f0be08e4ecc5598b8c5e176429c32e597c65fd2428d5c6f"
},
"x86_64-windows-msvc": {
"bytes": 8826,
"sha256": "aaac3e48856448edc19c682a6b5c3544ecc5f704fa3c0c7b331a7f959ae1c749"
}
}
},
Expand All @@ -35,13 +35,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 8930,
"sha256": "61d21e85eb7243faa863d8203ed3effc00dfcdc5651983f8fb6f65d231839327"
},
"x86_64-linux-gnu": {
"bytes": 8942,
"sha256": "29616e966673e2c029037a872df8d74bae22c4d6c8a9b1578d5e7377309abe2b"
"bytes": 8826,
"sha256": "b605367c0ca15ff23f0be08e4ecc5598b8c5e176429c32e597c65fd2428d5c6f"
},
"x86_64-windows-msvc": {
"bytes": 8826,
"sha256": "aaac3e48856448edc19c682a6b5c3544ecc5f704fa3c0c7b331a7f959ae1c749"
}
}
},
Expand All @@ -60,13 +60,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 5866,
"sha256": "34b0959c6bb45accc217e0cc1572c499b23c26db303026464a2acd657f23eabb"
},
"x86_64-linux-gnu": {
"bytes": 5870,
"sha256": "1f97c22656c57bb6dca084184ea2eb63fea8e69945b3acead58aa88aae8385df"
"bytes": 5790,
"sha256": "b6d5c649cee3b9f0d781bc508e457a560bcf55a2b4706656806f21acb5d760e0"
},
"x86_64-windows-msvc": {
"bytes": 5782,
"sha256": "ea544ec4bda9f2c0ff71c6711164c9b88e1dcd3617838f79a58872c157ddd9cd"
}
}
},
Expand All @@ -82,13 +82,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 8950,
"sha256": "d6cad56a7fc9eebcba5ade0124afbf89f08fd59edda98cc233d0359e76a58887"
},
"x86_64-linux-gnu": {
"bytes": 8962,
"sha256": "4277f433de48b8f09703601c9d115ec5dbf5ab5560576fd5e2986ec4c11b07b9"
"bytes": 8846,
"sha256": "6677a9b3711698a52f2cd8d9a892505c595f3f1da32f7a6abb533f6b9470c48b"
},
"x86_64-windows-msvc": {
"bytes": 8846,
"sha256": "e558048b2aac2f534e296f307b8bc2c8cf48093f40da9f38a04a5eccabd786b6"
}
}
},
Expand All @@ -104,13 +104,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 3104,
"sha256": "641dc56a5d8ec53390025675eabd61a919878678d28a4fe69a48a470c0e1f754"
},
"x86_64-linux-gnu": {
"bytes": 3103,
"sha256": "6a2eaa498825ea05c5f50f6bcae54a0aa2d478cc754b1ce2c1c9dfffa9139533"
"bytes": 3303,
"sha256": "61f4dd2b28791294991b26464f896af1ec5a8df0db13adb790833af3b364757f"
},
"x86_64-windows-msvc": {
"bytes": 3303,
"sha256": "1206b5a7806c272325cdf86d6c7de9c2ba1f7d4a14dac9a5d6dee21fc782943d"
}
}
},
Expand All @@ -129,13 +129,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 3104,
"sha256": "641dc56a5d8ec53390025675eabd61a919878678d28a4fe69a48a470c0e1f754"
},
"x86_64-linux-gnu": {
"bytes": 3103,
"sha256": "6a2eaa498825ea05c5f50f6bcae54a0aa2d478cc754b1ce2c1c9dfffa9139533"
"bytes": 3303,
"sha256": "61f4dd2b28791294991b26464f896af1ec5a8df0db13adb790833af3b364757f"
},
"x86_64-windows-msvc": {
"bytes": 3303,
"sha256": "1206b5a7806c272325cdf86d6c7de9c2ba1f7d4a14dac9a5d6dee21fc782943d"
}
}
},
Expand All @@ -152,13 +152,13 @@
"height": 96
},
"svg": {
"x86_64-windows-msvc": {
"bytes": 3120,
"sha256": "6d8b8f685f719c4c9e55c6d8b0b14200e0d05fd56766f162cc8d8caaef4ac1be"
},
"x86_64-linux-gnu": {
"bytes": 3119,
"sha256": "8a91cd20f350687eb32c3f4ffe7365044278be3c0eacf18479abea099865918a"
"bytes": 3319,
"sha256": "1fd4806b93c420c56098142da56f9f8a01fc694964bc30237742ef5b0c330e9c"
},
"x86_64-windows-msvc": {
"bytes": 3319,
"sha256": "62952a5875fb97291e617fa027dc2ac8f5b37ef8669f8aff3af89244fcfbc222"
}
}
},
Expand All @@ -172,11 +172,11 @@
"height": 64
},
"svg": {
"x86_64-windows-msvc": {
"x86_64-linux-gnu": {
"bytes": 679,
"sha256": "cbaf89d8dea3b3715e88d954dac5f99b8d52006cbffc236758a7a91a65f9112b"
},
"x86_64-linux-gnu": {
"x86_64-windows-msvc": {
"bytes": 679,
"sha256": "cbaf89d8dea3b3715e88d954dac5f99b8d52006cbffc236758a7a91a65f9112b"
}
Expand All @@ -195,11 +195,11 @@
"height": 64
},
"svg": {
"x86_64-windows-msvc": {
"x86_64-linux-gnu": {
"bytes": 679,
"sha256": "cbaf89d8dea3b3715e88d954dac5f99b8d52006cbffc236758a7a91a65f9112b"
},
"x86_64-linux-gnu": {
"x86_64-windows-msvc": {
"bytes": 679,
"sha256": "cbaf89d8dea3b3715e88d954dac5f99b8d52006cbffc236758a7a91a65f9112b"
}
Expand All @@ -217,11 +217,11 @@
"height": 64
},
"svg": {
"x86_64-windows-msvc": {
"x86_64-linux-gnu": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
},
"x86_64-linux-gnu": {
"x86_64-windows-msvc": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
}
Expand All @@ -240,11 +240,11 @@
"height": 64
},
"svg": {
"x86_64-windows-msvc": {
"x86_64-linux-gnu": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
},
"x86_64-linux-gnu": {
"x86_64-windows-msvc": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
}
Expand All @@ -266,11 +266,11 @@
"height": 64
},
"svg": {
"x86_64-windows-msvc": {
"x86_64-linux-gnu": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
},
"x86_64-linux-gnu": {
"x86_64-windows-msvc": {
"bytes": 760,
"sha256": "79f85e2ec9adb8b2ea9ba1ab39d108c8872d76e49bf7e7c8c3416fe493dfeb76"
}
Expand Down
9 changes: 9 additions & 0 deletions crates/inkvec-cli/src/mirror_fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub(crate) fn fit(
cfg: &FitConfig,
fit_plain: &dyn Fn(&Polyline) -> FittedPath,
) -> Option<FittedPath> {
// A half turn has no axis to fit one side of; it reaches the fit through the pairing.
let mirrors: Vec<Mirror> = mirrors.iter().copied().filter(|m| m.is_axis()).collect();
let mirrors = mirrors.as_slice();
let &m = mirrors.first()?;
if poly.points.len() < MIN_POINTS {
return None;
Expand Down Expand Up @@ -220,6 +223,8 @@ pub(crate) fn choose(
cfg: &FitConfig,
fit_plain: &dyn Fn(&Polyline) -> FittedPath,
) -> FittedPath {
let mirrors: Vec<Mirror> = mirrors.iter().copied().filter(|m| m.is_axis()).collect();
let mirrors = mirrors.as_slice();
let plain = fit_plain(poly);
if mirrors.is_empty() || mirrors.iter().all(|&m| anchors_mirror(&plain, m)) {
return plain;
Expand Down Expand Up @@ -250,6 +255,7 @@ fn anchors_mirror(path: &FittedPath, m: Mirror) -> bool {
fn axis(m: Mirror) -> f64 {
match m {
Mirror::V(k) | Mirror::H(k) => k as f64 * 0.5,
Mirror::Rot180(..) => unreachable!("`fit` and `choose` keep the axis mirrors only"),
}
}

Expand All @@ -258,6 +264,7 @@ fn onto_axis(p: Point, m: Mirror) -> Point {
match m {
Mirror::V(_) => Point::new(axis(m), p.y),
Mirror::H(_) => Point::new(p.x, axis(m)),
Mirror::Rot180(..) => unreachable!("`fit` and `choose` keep the axis mirrors only"),
}
}

Expand Down Expand Up @@ -574,13 +581,15 @@ fn snap_cubic(part: &FittedPath, m: Mirror, at_end: bool) -> Option<FittedPath>
// The normal to a vertical axis is horizontal: the offset across is in x, along in y.
Mirror::V(_) => (ctrl.x - cross.x, ctrl.y - cross.y),
Mirror::H(_) => (ctrl.y - cross.y, ctrl.x - cross.x),
Mirror::Rot180(..) => return None,
};
if dn.abs() <= 1e-12 || da.atan2(dn.abs()).abs().to_degrees() > SNAP_DEGREES {
return None;
}
let on = match m {
Mirror::V(_) => Point::new(ctrl.x, cross.y),
Mirror::H(_) => Point::new(cross.x, ctrl.y),
Mirror::Rot180(..) => return None,
};
let mut out = part.clone();
out.segments[idx] = if at_end {
Expand Down
2 changes: 1 addition & 1 deletion crates/inkvec-trace/src/color/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) const REP_DE00: f32 = super::SAME_INK_DE00;
///
/// `faces` is the face map, one id per pixel, row-major `w × h`; ids at or above `n_faces`
/// are ignored. One pass, O(w·h). An image narrower or shorter than 3 px has no interior.
fn interior_counts(faces: &[u16], w: usize, h: usize, n_faces: usize) -> Vec<u32> {
pub(crate) fn interior_counts(faces: &[u16], w: usize, h: usize, n_faces: usize) -> Vec<u32> {
let mut count = vec![0u32; n_faces];
if w < 3 || h < 3 || faces.len() < w * h {
return count;
Expand Down
4 changes: 2 additions & 2 deletions crates/inkvec-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ pub(crate) fn finish_color_trace_alpha(
};
// A small map is refined on this thread, after detection, as before: handing it to the
// pool costs more than it saves (see `planar::refine_in_parallel`).
let (sym, refined) = if planar::refine_in_parallel(&map) {
let (mut sym, refined) = if planar::refine_in_parallel(&map) {
rayon::join(|| symmetry::detect(&map, &labels, &face_color), measure)
} else {
(symmetry::detect(&map, &labels, &face_color), measure())
Expand Down Expand Up @@ -1195,7 +1195,7 @@ pub(crate) fn finish_color_trace_alpha(
let symmetrised = if sym.is_empty() {
0
} else {
symmetry::enforce(&mut map, &sym)
symmetry::enforce(&mut map, &mut sym)
};
sw.mark("symmetry");
ColorTrace {
Expand Down
Loading
Loading