mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 09:36:45 +00:00
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.
This commit is contained in:
@@ -370,7 +370,7 @@ type ClippedLeaf = (Node, Option<Arc<Clip>>);
|
||||
|
||||
/// [`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<Clip>>, precision: f64, out: &mut Vec<ClippedLeaf>) -> 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<Clip>>, 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 };
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user