Brush tests: seams, hard edge, zero scatter and ABR tip colour (#213) (#1221)

* Brush tests: seams, hard edge, zero scatter and ABR tip colour (#213)

Adds the four TOOL-213-13 regressions: minimum coverage inside a stroke
(spacing 0.1/0.25/0.5), a hardness-1 rim measured against a soft falloff,
dabs staying on the path at zero scatter, and an imported ABR tip painting
the brush colour instead of black. Scorecard row flipped to done.

* Contributors: add Reynold Hu to people.toml

Real name credited, display name synced from the public GitHub profile at the
next contributors.py refresh (every field is opt-in).

* Regenerate docs/scorecard.md after rebase onto main

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Brandon Thomas <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-08 18:28:12 -04:00
1 parent da86700693
commit 5a97ee30f3
5 files changed
+91 -4

No files matched your search

+4
View File
@@ -26,3 +26,7 @@ sync_github_name = false
real_name = "Gert Pellin"
display_name = "Gert Pellin"
sync_github_name = false
[people.reynold-hu]
real_name = "Reynold Hu"
sync_github_name = true
+33
View File
@@ -277,3 +277,36 @@ fn garbage_is_an_error() {
assert!(read_abr(b"8BPS not a brush", "g").is_err());
assert!(read_abr(&[0, 6, 0, 2], "g").is_err());
}
#[test]
fn sampled_tip_paints_the_brush_colour_never_black() {
// An imported tip is coverage: its pixels decide where paint lands, never what colour.
// A black tip pixel must mean "no paint", and a painted pixel must carry the brush colour,
// so a regression that treats the tip bitmap as RGB shows up here as black output.
use photocraft_color::PixelFormat;
use photocraft_paint::StrokePoint;
use photocraft_paint::render::render_stroke;
use photocraft_raster::Surface;
let preset = Descriptor::new("brushPreset").with("Nm ", t("Tip")).with("Brsh", Value::Descriptor(sampled_tip("$tip-1")));
let bytes = write_v6(2, &[sample("$tip-1", 8, 8, 8)], &[], &[preset], false).unwrap();
let imp = read_abr(&bytes, "Test").unwrap();
let mut b = imp.presets[0].brush.clone();
b.pressure_size = false;
b.color = [0.8, 0.1, 0.1, 1.0];
let mut s = Surface::new(PixelFormat::RGBA32F);
render_stroke(&mut s, &b, &[StrokePoint::new(30.0, 32.5, 1.0), StrokePoint::new(34.0, 32.5, 1.0)], None, false, 1.0);
let mut painted = 0;
for y in 0..64 {
for x in 0..64 {
let p = s.rgba(x, y);
if p[3] > 0.5 {
painted += 1;
assert!((p[0] - 0.8).abs() < 0.05 && (p[1] - 0.1).abs() < 0.05, "not the brush colour at ({x},{y}): {p:?}");
}
}
}
// The helper writes an alternating 255/0 tip, so both painted and unpainted pixels exist.
assert!(painted > 0, "the imported tip painted nothing");
assert!(painted < 64 * 64, "the tip covered everything - coverage was treated as solid colour");
}
+50
View File
@@ -93,6 +93,25 @@ fn hardness_profile_is_monotonic() {
}
}
#[test]
fn hard_edge_is_sharp() {
// A hardness of 1 is a steep rim: fully opaque inside the nominal radius, empty just past
// it, with only the anti-aliasing band in between.
let b = BrushSettings { hardness: 1.0, ..brush() };
let r = raster(&b, &Dab::round(Point::new(50.0, 50.0), 20.0, 1.0));
let prof: Vec<f32> = (0..22).map(|i| at(&r, 50 + i, 50)).collect();
let band = prof.iter().filter(|&&a| (0.01..0.99).contains(&a)).count();
assert!(band <= 3, "hardness 1 rim is {band} px wide: {prof:?}");
assert!(prof[17] > 0.99, "translucent inside the rim: {prof:?}");
assert_eq!(*prof.last().unwrap(), 0.0);
// A soft tip spreads the same crossing over many pixels instead.
let soft = BrushSettings { hardness: 0.0, ..brush() };
let rs = raster(&soft, &Dab::round(Point::new(50.0, 50.0), 20.0, 1.0));
let profs: Vec<f32> = (0..22).map(|i| at(&rs, 50 + i, 50)).collect();
let soft_band = profs.iter().filter(|&&a| (0.01..0.99).contains(&a)).count();
assert!(soft_band >= 10, "soft rim is only {soft_band} px: {profs:?}");
}
#[test]
fn sampled_tip_is_scaled_and_oriented() {
// Tip: left half painted.
@@ -182,6 +201,22 @@ fn spacing_sets_dab_count() {
assert!(d.windows(2).all(|w| ((w[1].center.x - w[0].center.x) - 10.0).abs() < 1e-6));
}
#[test]
fn stroke_has_no_seams() {
// Overlapping dabs must fuse into one solid band: a seam is a periodic gap or a darker
// join, so the minimum coverage inside the stroke stays at the opacity.
for spacing in [0.1f32, 0.25, 0.5] {
let b = BrushSettings { spacing, size: 20.0, ..brush() };
let s = paint(&b, &line(20.0, 180.0, 100.5), 200, 200);
for y in 98..=102 {
for x in 40..=160 {
let a = s.rgba(x, y)[3];
assert!(a > 0.99, "spacing {spacing} seam at ({x},{y}): {a}");
}
}
}
}
// ---------- dynamics ----------
#[test]
@@ -318,6 +353,21 @@ fn scattering_stays_in_bounds() {
}
}
#[test]
fn zero_scatter_keeps_dabs_on_the_stroke() {
// Scatter at 0 % must not move a dab, even with the section switched on.
let on = BrushSettings { scattering: Scattering { enabled: true, ..Default::default() }, ..brush() };
for b in [brush(), on] {
let d = dabs_of(&b, &line(10.0, 90.0, 40.5));
assert!(d.len() > 4);
assert!(
d.iter().all(|x| (x.center.y - 40.5).abs() < 1e-9),
"scatter moved dabs off the stroke: {:?}",
d.iter().map(|x| x.center.y).collect::<Vec<_>>()
);
}
}
#[test]
fn color_dynamics_ranges() {
let base = BrushSettings { color: [1.0, 0.0, 0.0, 1.0], background: [0.0, 0.0, 1.0, 1.0], seed: 5, ..brush() };
+2 -2
View File
@@ -8,7 +8,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
|---|---:|---:|---:|---|
| [Performance](#performance) | 3 | 22 | 13 | 47 scenarios: 3 within budget, 22 over budget or failing, 15 tracked only, 6 not run, 7 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 4 | 10 | 13 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 229/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 6 | 15 | 9 | |
| [Tools](#tools) | 7 | 14 | 9 | |
| [Workspace and UI](#workspace-and-ui) | 0 | 5 | 18 | settings that do nothing: 57 of 139 (target 0) |
| [Type](#type) | 0 | 3 | 6 | |
| [Automation](#automation) | 3 | 2 | 6 | 627 of 627 menu items live (100.0%) |
@@ -133,7 +133,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
| TOOL-213-10 | Ctrl+Alt drag resizes brush size/hardness with an on-canvas readout | missing | [#213](https://github.com/storytold/photocraft/issues/213) | Only [ ] resize (shortcuts.rs:270) |
| TOOL-213-11 | Editable pressure curve, global and per control | missing | [#213](https://github.com/storytold/photocraft/issues/213) | No pressure curve in engine, paint or ui-egui |
| TOOL-213-12 | Import an image file as a brush tip | missing | [#213](https://github.com/storytold/photocraft/issues/213) | Only brush.defineFromSelection and brush.presets.importAbr |
| TOOL-213-13 | Brush regression tests: no seams, hard edge, zero-scatter defaults, ABR never black | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Missing-pattern ABR test (abr_map/tests.rs:181), hardness test; no seam/black tests |
| TOOL-213-13 | Brush regression tests: no seams, hard edge, zero-scatter defaults, ABR never black | done | [#213](https://github.com/storytold/photocraft/issues/213) | Seam, hard-edge and zero-scatter tests in brush_tests.rs; ABR tip colour test in abr_map/tests.rs |
| TOOL-213-14 | Tablet: no OS arrow cursor over the canvas on macOS, Windows and Linux | partial | [#213](https://github.com/storytold/photocraft/issues/213) | Brush tools set CursorIcon::None (canvas.rs:1259-1275); not verified per OS |
| TOOL-214-1 | Select and Mask workspace: view modes, Refine Edge brush, 6 outputs | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Opens the generic select.refineEdge dialog (menus.rs:308) |
| TOOL-214-2 | Marquee: Shift square, Alt from centre, live W x H readout | partial | [#214](https://github.com/storytold/photocraft/issues/214) | marquee_end supports shift (chrome_ui.rs:167) but canvas.rs passes false (#208) |
+2 -2
View File
@@ -92,9 +92,9 @@ note = "Only brush.defineFromSelection and brush.presets.importAbr"
[[item]]
id = "TOOL-213-13"
target = "Brush regression tests: no seams, hard edge, zero-scatter defaults, ABR never black"
status = "partial"
status = "done"
issue = 213
note = "Missing-pattern ABR test (abr_map/tests.rs:181), hardness test; no seam/black tests"
note = "Seam, hard-edge and zero-scatter tests in brush_tests.rs; ABR tip colour test in abr_map/tests.rs"
[[item]]
id = "TOOL-213-14"