Fix #8093: a hidden operand is an empty shape where it changes the result

A selected object its clipping masks hide altogether was left out of the
operation. For Intersect, Minus Front (hidden at the back), Minus Back
(hidden in front) and Crop (hidden on top) that changed the result: the
others' overlap or the next object down took its place. It now stays in as
an empty shape for those four, which then give nothing. The other operations
still leave it out, which gives the same art and keeps its style off the
result.
This commit is contained in:
Sven Lafebre
2026-11-16 13:11:07 +01:00
parent 8c53f8ce88
commit 099ab6ea13
3 changed files with 88 additions and 33 deletions
+45 -32
View File
@@ -677,6 +677,10 @@ fn run_pf(s: &mut Session, p: &Value, op: PathfinderOp) -> Result<Value> {
}
let shape_mode =
matches!(op, PathfinderOp::Unite | PathfinderOp::MinusFront | PathfinderOp::Intersect | PathfinderOp::Exclude | PathfinderOp::MinusBack);
// An operand its clipping masks hide altogether is an empty shape for the operations whose
// result it changes (Intersect gives nothing, Minus Front loses its back object, Minus Back its
// front one, Crop its cropping shape); the others leave it out, which gives the same art.
let keeps_hidden = matches!(op, PathfinderOp::Intersect | PathfinderOp::MinusFront | PathfinderOp::MinusBack | PathfinderOp::Crop);
let label = pf_label(op);
let options = pf_options(s, p, &format!("object.pathfinder.{}", pf_id(op)))?;
let ids = s.edit(label, |d, sel| {
@@ -684,39 +688,41 @@ fn run_pf(s: &mut Session, p: &Value, op: PathfinderOp) -> Result<Value> {
let mut styles: Vec<Style> = vec![];
let mut shapes: Vec<po::Shape> = vec![];
let mut names: Vec<Option<String>> = vec![];
let mut push = |mut path: PathData, mut rule: FillRule, mut st: Style, name: Option<String>, clip: Option<&Clip>| -> Result<()> {
if path.is_empty() {
return Ok(());
}
// Trim, Merge and Crop remove any strokes (and Merge then merges by fill alone), as the
// public Pathfinder documentation describes.
if matches!(op, PathfinderOp::Trim | PathfinderOp::Merge | PathfinderOp::Crop) {
st.appearance.items.retain(|i| !matches!(i, AppearanceItem::Stroke(_)));
}
if op == PathfinderOp::Divide && st.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Fill(f) if !f.paint.is_none())) {
// Filled open contours keep their implicit closing edge. A zero-area line
// stays a cutter; normalised area also catches zero-signed-area self crossings.
for sub in path.subpaths.iter_mut().filter(|sp| !sp.closed) {
sub.closed = po::encloses_area(sub) || po::area(&PathData::single(sub.clone()), rule) > 0.0;
}
}
if let Some(clip) = clip {
(path, rule) = clipped(path, rule, clip, op == PathfinderOp::Divide, options.precision)?;
if path.is_empty() {
// `hidden`: the masks hide the operand altogether, and its empty path stands for it.
let mut push =
|mut path: PathData, mut rule: FillRule, mut st: Style, name: Option<String>, clip: Option<&Clip>, hidden: bool| -> Result<()> {
if path.is_empty() && !(hidden && keeps_hidden) {
return Ok(());
}
}
let key = match styles.iter().position(|x| *x == st) {
Some(k) => k,
None => {
styles.push(st);
styles.len() - 1
// Trim, Merge and Crop remove any strokes (and Merge then merges by fill alone), as the
// public Pathfinder documentation describes.
if matches!(op, PathfinderOp::Trim | PathfinderOp::Merge | PathfinderOp::Crop) {
st.appearance.items.retain(|i| !matches!(i, AppearanceItem::Stroke(_)));
}
if op == PathfinderOp::Divide && st.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Fill(f) if !f.paint.is_none())) {
// Filled open contours keep their implicit closing edge. A zero-area line
// stays a cutter; normalised area also catches zero-signed-area self crossings.
for sub in path.subpaths.iter_mut().filter(|sp| !sp.closed) {
sub.closed = po::encloses_area(sub) || po::area(&PathData::single(sub.clone()), rule) > 0.0;
}
}
if let Some(clip) = clip {
(path, rule) = clipped(path, rule, clip, op == PathfinderOp::Divide, options.precision)?;
if path.is_empty() && !keeps_hidden {
return Ok(());
}
}
let key = match styles.iter().position(|x| *x == st) {
Some(k) => k,
None => {
styles.push(st);
styles.len() - 1
}
};
shapes.push(po::Shape::new(path, rule, key as u64));
names.push(name);
Ok(())
};
shapes.push(po::Shape::new(path, rule, key as u64));
names.push(name);
Ok(())
};
// Whether a clip group was among the selection, for the error when its mask hides it all.
let mut masked = false;
for id in &roots {
@@ -742,21 +748,28 @@ fn run_pf(s: &mut Session, p: &Value, op: PathfinderOp) -> Result<Value> {
parts.push((l, p, r));
}
}
let Some((top, ..)) = parts.last() else { continue };
let name = n.name.clone().or_else(|| parts.iter().find_map(|(l, ..)| l.name.clone()));
let Some((top, ..)) = parts.last() else {
// The masks hide the whole group.
if let Some((top, _)) = lv.last() {
push(PathData::default(), FillRule::NonZero, style_of(top), name, None, true)?;
}
continue;
};
let top = *top;
let refs: Vec<(&PathData, FillRule)> = parts.iter().map(|(_, p, r)| (p, *r)).collect();
let name = n.name.clone().or_else(|| parts.iter().find_map(|(l, ..)| l.name.clone()));
push(
po::try_unite_all_with(&refs, options.precision).map_err(|e| EngineError::Other(e.to_string()))?,
FillRule::NonZero,
style_of(top),
name,
None,
false,
)?;
} else {
for (l, clip) in &lv {
if let Some((p, r)) = node_path(l) {
push(p, r, style_of(l), n.name.clone().or_else(|| l.name.clone()), clip.as_deref())?;
push(p, r, style_of(l), n.name.clone().or_else(|| l.name.clone()), clip.as_deref(), clip.is_some())?;
}
}
}
@@ -241,3 +241,45 @@ fn art_the_masks_hide_altogether_is_refused_with_a_reason() {
assert!(e.contains("clipping masks hide"), "{e}");
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "nothing changes");
}
/// A clip group its mask hides altogether, selected with a red square at (0, 0) and a blue one at
/// (50, 50), each 100 pt, at `position` in the stacking order (0: at the back).
fn with_a_hidden_clip_group(s: &mut Session, position: usize) {
let mut ids = vec![];
for i in 0..3 {
if i == position {
// Two members, so among other objects the group is one shape: their union.
let a = rect(s, 300.0, 300.0, 100.0, 100.0, green());
let b = rect(s, 450.0, 300.0, 100.0, 100.0, green());
let mask = rect(s, 0.0, 0.0, 100.0, 100.0, green());
ids.push(clip(s, &[a, b, mask]));
} else {
let at = if ids.len() == usize::from(position == 0) { 0.0 } else { 50.0 };
ids.push(rect(s, at, at, 100.0, 100.0, if at == 0.0 { red() } else { blue() }));
}
}
select(s, &ids);
}
/// A selected object its masks hide altogether is an empty operand: Intersect, Minus Front with
/// it at the back, Minus Back with it in front and Crop with it on top give nothing, and the other
/// operations make what they make without it.
#[test]
fn a_hidden_operand_is_an_empty_shape_where_it_changes_the_result() {
for (op, position) in [("intersect", 1), ("minusFront", 0), ("minusBack", 2), ("crop", 2)] {
let mut s = session();
with_a_hidden_clip_group(&mut s, position);
let undo = s.doc().unwrap().history.undo.len();
let e = s.execute(&format!("object.pathfinder.{op}"), &json!({})).unwrap_err().to_string();
assert!(e.contains("empty result"), "{op}: {e}");
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "{op}: nothing changes");
}
for (op, position, want) in [("unite", 2, 17500.0), ("exclude", 2, 15000.0), ("minusFront", 2, 7500.0), ("minusBack", 0, 7500.0)] {
let mut s = session();
with_a_hidden_clip_group(&mut s, position);
let ps = pieces(&mut s, &format!("object.pathfinder.{op}"));
let total: f64 = ps.iter().map(area).sum();
assert!((total - want).abs() < 1.0, "{op}: {total}, want {want}");
assert!(ps.iter().all(|p| p.0 != Paint::solid(green())), "{op}: the hidden group's style: {ps:?}");
}
}
+1 -1
View File
@@ -1403,7 +1403,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- Live effects with previewing dialogs: Distort & Transform, Path, Convert to Shape, 15 Warp styles, Round Corners, Scribble, Effect → Pathfinder (all 10 operations, live on groups; several loose objects are grouped first, in one undo step), Color Adjustments (Brightness/Contrast, Curves, Levels, Hue/Saturation, Shift to Color, Temperature/Tint, on vectors, live type and embedded images), and raster drop shadow, glows and feather. SVG and PDF export keep live effects (geometry baked; SVG raster effects as filters). Zig Zag spaces its ridges evenly along each segment, so lines and curves get a regular wave in Corner and Smooth (#1558). Warp › Arc (the effect and Envelope › Make with Warp) bends in the object's real proportions: a circular arc with concentric edges and no fold-over at 100%, so Arc on art that isn't square draws differently from before (#1581, fixes #1578). `effect.apply` and `effect.setParams` give an error for a misspelt or wrongly typed effect parameter instead of running the effect with its default (#1623, #1592). Roughen with Smooth keeps turn-backs smooth instead of making cusps that draw as spikes (#1646, #1643). Scribble draws one zig-zag per region, with no lines across holes and notches; convex shapes are unchanged (#1651, #1648). On the canvas, in Expand Appearance and in exports, Effect → Pathfinder uses the glyph outlines of type in the group, and results painted like the type keep its opacity and blend mode.
- Cmd/Ctrl+4 (`pathfinder.repeat`) repeats the last successful Pathfinder panel operation, direct `object.pathfinder.*` command or `command.batch` step (including Actions playback) on the current selection; the panel menu names it. `action.batch`, Trap, compound-shape edits and live effects do not set history. Public references: [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), [Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html).
- Pathfinder Options ([Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html)): the panel menu's Pathfinder Options… sets Precision (0.001–10 pt: results refit to within it, thinner pieces dropped), Remove Redundant Points and Divide and Outline Will Remove Unpainted Artwork (`object.pathfinder.options`, kept in the preferences) for every Shape Mode and Pathfinder operation; the defaults keep the earlier output (`pathops` `precision_drops_pieces_thinner_than_it`, engine `tests_pathops` Pathfinder Options tests, `panels::pathfinder` dialog test).
- Pathfinder on clip groups (#8093): a clip group's members take part in the Shape Modes and Pathfinder buttons (`object.pathfinder.*`) only where its clipping path shows them, so Divide cuts the visible art along the mask and the hidden art goes; nested clip groups cut by each mask, a member the mask hides gives no piece, a cutting line's hidden part cuts nothing, and the clipping path adds no piece of its own (the public documentation doesn't say what Pathfinder does with masked art; our choice, asked on the issue). A cutting line is clipped by sampling, so a part of the mask much narrower than the mask itself can be missed. Make Compound Shape, Trap and the Pathfinder effects still take the members whole. Tests: `crates/engine/src/tests/pathfinder_clip.rs`.
- Pathfinder on clip groups (#8093): a clip group's members take part in the Shape Modes and Pathfinder buttons (`object.pathfinder.*`) only where its clipping path shows them, so Divide cuts the visible art along the mask and the hidden art goes; nested clip groups cut by each mask, a member the mask hides gives no piece, a cutting line's hidden part cuts nothing, a selected object the masks hide altogether counts as an empty shape where that changes the result (Intersect, Minus Front, Minus Back, Crop), and the clipping path adds no piece of its own (the public documentation doesn't say what Pathfinder does with masked art; our choice, asked on the issue). A cutting line is clipped by sampling, so a part of the mask much narrower than the mask itself can be missed. Make Compound Shape, Trap and the Pathfinder effects still take the members whole. Tests: `crates/engine/src/tests/pathfinder_clip.rs`.
- Pathfinder › Trap ([trapping](https://helpx.adobe.com/illustrator/using/trapping.html), [Pathfinder panel](https://helpx.adobe.com/illustrator/using/pathfinder-panel-overview.html)): the Pathfinder panel menu's Trap… (`object.pathfinder.trap`) and Effect › Pathfinder › Trap… (`pathfinder.trap`, live on groups) add, where two objects' visible areas of different solid colours meet, a strip of the darker one's area along the edge, filled with the lighter colour at the Tint Reduction percentage and set to overprint (Reverse Traps: the darker colour spreads instead, but not a rich black); Thickness 0.01–5000 pt across vertical edges, Height/Width scales it across horizontal ones, Traps with Process Color paints a swatch colour's trap with its CMYK equivalent; the effect also has Precision and Remove Redundant Points. The panel's Trap is one undo step and groups the traps above the topmost selected object, selected; with no adjoining edges of different colours it says so and changes nothing. Tests: `crates/pathops/src/trap.rs`, `crates/effects/src/trap.rs`, `group::tests::trap_effect_adds_an_overprinting_strip_above_the_members`, `crates/engine/src/tests/trap.rs`, `panels::pathfinder::tests::trap_opens_its_options_and_ok_traps_the_selection`.
- Compound shapes ([Create compound shapes with Pathfinder](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/create-compound-shapes-with-pathfinder.html), [Pathfinder panel overview](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/pathfinder-panel-overview.html)): the Pathfinder panel menu's Make Compound Shape (every member in Add) and Alt-clicking a Shape Mode (every member in that mode) make the two or more selected paths, compound paths, groups, compound shapes or type a live compound shape (`object.compoundShape.make`): a group whose members each keep a shape mode and stay editable, drawn, printed and exported (SVG, PDF and the rest through the baked document) as the area the modes make from the backmost member up, open paths closed, painted with its own appearance, taken from the topmost member not subtracting. With members selected (Direct Selection, Layers panel, isolation mode) a Shape Mode button sets theirs (`object.compoundShape.setMode`) and is lit for the mode they share; paint given to a member goes to the compound shape. Release Compound Shape gives the members back as they were (`object.compoundShape.release`); Expand Compound Shape and the panel's Expand button turn it into the path or compound path of its area (`object.compoundShape.expand`). Shape Modes and Pathfinders take a compound shape as its area. Saved files keep it (`compound_shape`, `shape_mode`; an unknown mode reads as Add). Blends, envelopes and objects with a warp or another geometry effect are members as they draw (a blend's steps, an envelope's distorted art, the warped outline), and the area follows an edit of the blend, envelope or warp; Release gives them back as they were. Tests: `crates/engine/src/tests/compound_shape.rs`, `group::tests::compound_shapes_draw_the_area_their_shape_modes_make`, `group::tests::nested_compound_shapes_take_part_as_their_area`, `panels::pathfinder::tests::compound_shape_items_follow_the_selection`, the `CompoundShape` op of the property-test strategies. Not yet: the question marks on mixed member modes, hit-testing by the area (a click hits the members).
- Effect › Path › Outline Object has no options. Type that carries it is drawn, exported (PDF and SVG as paths, with no font) and expanded as its glyph outlines while it stays editable, and the effects after it reshape those outlines. Paths and images draw as before. With Use Preview Bounds on, type is measured by its glyph outlines. Public reference: [Summary of effects](https://web.archive.org/web/20210901011839/https://helpx.adobe.com/illustrator/using/summary-effects.html) (archived copy).