From ab141cfa109e704b7c3b7dbf96fa88a8bf0824f0 Mon Sep 17 00:00:00 2001 From: Sven Lafebre Date: Mon, 16 Nov 2026 13:45:59 +0100 Subject: [PATCH] Fix #8093: members of a clipping path that clips by nothing are hidden A clip group whose clipping path clips by nothing (an empty group) hides its members on the canvas, but Pathfinder skipped the group altogether, so Intersect gave the other objects' overlap. Its members now get an empty region and count as hidden like any other masked art. --- crates/engine/src/cmd/pathops.rs | 10 +++++---- crates/engine/src/tests/pathfinder_clip.rs | 26 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/cmd/pathops.rs b/crates/engine/src/cmd/pathops.rs index b98e49f512..70de82fa65 100644 --- a/crates/engine/src/cmd/pathops.rs +++ b/crates/engine/src/cmd/pathops.rs @@ -370,7 +370,7 @@ type ClippedLeaf = (Node, Option>); /// [`pf_leaves`], each with the region the clip groups it is in show it through (#8093). A clip /// group's clipping path is not a leaf, and the members of one whose clipping path clips by nothing -/// are hidden, as on the canvas, and left out. +/// are hidden, as on the canvas: their region is empty. fn clipped_pf_leaves(d: &Document, n: &Node, clip: Option<&Arc>, precision: f64, out: &mut Vec) -> Result<()> { let (NodeKind::Group { children, clip: clips } | NodeKind::Layer { children, clip: clips, .. }) = &n.kind else { let mut lv = vec![]; @@ -387,12 +387,14 @@ fn clipped_pf_leaves(d: &Document, n: &Node, clip: Option<&Arc>, precision return children.iter().try_for_each(|c| clipped_pf_leaves(d, c, clip, precision, out)); } let Some((first, rest)) = children.split_first() else { return Ok(()) }; - let Some((outline, rule)) = vectorcraft_render::effects::clip_outline(first) else { return Ok(()) }; - let mut region = Clip { path: PathData::from_bezpath(&outline), rule }; + let mut region = match vectorcraft_render::effects::clip_outline(first) { + Some((outline, rule)) => Clip { path: PathData::from_bezpath(&outline), rule }, + None => Clip { path: PathData::default(), rule: FillRule::NonZero }, + }; if has_invalid_coordinates(®ion.path) { return Err(EngineError::Other("paths contain invalid coordinates".into())); } - if let Some(outer) = clip { + if let Some(outer) = clip.filter(|_| !region.path.is_empty()) { let path = po::try_boolean(®ion.path, region.rule, &outer.path, outer.rule, BoolOp::Intersect, precision) .map_err(|e| EngineError::Other(e.to_string()))?; region = Clip { path, rule: FillRule::NonZero }; diff --git a/crates/engine/src/tests/pathfinder_clip.rs b/crates/engine/src/tests/pathfinder_clip.rs index 69cccbea38..5091b7db80 100644 --- a/crates/engine/src/tests/pathfinder_clip.rs +++ b/crates/engine/src/tests/pathfinder_clip.rs @@ -283,3 +283,29 @@ fn a_hidden_operand_is_an_empty_shape_where_it_changes_the_result() { assert!(ps.iter().all(|p| p.0 != Paint::solid(green())), "{op}: the hidden group's style: {ps:?}"); } } + +/// A clip group whose clipping path clips by nothing (here an empty group) hides its members, as on +/// the canvas: they are a hidden operand too, not left out of the selection. +#[test] +fn a_clipping_path_that_clips_by_nothing_hides_the_members() { + let mut s = session(); + let a = rect(&mut s, 0.0, 0.0, 100.0, 100.0, red()); + let b = rect(&mut s, 50.0, 50.0, 100.0, 100.0, blue()); + let m1 = rect(&mut s, 300.0, 300.0, 100.0, 100.0, green()); + let m2 = rect(&mut s, 450.0, 300.0, 100.0, 100.0, green()); + let mask = rect(&mut s, 300.0, 300.0, 300.0, 100.0, green()); + let g = clip(&mut s, &[m1, m2, mask]); + s.edit("empty clipping path", |d, _| { + let empty = vectorcraft_doc::Node::group(d.alloc_id(), vec![]); + let NodeKind::Group { children, .. } = &mut d.node_mut(g).unwrap().kind else { panic!("not a group") }; + children[0] = std::sync::Arc::new(empty); + Ok(()) + }) + .unwrap(); + select(&mut s, &[a, b, g]); + let e = s.execute("object.pathfinder.intersect", &json!({})).unwrap_err().to_string(); + assert!(e.contains("empty result"), "not the squares' overlap: {e}"); + select(&mut s, &[g]); + let e = s.execute("object.pathfinder.divide", &json!({})).unwrap_err().to_string(); + assert!(e.contains("clipping masks hide"), "{e}"); +}