Fill Area: clipped art bounds areas only where its mask shows it

Fill Area used the full outline of art inside a clipping group, so a
click in the part a mask hides still found an area, and the new path
above the clipping group showed art the mask hid. Now each clipped
path is cut to every mask around it before it bounds areas, nested
clipping groups and clipped layers included: a filled path keeps its
overlap with the mask, and the outline of an unfilled path and open
paths keep only their pieces inside it. A mask that clips to nothing
hides what it clips. The new path still goes above the clipping group.

Follows #8001.
This commit is contained in:
dotCooCoo committed 2026-11-25 12:21:49 -08:00
1 parent 3ce5379692
commit 9567d7349a
5 files changed
+128 -4

No files matched your search

+1 -1
View File
@@ -77,7 +77,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Fill Area",
[],
None,
"{point: [x,y], ids?|id?: [id…] (the objects or layers whose paths bound areas; default: every layer, nothing needs to be selected), gap?: pt (0–72; 0: Gap Detection off; out of range is an error), openFilledAsClosed?: true (as shapeBuilder.merge), fill?, stroke?: \"#rrggbb\" | {color|swatch|gradient|none} (default: the current fill and stroke, with the current stroke weight)} add a new closed path of the area under point that the visible, unlocked paths enclose (the region of shapeBuilder.regions holding it: areas a shape already fills and areas open paths bound count too), directly above the front-most object along the area (its outline touches the area's outline, or it covers the area; when a group, Live Paint group, Shaper group or clipping group holds that path, above the outermost group in its layer, never inside it), and select it; in isolation mode only the paths of the isolated layer or group bound areas (with ids, only the paths of the listed objects that are in it), and the new path goes inside it, directly above the object in it that holds that path; no area is found while the isolated object is not a layer or group (a path or compound path), is a Live Paint group, compound shape, Shaper group, graph, Image Trace result, dimension, flare or Objects on Path group, is a layer or group with a live effect or a clipping mask, or lies inside one of these or inside an envelope; the paths around the area are not changed; a point in no enclosed area is an error and changes nothing (no undo step); when the paths together have more than 65,536 segments, only an area the paths near the point enclose is found → {id, above (the object the new path went above)}",
"{point: [x,y], ids?|id?: [id…] (the objects or layers whose paths bound areas; default: every layer, nothing needs to be selected), gap?: pt (0–72; 0: Gap Detection off; out of range is an error), openFilledAsClosed?: true (as shapeBuilder.merge), fill?, stroke?: \"#rrggbb\" | {color|swatch|gradient|none} (default: the current fill and stroke, with the current stroke weight)} add a new closed path of the area under point that the visible, unlocked paths enclose (the region of shapeBuilder.regions holding it: areas a shape already fills and areas open paths bound count too; a path a clipping mask clips bounds areas only where every mask around it shows it), directly above the front-most object along the area (its outline touches the area's outline, or it covers the area; when a group, Live Paint group, Shaper group or clipping group holds that path, above the outermost group in its layer, never inside it), and select it; in isolation mode only the paths of the isolated layer or group bound areas (with ids, only the paths of the listed objects that are in it), and the new path goes inside it, directly above the object in it that holds that path; no area is found while the isolated object is not a layer or group (a path or compound path), is a Live Paint group, compound shape, Shaper group, graph, Image Trace result, dimension, flare or Objects on Path group, is a layer or group with a live effect or a clipping mask, or lies inside one of these or inside an envelope; the paths around the area are not changed; a point in no enclosed area is an error and changes nothing (no undo step); when the paths together have more than 65,536 segments, only an area the paths near the point enclose is found → {id, above (the object the new path went above)}",
has_doc,
sb_copy_region
),
+61
View File
@@ -189,6 +189,67 @@ fn fill_area_stacks_above_the_group_that_holds_the_paths() {
assert_eq!(members(&s, clip), before);
}
/// `ids` clipped by a new rectangle mask in front of them, as the clipping group's id.
fn clip_by(s: &mut Session, ids: &[NodeId], x: f64, y: f64, w: f64, h: f64) -> NodeId {
let mask = rect(s, x, y, w, h);
let ids: Vec<u64> = ids.iter().map(|i| i.0).chain([mask.0]).collect();
s.execute("select.set", &json!({"ids": ids})).unwrap();
id_of(&s.execute("object.clippingMask.make", &json!({})).unwrap())
}
/// Clipped art bounds areas only where its clipping mask shows it: a click in the part the mask
/// hides finds no area and changes nothing, and a click in the part it shows fills only that part.
#[test]
fn fill_area_takes_clipped_art_only_where_its_mask_shows_it() {
let mut s = session();
let square = rect(&mut s, 50.0, 0.0, 100.0, 100.0);
let clip = clip_by(&mut s, &[square], 0.0, -10.0, 100.0, 120.0);
deselect(&mut s);
let (undo, kids) = (undo_len(&s), stack(&s));
assert!(s.execute("shapeBuilder.copyRegion", &json!({"point": [125, 50]})).is_err());
assert_eq!((undo_len(&s), stack(&s)), (undo, kids));
let r = s.execute("shapeBuilder.copyRegion", &json!({"point": [75, 50]})).unwrap();
assert!((area(&s, id_of(&r)) - 5000.0).abs() < 1.0, "{}", area(&s, id_of(&r)));
assert_eq!(stack(&s), vec![clip, id_of(&r)], "the new path goes above the clipping group");
// Without a fill only the outline shows, and the mask's edge does not close the part it shows.
let mut s = session();
let square = rect(&mut s, 50.0, 0.0, 100.0, 100.0);
s.execute("paint.setFill", &json!({"none": true})).unwrap();
clip_by(&mut s, &[square], 0.0, -10.0, 100.0, 120.0);
deselect(&mut s);
let (undo, kids) = (undo_len(&s), stack(&s));
assert!(s.execute("shapeBuilder.copyRegion", &json!({"point": [75, 50]})).is_err());
assert_eq!((undo_len(&s), stack(&s)), (undo, kids));
// Lines the mask cuts bound no area where the parts that close it are hidden.
let mut s = session();
let lines = triangle(&mut s);
clip_by(&mut s, &lines, -20.0, -20.0, 60.0, 140.0);
deselect(&mut s);
let (undo, kids) = (undo_len(&s), stack(&s));
assert!(s.execute("shapeBuilder.copyRegion", &json!({"point": [30, 75]})).is_err());
assert_eq!((undo_len(&s), stack(&s)), (undo, kids));
}
/// In a clipping group inside another, clipped art shows only where both masks show it.
#[test]
fn fill_area_takes_art_in_nested_clipping_groups_only_where_every_mask_shows_it() {
let mut s = session();
let square = rect(&mut s, 50.0, 0.0, 100.0, 100.0);
let inner = clip_by(&mut s, &[square], 0.0, -10.0, 100.0, 120.0);
let outer = clip_by(&mut s, &[inner], 0.0, -20.0, 80.0, 140.0);
deselect(&mut s);
let (undo, kids) = (undo_len(&s), stack(&s));
for p in [[125, 50], [90, 50]] {
assert!(s.execute("shapeBuilder.copyRegion", &json!({"point": p})).is_err(), "{p:?}");
}
assert_eq!((undo_len(&s), stack(&s)), (undo, kids));
let r = s.execute("shapeBuilder.copyRegion", &json!({"point": [65, 50]})).unwrap();
assert!((area(&s, id_of(&r)) - 3000.0).abs() < 1.0, "{}", area(&s, id_of(&r)));
assert_eq!(stack(&s), vec![outer, id_of(&r)]);
}
/// In isolation mode only the isolated group's paths bound areas, for the command and the tool: a
/// click in an area that art outside the group encloses adds nothing, and the new path goes inside
/// the group, above the path along the area.
+62 -1
View File
@@ -146,6 +146,64 @@ fn within(inner: &Rect, outer: &Rect) -> bool {
inner.x0 >= outer.x0 && inner.x1 <= outer.x1 && inner.y0 >= outer.y0 && inner.y1 <= outer.y1
}
/// The outlines of the clipping masks [`unmasked`] has read, by the clipping group or clipped
/// layer: None for one whose mask clips to nothing, which hides all it clips.
type Masks = std::collections::HashMap<NodeId, Option<(PathData, FillRule)>>;
/// `shape`, the outline of `leaf`, cut to where every clipping mask around `leaf` shows it
/// ([`clip_to`]). A path in a mask is not cut by that mask. None when the masks hide all of it.
fn unmasked(doc: &Document, leaf: &Node, mut shape: po::Shape, masks: &mut Masks) -> Option<po::Shape> {
let Some(line) = doc.ancestry(leaf.id) else { return Some(shape) };
let filled = leaf.appearance.has_drawn_fill();
for a in line.iter().filter(|a| **a != leaf.id) {
let Some(n) = doc.node(*a).filter(|n| n.clips()) else { continue };
let Some(mask) = n.children().and_then(|c| c.first()) else { continue };
if line.contains(&mask.id) {
continue;
}
let outline = masks.entry(*a).or_insert_with(|| {
vectorcraft_effects::clip_outline(mask).map(|(bp, rule)| (PathData::from_bezpath(&bp), rule)).filter(|(p, _)| !p.is_empty())
});
let (m, rule) = outline.as_ref()?;
shape = clip_to(shape, filled, m, *rule)?;
}
Some(shape)
}
/// `shape` cut to `mask` (filled with `rule`). With `filled` (the path's fill draws), its closed
/// subpaths are cut to their overlap with the mask, whose edge then bounds the fill. Its other
/// subpaths, and every subpath of a path without a fill, are cut to their pieces inside the mask,
/// so a hidden part of an outline does not close an area. A subpath with more segments or
/// crossings than [`po::addons::pathtools::crossings_on`] takes is left out. None when nothing of
/// it is inside.
fn clip_to(shape: po::Shape, filled: bool, mask: &PathData, rule: FillRule) -> Option<po::Shape> {
let (b, mb) = (shape.path.bounds()?, mask.bounds()?);
if !meet(&b, &mb) {
return None;
}
let (closed, lines): (Vec<SubPath>, Vec<SubPath>) = shape.path.subpaths.into_iter().partition(|sp| filled && sp.closed);
let had_closed = !closed.is_empty();
let mut subs = if had_closed { po::boolean(&PathData::new(closed), shape.rule, mask, rule, po::BoolOp::Intersect).subpaths } else { vec![] };
for sp in lines {
let one = PathData::new(vec![sp]);
// A subpath whose crossings with the mask are past what can be found is left out, so no
// part of it the mask hides bounds an area.
let Some(crossed) = po::addons::pathtools::crossings_on(&one, &[mask]) else { continue };
let places: Vec<(usize, f64)> = crossed.into_iter().map(|(_, s, t)| (s, t)).collect();
let Some(sp) = one.subpaths.first() else { continue };
let (cut, at) = po::addons::pathtools::insert_at(sp, &places);
subs.extend(cut.cut_at(&at).into_iter().filter(|piece| {
let n = piece.segment_count();
n > 0 && path_contains(mask, rule, piece.segment(n / 2).eval(0.5))
}));
}
if subs.is_empty() {
return None;
}
let rule = if had_closed { FillRule::NonZero } else { shape.rule };
Some(po::Shape::new(PathData::new(subs), rule, shape.key))
}
/// The object directly in `scope` (the isolated object in isolation mode), or else directly in a
/// layer (or sublayer), that holds `id`: `id` itself when `scope` or a layer holds it, or when `id`
/// is `scope`.
@@ -217,7 +275,8 @@ pub fn fill_area_roots(doc: &Document, isolation: Option<NodeId>, named: Option<
impl AreaFinder {
/// The finder over the paths of `roots` (layers or objects) that the Shape Builder takes:
/// visible, unlocked paths, compound paths and Live Paint faces and edges that draw, not on a
/// locked artboard. Gaps up to `gap` close, and with `open_filled_as_closed` a filled open path
/// locked artboard. A path a clipping mask clips counts only where the mask shows it
/// ([`unmasked`]). Gaps up to `gap` close, and with `open_filled_as_closed` a filled open path
/// bounds an area as if an invisible edge closed it. With `scope` (the isolated object in
/// isolation mode), an area's new path goes directly above the object in `scope` that holds the
/// front-most path along it, so it stays inside the isolated object.
@@ -225,11 +284,13 @@ impl AreaFinder {
let roots = sorted_roots(doc, roots);
let (shapes, leaves) = shape_builder_shapes(doc, &roots, open_filled_as_closed);
let editable = doc.editable();
let mut masks = Masks::new();
let inputs: Vec<(po::Shape, Rect, NodeId)> = shapes
.into_iter()
.zip(leaves)
.filter(|(_, l)| editable(l.id))
.filter_map(|(s, l)| {
let s = unmasked(doc, l, s, &mut masks)?;
let b = s.path.bounds()?;
Some((s, b, outermost(doc, l.id, scope)))
})
+3 -1
View File
@@ -14059,7 +14059,9 @@ a stroke when it has `rect`. With both `rect` and `points`, the command also tou
The Fill Area tool (`fillArea`, in the Live Paint Bucket's group) adds a new closed path of the area under a click
and leaves the paths around it as they are. Nothing needs to be selected: the visible, unlocked paths on every layer
bound areas, filled or not, open paths included, and the overlap of two filled shapes is an area of its own. While the
bound areas, filled or not, open paths included, and the overlap of two filled shapes is an area of its own. A path
that a clipping mask clips bounds areas only where every mask around it shows it, so a click where a mask hides the art
finds no area there. While the
pointer hovers an area, the tool outlines it in red and the pointer shows the bucket with paint; elsewhere the pointer
shows the empty bucket, and a click there does nothing. The new path appears on the press and is kept on the release;
Escape or a canceled touch before the release takes it back. In a document of more than 128 path segments the tool looks
+1 -1
View File
@@ -1599,7 +1599,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
With Pick Color From Artwork, a merged shape takes the appearance, opacity and blending mode of the object where the drag starts, else of the object where it ends, else of the front-most selected object, as the [Shape Builder combine page](https://web.archive.org/web/20251006211643/https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/combine-shapes-with-shape-builder-tool.html) describes. A click in an area that no selected object covers, such as a hole other shapes enclose, takes the front-most selected object's look (`shapeBuilder.merge` `points`: the first point is where the drag starts, and the last point is where it ends).
A Shift-drag with the Shape Builder tool draws a rectangular marquee for merging many paths at once, as [Combine shapes with the Shape Builder tool](https://web.archive.org/web/20251006211643/https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/combine-shapes-with-shape-builder-tool.html) describes: the regions it reaches are shaded while it is drawn and merge into one shape on release, or with Alt they are deleted. The marquee reaches each region whose outline crosses it or has an anchor inside it, and the region that holds the whole marquee; this rule is VectorCraft's own. For Pick Color From Artwork, the marquee's starting corner is where the drag starts and the opposite corner is where it ends (`shapeBuilder.merge` `rect`).
The Shape Builder works on the selected paths, as [Combine shapes with the Shape Builder tool](https://web.archive.org/web/20251006211643/https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/combine-shapes-with-shape-builder-tool.html) describes. As VectorCraft's own rule, a click or drag that builds nothing says why in the status bar when it is released: "Shape Builder: select paths or compound paths" when nothing is selected or the selection holds no unlocked, visible path; "Shape Builder: select all paths you want to merge" when the release is over a path or compound path that is not selected; and "Shape Builder: no region under the pointer" otherwise. The document, the selection and the undo history stay as they were, and the next gesture that builds something clears the message. Regression tests: `shape_builder_with_nothing_selected_says_what_to_select`, `shape_builder_names_the_unselected_path_under_a_release_that_built_nothing` and `shape_builder_replayed_gesture_over_nothing_gives_its_status_once` in `builder/tests.rs`, and `tests::build::shape_builder_click_that_builds_nothing_shows_why`.
As VectorCraft's own tool, Fill Area (in the Live Paint Bucket's group) adds a new closed path of the area under a click with the current fill and stroke, directly above the front-most object along it, and leaves the paths around it as they are. It needs no selection: the visible, unlocked paths on every layer bound areas, open paths and the overlap of filled shapes included, and it uses the Shape Builder's Gap Detection (`shapeBuilder.copyRegion`). In isolation mode only the isolated layer or group's paths bound areas and the new path goes inside it. It finds no area while the isolated object is not a layer or group, is a group that makes, moves or combines its own art (Live Paint, compound shapes, Shaper groups, graphs, Image Trace results, dimensions, flares, Objects on Path), is a layer or group with a live effect or a clipping mask, or lies inside one of these or inside an envelope. Regression tests: `tests::fill_area::*`.
As VectorCraft's own tool, Fill Area (in the Live Paint Bucket's group) adds a new closed path of the area under a click with the current fill and stroke, directly above the front-most object along it, and leaves the paths around it as they are. It needs no selection: the visible, unlocked paths on every layer bound areas, open paths and the overlap of filled shapes included, and it uses the Shape Builder's Gap Detection (`shapeBuilder.copyRegion`). A path that a clipping mask clips bounds areas only where every mask around it shows it. In isolation mode only the isolated layer or group's paths bound areas and the new path goes inside it. It finds no area while the isolated object is not a layer or group, is a group that makes, moves or combines its own art (Live Paint, compound shapes, Shaper groups, graphs, Image Trace results, dimensions, flares, Objects on Path), is a layer or group with a live effect or a clipping mask, or lies inside one of these or inside an envelope. Regression tests: `tests::fill_area::*`.
Shape Builder pieces on dense hatches (lines at exact 0.25 or 0.5 pt steps across another line) come back one per stretch between crossings, with no speck where the sweep cut a line's two passes a rounding error apart: the planar map contracts the stub between such cuts into one vertex, bounded by each cluster's extent so a run of tiny level segments keeps its length (`crates/pathops/src/planar.rs` tests `a_dense_hatch_at_exact_binary_steps_cuts_each_line_once_per_crossing`, `a_run_of_tiny_level_segments_is_not_contracted_as_stubs`, `a_line_crossed_where_its_two_passes_part_is_cut_once`).
The Shape Builder's gray hatch over the region under the pointer and the regions a drag has touched is drawn by a sweep that tests each hatch line only against the region's edges that span it, instead of every edge on every line. The hatch lines are the same, coordinate for coordinate; on a 2,000-sided region 1,000 hatches take about 83 ms of CPU time instead of 356 ms (release build, median of 7 alternating runs), and on a region of 40 sides the time is about the same, so the gain is on large, complex regions such as traced art (`crates/tools/src/builder/tests.rs` tests `hatch_matches_testing_every_edge`, `hatch_tests_only_the_edges_spanning_each_line` and `hatch_sweep_finds_the_crossings_of_every_edge`; timing: `hatch_perf`).
The planar map's edge-source grid stays linear in memory on any input: a segment is filed once per cell it crosses, and the grid holds at most a budget of cell references (a few dozen per item plus a few rows' worth), past which the remaining items go to a short scanned list and are still found, so thousands of coincident segments cannot make the index quadratic (`crates/pathops/src/planar.rs` test `rect_index_holds_a_bounded_number_of_references`).