Tests: translucent brushed type compares each pixel with full opacity

The test for Crisp and Strong type in a scatter brush stroke at 50% opacity
now checks that every pixel is half of what the same stroke draws at full
opacity. It fails without the coverage fix for Crisp as well as for Strong.
This commit is contained in:
dotCooCoo
2026-11-08 14:05:55 -08:00
parent d8ff63f5d0
commit e3e716c441
+10 -9
View File
@@ -642,13 +642,13 @@ fn type_with_a_brush_stroke_is_drawn_as_sharp() {
}
}
/// Strong and Crisp type in the art of a scatter brush, on an undashed path at 50% opacity, keep
/// that opacity inside the characters: the coverage the method reshapes the edges by is drawn
/// without the path's opacity.
/// Strong and Crisp type in the art of a scatter brush, on an undashed path at 50% opacity, draw
/// every pixel at half of what the same path draws at full opacity: the coverage the method
/// reshapes the edges by is drawn without the path's opacity.
#[test]
fn type_in_a_translucent_scatter_brush_stroke_keeps_its_opacity() {
use vectorcraft_brush::{Brush, BrushKind, Scatter};
let draw = |m: TypeAntiAlias| {
let draw = |m: TypeAntiAlias, opacity: f32| {
let mut d = Document::new(f64::from(W), f64::from(H));
let mut t = TextObject::point(Point::new(0.0, 0.0), "H", CharStyle { size: 40.0, ..Default::default() });
t.anti_alias = m;
@@ -662,18 +662,19 @@ fn type_in_a_translucent_scatter_brush_stroke_keeps_its_opacity() {
}
let line = vectorcraft_geom::shapes::line(Point::new(20.0, 45.0), Point::new(240.0, 45.0));
let mut n = Node::path(d.alloc_id(), line, ap);
n.opacity = 0.5;
n.opacity = opacity;
let l = d.layers[0].id;
d.insert(Some(l), 0, n).unwrap();
alphas(&d, &RenderOptions::default())
};
let most = |a: &[u8]| a.iter().copied().max().unwrap_or(0);
let sharp = draw(TypeAntiAlias::Sharp);
let sharp = draw(TypeAntiAlias::Sharp, 0.5);
assert!((126..=129).contains(&most(&sharp)), "half opaque: {}", most(&sharp));
for m in [TypeAntiAlias::Crisp, TypeAntiAlias::Strong] {
let drawn = draw(m);
assert!((126..=129).contains(&most(&drawn)), "{m:?} keeps the path's opacity: {}", most(&drawn));
assert_ne!(drawn, sharp, "{m:?} changes the edges");
let (half, full) = (draw(m, 0.5), draw(m, 1.0));
assert_ne!(half, sharp, "{m:?} changes the edges");
let off = half.iter().zip(&full).filter(|&(&h, &f)| (2 * i32::from(h) - i32::from(f)).abs() > 6).count();
assert_eq!(off, 0, "{m:?}: pixels not at half of full opacity");
}
}