test(paint): pin the retouch dab footprint to the Full Size ring (#1761) (#3258)

A dab never paints past radius + 0.5 px from its centre, at any hardness:
the half pixel is the anti-aliased edge of dab_coverage. A hard tip does
reach the ring; softer tips fade out inside it, which is the falloff
working as intended.
This commit is contained in:
Gert Pellin - GPE
2026-10-11 20:02:35 -04:00
committed by GitHub
parent 599aea0086
commit 5a907b110e
+36
View File
@@ -423,6 +423,7 @@ fn premultiply(px: &mut [f32], alpha: Option<usize>) {
mod tests {
use super::*;
use crate::{BrushSettings, StrokePoint};
use photocraft_geom::Point;
fn stroke(points: &[(f64, f64)], size: f32, hardness: f32) -> Stroke {
Stroke {
@@ -551,4 +552,39 @@ mod tests {
mix_premultiplied(&mut d, &[1.0, 1.0], 7, 0.5);
assert_eq!(d, [0.5, 0.5]);
}
#[test]
fn footprint_stays_inside_the_full_size_ring() {
let radius = 10.5f32;
for hardness in [1.0, 0.5, 0.0] {
let dab = Dab::round(Point::new(32.0, 32.0), radius, 1.0);
let fp = footprint(&dab, 0, hardness);
let mut painted = 0usize;
let mut farthest = 0.0f64;
for y in fp.rect.y0..fp.rect.y1 {
for x in fp.rect.x0..fp.rect.x1 {
let dist = ((x as f64 + 0.5 - dab.center.x).powi(2) + (y as f64 + 0.5 - dab.center.y).powi(2)).sqrt();
if fp.at(x, y) <= 0.0 {
continue;
}
painted += 1;
farthest = farthest.max(dist);
assert!(
dist < radius as f64 + 0.5,
"hardness {hardness}: pixel ({x}, {y}) at {dist} px from \
the centre is painted past the Full Size ring of \
{radius} px"
);
}
}
assert!(painted > 0, "hardness {hardness}: nothing painted");
if hardness == 1.0 {
assert!(
farthest > radius as f64,
"a hard tip painted only {farthest} px out, so the Full \
Size ring at {radius} px is never reached"
);
}
}
}
}