Merge pull request #10442 from dotCooCoo/fix/engine-test-tolerances

Tests: engine assertions check the exact drag offset, dither shares and colors
This commit is contained in:
.CooCoo
2026-12-01 07:20:16 -08:00
committed by GitHub
4 changed files with 12 additions and 4 deletions
@@ -120,6 +120,10 @@ fn palette_exports_take_the_transparency_dither() {
let dithered = file(json!({"transparencyDither": method}));
let [left, right] = opaque_halves(&dithered);
assert!((left - 0.25).abs() < 0.1 && (right - 0.75).abs() < 0.1, "{format} {method}: {left} {right}");
if method == "pattern" {
// The ordered pattern keeps exactly one pixel of each 2x2 cell at 25% and three at 75%.
assert_eq!([left, right], [0.25, 0.75], "{format}");
}
assert_eq!(file(json!({"transparencyDither": method})), dithered, "{format} {method}: the same art gives the same file");
// Without transparency the dither does nothing.
let opaque = file(json!({"transparencyDither": method, "transparency": false}));
+1 -1
View File
@@ -435,7 +435,7 @@ fn alt_drag_of_30000_objects_takes_few_tree_walks() {
assert_eq!(s.doc().unwrap().history.undo.last().map(|e| e.label.as_str()), Some("Copy"));
// The squares stay; their copies move together.
let moved = bounds(&s, copies[0]).origin() - square_at(0).origin();
assert!(moved.x > 0.0, "{moved:?}");
assert!((moved.x - 80.0).abs() < 1e-6 && moved.y.abs() < 1e-6, "the copies move by the drag: {moved:?}");
for (k, (id, copy)) in ids.iter().zip(&copies).enumerate() {
assert_eq!(bounds(&s, *id), square_at(k));
assert_eq!(bounds(&s, *copy), square_at(k) + moved);
+3 -3
View File
@@ -1545,10 +1545,10 @@ fn kept_art_follows_the_swatches_once_a_replaced_plugin_paints() {
assert_eq!(draw(&s), (WHITE, RED), "without the swatch, the object as it is");
}
/// Whether `px` is within 40 levels of `want` on every channel. A blur leaves the middle of a
/// shape close to its color.
/// Whether `px` is within 2 levels of `want` on every channel. The samples sit well inside their
/// shapes, so a blur changes them only by rounding.
fn near(px: [u8; 4], want: [u8; 4]) -> bool {
px.iter().zip(want).all(|(a, b)| a.abs_diff(b) <= 40)
px.iter().zip(want).all(|(a, b)| a.abs_diff(b) <= 2)
}
/// A kept raster of a blur over a painted effect is made again when a swatch its piece names
+4
View File
@@ -197,6 +197,10 @@ fn transparency_dither_keeps_a_share_of_partly_transparent_pixels() {
let dithered = file(&mut s, p.clone());
let [left, right] = opaque_halves(&pixels(&dithered));
assert!((left - 0.25).abs() < 0.1 && (right - 0.75).abs() < 0.1, "{format} {method}: {left} {right}");
if method == "pattern" {
// The ordered pattern keeps exactly one pixel of each 2x2 cell at 25% and three at 75%.
assert_eq!([left, right], [0.25, 0.75], "{format}");
}
if format == "gif" {
assert_eq!(gif_transparent_index(&dithered), Some(0), "{method}");
}