Show the result of combining selected shape layers

This commit is contained in:
yoriswind committed 2026-11-30 13:08:45 -08:00
1 parent 1553cd3c9e
commit b008b6cc68
3 files changed
+40

No files matched your search

@@ -0,0 +1,33 @@
use photocraft_doc::LayerId;
use serde_json::json;
use super::{alpha_sum, doc, shape, two_selected_rects};
#[test]
fn combining_shapes_shows_the_result_and_undo_restores_visibility() {
for (command, expected_area) in [
("layer.combineShapes.unite", 2800.0),
("layer.combineShapes.subtractFrontShape", 1200.0),
("layer.combineShapes.intersectShapeAreas", 400.0),
("layer.combineShapes.excludeOverlappingShapes", 2400.0),
] {
for hide_top in [true, false] {
let (mut session, lower, top) = two_selected_rects(8);
let hidden = if hide_top { top } else { lower };
session.execute("layer.setProps", json!({"layer": hidden, "visible": false})).unwrap();
session.execute("layer.select", json!({"layers": [lower, top]})).unwrap();
let before = doc(&session).clone();
let history = session.active().unwrap().history.past_len();
let result = session.execute(command, json!({})).unwrap();
assert_eq!(result["layer"], top);
assert!(doc(&session).layer(LayerId(top)).unwrap().visible, "{command} with {hidden} hidden");
assert!(doc(&session).layer(LayerId(lower)).is_none());
assert!((alpha_sum(&shape(&session, top)) - expected_area).abs() < 2.0, "{command} still includes both shapes");
assert_eq!(session.active().unwrap().history.past_len(), history + 1);
session.execute("edit.undo", json!({})).unwrap();
assert_eq!(*doc(&session), before, "{command}: undo restores the original layers and visibility");
}
}
}
@@ -903,6 +903,10 @@ fn merge_shape_layers(s: &mut Session, ids: &[LayerId], op: Option<PathOp>, labe
vector::flatten::validate_shape(&merged.path, merged.stroke.as_ref()).map_err(|e| bad(label, e))?;
refresh_shape(&snapshot, &mut merged);
*sh = merged;
// The four Combine Shapes operations show their result even if the top layer was hidden.
if op.is_some() {
l.visible = true;
}
for id in ids.iter().filter(|id| **id != keep) {
doc.remove(*id);
}
@@ -2,6 +2,9 @@ use serde_json::json;
use super::*;
#[path = "combine_shapes_hidden_top_layer_tests.rs"]
mod combine_shapes_hidden_top_layer_tests;
#[test]
fn stroke_validation_rejects_hostile_values_without_editing_history() {
let mut s = session(100, 80, 8);