From 0c65a8442bc4eeb020b6d7545bc32d4f91aa4efd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 13:02:16 -0800 Subject: [PATCH] Fill Area: a path left out of the search stops an area only when it reaches it When the paths together are over the segment limit, the search maps the paths near the point and leaves out the ones with the most segments. A path left out made the search give up on an area when it came within the gap plus 1 pt of the area's outline, so with Gap Detection off a long line 0.75 pt outside a square stopped a click inside the square from filling it. A gap bridge reaches at most the gap, so the check now uses the gap plus the map's 0.05 pt contact tolerance. The 1 pt padding still decides which paths the search picks. --- crates/engine/src/tests/fill_area.rs | 34 +++++++++++++++++++++++++++ crates/tools/src/builder/fill_area.rs | 11 +++++---- docs/mcp.md | 4 +++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/tests/fill_area.rs b/crates/engine/src/tests/fill_area.rs index 6703d4f928..d6e82af05b 100644 --- a/crates/engine/src/tests/fill_area.rs +++ b/crates/engine/src/tests/fill_area.rs @@ -582,6 +582,40 @@ fn fill_area_fills_an_l_whose_empty_corner_holds_a_left_out_path() { assert!((area(&s, id_of(&r)) - 70_000.0).abs() < 1.0, "{}", area(&s, id_of(&r))); } +/// Draws a 100 pt square at the origin and, in front of it, an open path with too many segments +/// that runs from x -20 to 120 at `y` and up to 0.1 pt above it, then clicks at `click` with +/// `gap`. Gives the area of the new path, or None when the click finds no area. +fn square_beside_a_huge_line(y: f64, gap: f64, click: (f64, f64)) -> Option { + let mut s = session(); + rect(&mut s, 0.0, 0.0, 100.0, 100.0); + let n = vectorcraft_pathops::SHAPE_BUILDER_MAX_SEGMENTS; + let pts: Vec = (0..=n).map(|k| Point::new(-20.0 + 140.0 * k as f64 / n as f64, y - (k % 2) as f64 * 0.1)).collect(); + let look = vectorcraft_doc::Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0); + insert_path(&mut s, PathData::single(vectorcraft_geom::SubPath::polyline(&pts, false)), look); + deselect(&mut s); + let r = s.execute("shapeBuilder.copyRegion", &json!({"point": [click.0, click.1], "gap": gap})).ok()?; + Some(area(&s, id_of(&r))) +} + +/// With Gap Detection off, a path with too many segments 0.75 pt outside a square is left out and +/// does not touch the square, so a click in the square fills it. One that crosses the square still +/// stops the fill. +#[test] +fn fill_area_fills_a_square_a_left_out_path_passes_close_to() { + let a = square_beside_a_huge_line(-0.75, 0.0, (50.0, 50.0)).expect("the square"); + assert!((a - 10_000.0).abs() < 1.0, "{a}"); + assert_eq!(square_beside_a_huge_line(60.0, 0.0, (50.0, 25.0)), None); +} + +/// With a gap, a path with too many segments farther from the square than the gap is left out and +/// does not stop the square from being filled. One that crosses the square still stops the fill. +#[test] +fn fill_area_gap_fills_a_square_a_left_out_path_passes_beyond_the_gap() { + let a = square_beside_a_huge_line(-2.75, 2.0, (50.0, 50.0)).expect("the square"); + assert!((a - 10_000.0).abs() < 1.0, "{a}"); + assert_eq!(square_beside_a_huge_line(60.0, 2.0, (50.0, 25.0)), None); +} + /// A filled contour with too many segments on a higher layer surrounds a small square, its outline /// far from it: it is left out of the map, and the new path still goes above it, since it covers /// the area. diff --git a/crates/tools/src/builder/fill_area.rs b/crates/tools/src/builder/fill_area.rs index 367ff09318..2ce72b15f3 100644 --- a/crates/tools/src/builder/fill_area.rs +++ b/crates/tools/src/builder/fill_area.rs @@ -74,7 +74,8 @@ struct Reach<'a> { face: &'a PathData, bez: &'a vectorcraft_geom::kurbo::BezPath, zone: Rect, - /// How close (pt) to the outline a path may come and still change the area: the gap and 1 pt. + /// How close (pt) to the outline a path may come and still change the area: the gap and + /// [`CONTACT`]. reach: f64, } @@ -359,13 +360,15 @@ impl AreaFinder { let before = window; match bounds { // A path left out that crosses the area or comes within its reach could cut it, and - // only the map of every path holds both. + // only the map of every path holds both. A bridge reaches at most `gap`, so a path + // farther than that from the outline, give or take [`CONTACT`], does not change it. Some(rb) if within(&rb, &window) => { - let reached = rb.inflate(reach, reach); + let contact = self.gap + CONTACT; + let reached = rb.inflate(contact, contact); let mut budget = CUT_BUDGET; let cut = any_left_out && face.is_none_or(|(region, bez, _)| { - let area = Reach { face: ®ion.path, bez, zone: reached, reach }; + let area = Reach { face: ®ion.path, bez, zone: reached, reach: contact }; self.inputs.iter().zip(&left_out).any(|((s, b, _), out)| *out && meet(b, &reached) && cuts(&s.path, &area, &mut budget)) }); if !cut { diff --git a/docs/mcp.md b/docs/mcp.md index 3a496a84df..8bd390d263 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -14082,7 +14082,9 @@ Objects on Path group, is a layer or group with a live effect or a clipping mask inside an envelope. A point in no enclosed area is the error "Fill Area: no enclosed area under the pointer" and records no undo step; a `gap` outside 0 to 72 is an error. It returns `{id, above}`. The command looks for the area among the paths near the point first. When the paths together have more than 65,536 segments and the paths near the point do not -enclose it, the point counts as in no enclosed area. +enclose it, the point counts as in no enclosed area. A path that this search leaves out to stay within that limit +stops the command from finding the area only when it crosses the area or comes within the gap plus 0.05 pt of its +outline. ```json {"name":"run_command","arguments":{"command":"shapeBuilder.copyRegion","params":{"point":[50,70],"gap":3}}}