Fill Area: a left-out path cuts an area only when one of its segments reaches it

A path with too many segments for a window's map is left out of it. The finder treated such a path as cutting the area whenever its bounding box met the area, so a path made of subpaths far apart on either side of an area made the finder map every path, which fails past the segment limit, and the area could not be filled. The finder now checks the path's segments.
This commit is contained in:
dotCooCoo
2026-11-17 18:53:58 -08:00
parent 94fee63cc1
commit af868f2de6
2 changed files with 37 additions and 1 deletions
+26
View File
@@ -316,6 +316,32 @@ fn fill_area_does_not_fill_across_a_huge_path_it_left_out() {
}
}
/// A path with too many segments whose subpaths lie far apart on either side of the square has a box
/// that holds the square, but no segment of it comes near: it is left out and the square is filled.
#[test]
fn fill_area_fills_an_area_that_a_left_out_paths_box_holds_but_its_segments_miss() {
let mut s = session();
line(&mut s, (-20.0, 0.0), (420.0, 0.0));
line(&mut s, (-20.0, 400.0), (420.0, 400.0));
line(&mut s, (0.0, -20.0), (0.0, 420.0));
line(&mut s, (400.0, -20.0), (400.0, 420.0));
let n = vectorcraft_pathops::SHAPE_BUILDER_MAX_SEGMENTS;
let pts: Vec<Point> = (0..=n).map(|k| Point::new(-2000.0 + 400.0 * k as f64 / n as f64, -1000.0 + (k % 2) as f64)).collect();
let far = [Point::new(2000.0, 1500.0), Point::new(2100.0, 1500.0)];
let path = PathData::new(vec![vectorcraft_geom::SubPath::polyline(&pts, false), vectorcraft_geom::SubPath::polyline(&far, false)]);
let look = vectorcraft_doc::Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0);
s.edit("t", |d, _| {
let id = d.alloc_id();
let top = d.children(d.default_layer()).map_or(0, |c| c.len());
d.insert(d.default_layer(), top, Node::path(id, path, look))?;
Ok(id)
})
.unwrap();
deselect(&mut s);
let r = s.execute("shapeBuilder.copyRegion", &json!({"point": [200, 200]})).unwrap();
assert!((area(&s, id_of(&r)) - 160_000.0).abs() < 1.0, "{}", area(&s, id_of(&r)));
}
/// With Gap Detection on, a square on a higher layer within the gap of the area's corners does not
/// bound the area, so the new path stays above the square that does.
#[test]
+11 -1
View File
@@ -2,6 +2,8 @@
//! closed path of that area with the current fill and stroke (`shapeBuilder.copyRegion`). The
//! paths around the area stay as they are, and nothing needs to be selected.
use vectorcraft_geom::path::segment_bounds;
use super::lookup::path_contains;
use super::*;
@@ -63,6 +65,13 @@ fn meet(a: &Rect, b: &Rect) -> bool {
a.x0 <= b.x1 && b.x0 <= a.x1 && a.y0 <= b.y1 && b.y0 <= a.y1
}
/// Does a segment of `path` (closing segments included) meet `zone`? A path whose box meets the zone
/// may still lie wholly outside it, as a path of subpaths far apart does.
fn reaches(path: &PathData, zone: &Rect) -> bool {
let bez = path.to_bezpath();
vectorcraft_geom::kurbo::segments(bez.elements().iter().copied()).any(|seg| meet(&segment_bounds(seg), zone))
}
/// Does `outer` hold all of `inner`?
fn within(inner: &Rect, outer: &Rect) -> bool {
inner.x0 >= outer.x0 && inner.x1 <= outer.x1 && inner.y0 >= outer.y0 && inner.y1 <= outer.y1
@@ -159,7 +168,8 @@ impl AreaFinder {
// path holds both.
Some(rb) if within(&rb, &window) => {
let reached = rb.inflate(reach, reach);
let cut = any_left_out && self.inputs.iter().zip(&left_out).any(|((_, b, _), out)| *out && meet(b, &reached));
let cut = any_left_out
&& self.inputs.iter().zip(&left_out).any(|((s, b, _), out)| *out && meet(b, &reached) && reaches(&s.path, &reached));
if !cut {
return self.area_in(&map, &picked, p);
}