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.
This commit is contained in:
dotCooCoo committed 2026-12-01 14:10:14 -08:00
1 parent 9c7777372a
commit 827f4fc87e
1 file changed
+16 -3
+16 -3
View File
@@ -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());