mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
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.
This commit is contained in:
1 parent
788365db28
commit
0c65a8442b
3 files changed
+44
-5
No files matched your search
@@ -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<f64> {
|
||||
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<Point> = (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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+3
-1
@@ -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}}}
|
||||
|
||||
Reference in new issue
Block a user