From b3a7bf05a94f0a826f1f3ad0eac73d6b82e98832 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 09:48:39 -0800 Subject: [PATCH] Pathfinder: Divide keeps the pieces a group's own fill paints under Remove Unpainted Artwork A live Divide effect with removeUnpainted on left out every piece of a member with no visible fill, even where the group's own fill paints the members. A compound shape's area has no paint of its own, so a filled compound shape drew nothing. A group's or compound shape's own visible fill now counts as painting its pieces for Divide. Outline's open segments still go by their source's fill. --- crates/effects/src/group.rs | 13 +++++++-- crates/effects/src/group/tests.rs | 44 +++++++++++++++++++++++++++++++ docs/mcp.md | 5 ++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/crates/effects/src/group.rs b/crates/effects/src/group.rs index 123e5963f4..70e010c8e3 100644 --- a/crates/effects/src/group.rs +++ b/crates/effects/src/group.rs @@ -66,7 +66,7 @@ pub const PATHFINDER_EFFECT_PRECISION: std::ops::RangeInclusive = 0.001..=1 /// The documentation of [`PATHFINDER_OPTION_KEYS`], as a literal for `concat!`. macro_rules! options_doc { () => { - "precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, the other operations ignore it)" + "precision?: pt 0.001..10 (effect.apply: Pathfinder Options › Precision; 0.01 when missing; results are refit to within it and pieces thinner than it are dropped), removeRedundantPoints?: bool (effect.apply: Pathfinder Options › Remove Redundant Points; false when missing; results lose the anchors that don't change their shape to within precision), removeUnpainted?: bool (effect.apply: Pathfinder Options › Divide and Outline Will Remove Unpainted Artwork; false when missing; Divide and Outline leave out the pieces of members with no visible fill, except that Divide keeps every piece when the group or compound shape has a visible fill of its own; the other operations ignore it)" }; } @@ -555,6 +555,10 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option> = if group.is_compound_shape() { // The group's own appearance paints the area ([`evaluate_container`]), so the art has none. match compound_shape_area(doc, group, hook) { @@ -644,7 +648,12 @@ pub fn pathfinder_children(doc: Option<&Document>, group: &Node, hook: Option !own_fill, + PathfinderOp::Outline => true, + _ => false, + }; po::pathfinder_with(op, &shapes, options.precision) .into_iter() .filter(|r| !r.path.is_empty() && !(unpainted && !has_visible_fill(&sources[r.key as usize]))) diff --git a/crates/effects/src/group/tests.rs b/crates/effects/src/group/tests.rs index 519323e5f0..2d1e34111b 100644 --- a/crates/effects/src/group/tests.rs +++ b/crates/effects/src/group/tests.rs @@ -120,6 +120,50 @@ fn divide_and_outline_draw_nothing_for_unpainted_members() { } } +/// With Remove Unpainted Artwork, Divide keeps the area of a compound shape whose own appearance +/// has a visible fill and leaves out the area of one without. Outline's open segments of the area +/// go either way. +#[test] +fn remove_unpainted_keeps_a_filled_compound_shapes_area() { + for effect in ["pathfinder.divide", "pathfinder.outline"] { + for filled in [true, false] { + let mut g = compound_shape(ShapeMode::Add); + if !filled { + g.appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0).into(); + } + g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": true}), visible: true }); + let out = pathfinder_children(None, &g, None).unwrap(); + let kept = filled && effect == "pathfinder.divide"; + assert_eq!(!out.is_empty(), kept, "{effect}, filled {filled}: {out:#?}"); + } + } +} + +/// With Remove Unpainted Artwork, Divide keeps the pieces of an unfilled member when its group's +/// own visible fill paints them and leaves them out when the group has no fill. Outline leaves out +/// the member's segments either way. +#[test] +fn remove_unpainted_keeps_members_a_groups_own_fill_paints() { + let unfilled = Arc::new(Node::path( + NodeId(2), + shapes::rectangle(Rect::new(5.0, 0.0, 15.0, 10.0)), + Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0), + )); + for effect in ["pathfinder.divide", "pathfinder.outline"] { + for filled in [true, false] { + let mut g = Node::group(NodeId(10), vec![sq(1, 0.0, Color::rgb(1.0, 0.0, 0.0)), unfilled.clone()]); + if filled { + g.appearance = Appearance::basic(Paint::solid(Color::rgb(0.0, 1.0, 0.0)), Paint::None, 0.0).into(); + } + g.appearance.effects.push(Effect { id: effect.into(), params: serde_json::json!({"removeUnpainted": true}), visible: true }); + let out = pathfinder_children(None, &g, None).unwrap(); + assert!(out.iter().any(|n| n.id == NodeId(1)), "{effect}, filled {filled}: {out:#?}"); + let kept = filled && effect == "pathfinder.divide"; + assert_eq!(out.iter().any(|n| n.id == NodeId(2)), kept, "{effect}, filled {filled}: {out:#?}"); + } + } +} + /// Returns an "H" in blue type at 100 pt on a baseline at y = 80, with its stems on either /// side of x = 100. fn type_h() -> Node { diff --git a/docs/mcp.md b/docs/mcp.md index 8703a01d05..05899cee14 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4891,8 +4891,9 @@ whatever the options are then. Each Effect › Pathfinder effect (`pathfinder.add` … `pathfinder.softMix`, not Trap) keeps Pathfinder Options of its own in its params: `precision` (a number, 0.001–10 pt), `removeRedundantPoints` and `removeUnpainted` (true or false), which -mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`. `effect.apply` fills -the ones `params` leave out from the current Pathfinder Options, and the values join its journal entry. An effect saved +mean what they mean for the panel's operations; the other operations ignore `removeUnpainted`, and Divide keeps every +piece when the group or compound shape has a visible fill of its own. `effect.apply` fills the ones `params` leave out +from the current Pathfinder Options, and the values join its journal entry. An effect saved without them evaluates with precision 0.01 and both switches off, as before effects kept them. `effect.setParams {index, params: {precision?, removeRedundantPoints?, removeUnpainted?}}` edits them as one undo step; values the effect already evaluates with record no undo step and return `{ids: []}`. A precision out of range, or a switch that