From fca9f00cd474c43a26f1dcceb629d2a1f1190c1b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 07:10:54 -0800 Subject: [PATCH 1/2] Tests: check the contrast answer for a Difference square in an isolating group a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors only checked that color.contrast returned Ok. It now checks that the answer has a ratio above 1 and a background color, and that the same square in Normal mode gives a different ratio, so a contrast reading that drops the blend mode fails the test. --- crates/engine/src/tests/colorcontrast.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/tests/colorcontrast.rs b/crates/engine/src/tests/colorcontrast.rs index fecd16ed2a..152e48a837 100644 --- a/crates/engine/src/tests/colorcontrast.rs +++ b/crates/engine/src/tests/colorcontrast.rs @@ -1184,7 +1184,14 @@ fn a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors() { s.execute("object.group", &json!({"ids": [back, square]})).unwrap(); s.execute("transparency.set", &json!({"opacity": 50, "isolate": true})).unwrap(); s.execute("select.set", &json!({"ids": [square]})).unwrap(); - s.execute("color.contrast", &json!({})).unwrap(); + let r = s.execute("color.contrast", &json!({})).unwrap(); + let isolated = ratio(&r); + assert!(isolated > 1.0, "{r}"); + assert!(r["against"].as_str().is_some_and(|h| vectorcraft_color::Color::from_hex(h).is_some()), "{r}"); + // The Difference mode is applied: in Normal mode the same square gives another answer. + s.execute("transparency.set", &json!({"blend": "normal"})).unwrap(); + let normal = ratio(&s.execute("color.contrast", &json!({})).unwrap()); + assert!((isolated - normal).abs() > 0.1, "difference {isolated} against normal {normal}"); } /// With a fill of None, what a pick would be measured against is still read: the Color Wheel's From 827f4fc87ebfe78ddbe31024ee3f63d24676539c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 14:10:14 -0800 Subject: [PATCH 2/2] Tests: make isolation change the contrast answer for the grouped Difference square The white square behind the Difference square was opaque, so the art behind the group never reached the blend and the test gave the same answer with isolation off. That square is now 50 % opaque. The test checks that the isolating group gives one answer and that the same group without isolation reports that the art behind the selection is not one color. --- crates/engine/src/tests/colorcontrast.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/tests/colorcontrast.rs b/crates/engine/src/tests/colorcontrast.rs index 152e48a837..2ac70f800d 100644 --- a/crates/engine/src/tests/colorcontrast.rs +++ b/crates/engine/src/tests/colorcontrast.rs @@ -1160,9 +1160,10 @@ fn a_blend_mode_over_art_of_several_colors_has_no_one_answer() { assert!((ratio(&r) - 21.0).abs() < 1e-3, "white minus white is black: {r}"); } -/// A Difference square over a white square in a 50 % group that isolates its blending, over the -/// edge between black and white art: the square blends only with the white inside the group, so +/// A Difference square over a 50 % white square in a 50 % group that isolates its blending, over +/// the edge between black and white art: the square blends only with the white inside the group, so /// the art of two colors outside it, which the group draws over in Normal mode, leaves one answer. +/// Without isolation the blend also reaches that art, and there is no one answer. #[test] fn a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors() { let mut s = session(); @@ -1177,17 +1178,29 @@ fn a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors() { let back = id(s.execute("shape.rectangle", &json!({"x": 60, "y": 60, "width": 80, "height": 80})).unwrap()); s.execute("paint.setFill", &json!({"color": "#ffffff"})).unwrap(); s.execute("paint.setStroke", &json!({"none": true})).unwrap(); + // Translucent, so that a blend that is not isolated also reaches the art behind the group. + s.execute("transparency.set", &json!({"opacity": 50})).unwrap(); let square = id(s.execute("shape.rectangle", &json!({"x": 70, "y": 70, "width": 60, "height": 60})).unwrap()); s.execute("paint.setStroke", &json!({"none": true})).unwrap(); s.execute("paint.setFill", &json!({"color": "#ffffff"})).unwrap(); s.execute("transparency.set", &json!({"blend": "difference"})).unwrap(); - s.execute("object.group", &json!({"ids": [back, square]})).unwrap(); + let group = id(s.execute("object.group", &json!({"ids": [back, square]})).unwrap()); s.execute("transparency.set", &json!({"opacity": 50, "isolate": true})).unwrap(); s.execute("select.set", &json!({"ids": [square]})).unwrap(); let r = s.execute("color.contrast", &json!({})).unwrap(); let isolated = ratio(&r); assert!(isolated > 1.0, "{r}"); assert!(r["against"].as_str().is_some_and(|h| vectorcraft_color::Color::from_hex(h).is_some()), "{r}"); + // Without isolation the square also blends with the black and white art, so there is no one answer. + let set_isolate = |s: &mut Session, on: bool| { + s.execute("select.set", &json!({"ids": [group]})).unwrap(); + s.execute("transparency.set", &json!({"isolate": on})).unwrap(); + s.execute("select.set", &json!({"ids": [square]})).unwrap(); + }; + set_isolate(&mut s, false); + let e = s.execute("color.contrast", &json!({})).unwrap_err().to_string(); + assert!(e.contains("is not one color where it is read"), "{e}"); + set_isolate(&mut s, true); // The Difference mode is applied: in Normal mode the same square gives another answer. s.execute("transparency.set", &json!({"blend": "normal"})).unwrap(); let normal = ratio(&s.execute("color.contrast", &json!({})).unwrap());