From 6db229c28458a9489024ae6ebce0b7c76bd44415 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 17:46:30 -0800 Subject: [PATCH] Pathfinder: an Intersect effect with a group that has no area at its precision draws nothing A group operand whose members have no area left at the effect's precision was left out of the operation, so Intersect returned the other operand as it was. Intersect now draws nothing in that case, as do Minus Back when that group is the front operand and Subtract when it is the back operand. Add, Exclude and Subtract with the group in front still leave it out. --- crates/effects/src/group.rs | 20 +++++++++++++- crates/effects/src/group/tests.rs | 43 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/crates/effects/src/group.rs b/crates/effects/src/group.rs index aeffaacfb6..ed34fa5426 100644 --- a/crates/effects/src/group.rs +++ b/crates/effects/src/group.rs @@ -644,13 +644,19 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option = vec![]; let mut shapes: Vec = vec![]; + // Keys of the group operands whose art has no area left at the precision. + let mut collapsed: Vec = vec![]; for mut lv in all { if shape_mode && lv.len() > 1 { let parts: Vec<(PathData, FillRule)> = lv.iter().filter_map(geometry).collect(); let refs: Vec<(&PathData, FillRule)> = parts.iter().map(|(p, r)| (p, *r)).collect(); let key = sources.len() as u64; if let Some(top) = lv.pop() { - shapes.push(po::Shape::new(po::unite_all_with(&refs, options.precision), FillRule::NonZero, key)); + let united = po::unite_all_with(&refs, options.precision); + if united.is_empty() && !parts.is_empty() { + collapsed.push(key); + } + shapes.push(po::Shape::new(united, FillRule::NonZero, key)); sources.push(top); } } else { @@ -662,6 +668,18 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option shapes.iter().any(is_collapsed), + PathfinderOp::MinusFront => shapes.first().is_some_and(is_collapsed), + PathfinderOp::MinusBack => shapes.last().is_some_and(is_collapsed), + _ => false, + }; + if nothing_left { + return Some(vec![]); + } shapes.retain(|s| !s.path.is_empty() && s.path.subpaths.iter().all(|sp| sp.anchors.iter().all(|a| a.p.x.is_finite() && a.p.y.is_finite()))); if shapes.is_empty() { return Some(vec![]); diff --git a/crates/effects/src/group/tests.rs b/crates/effects/src/group/tests.rs index 1c62508347..94c71e936b 100644 --- a/crates/effects/src/group/tests.rs +++ b/crates/effects/src/group/tests.rs @@ -196,6 +196,49 @@ fn shape_modes_follow_the_pathfinder_panel() { assert_eq!(div.len(), 3); } +/// An Intersect effect draws nothing when a group member's art has no area left at the effect's +/// precision, and so do Minus Back when that group is in front and Subtract when it is at the +/// back. Add, and Subtract with the group in front, leave such a member out. +#[test] +fn intersect_with_a_group_that_collapses_at_its_precision_draws_nothing() { + let thin_pair = |width: f64| { + let bar = |id: u64, x: f64| { + let fill = Appearance::basic(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), Paint::None, 0.0); + Arc::new(Node::path(NodeId(id), shapes::rectangle(Rect::new(x, 10.0, x + width, 30.0)), fill)) + }; + Node::group(NodeId(5), vec![bar(3, 10.0), bar(4, 50.0)]) + }; + let with_precision = |front: Node, effect: &str| { + let mut g = square_and(Some(front), effect); + g.appearance.effects[0].params = serde_json::json!({"precision": 1.0}); + g + }; + let int = results(&with_precision(thin_pair(0.5), "pathfinder.intersect")); + assert!(int.is_empty(), "{int:#?}"); + // Bars wider than the precision keep their area. + let int = results(&with_precision(thin_pair(2.0), "pathfinder.intersect")); + let total: f64 = int.iter().map(|n| area(n)).sum(); + assert!((total - 80.0).abs() < 1.0, "{total}: {int:#?}"); + // Add keeps the square alone. + let add = results(&with_precision(thin_pair(0.5), "pathfinder.add")); + assert_eq!(add.len(), 1); + assert!((area(&add[0]) - 10_000.0).abs() < 1.0, "{add:#?}"); + // Minus Back cuts the square from the empty group in front, and Subtract cuts nothing from + // the square. + let minus_back = results(&with_precision(thin_pair(0.5), "pathfinder.minusBack")); + assert!(minus_back.is_empty(), "{minus_back:#?}"); + let subtract = results(&with_precision(thin_pair(0.5), "pathfinder.subtract")); + assert_eq!(subtract.len(), 1); + assert!((area(&subtract[0]) - 10_000.0).abs() < 1.0, "{subtract:#?}"); + // With the group at the back, Subtract cuts the square from it and leaves nothing. + let mut back = with_precision(thin_pair(0.5), "pathfinder.subtract"); + if let NodeKind::Group { children, .. } = &mut back.kind { + children.reverse(); + } + let subtract = results(&back); + assert!(subtract.is_empty(), "{subtract:#?}"); +} + /// Divide and Outline draw no piece of a member without fill or stroke, the same as when such /// pieces are left out. #[test]