Path Precision Tools: Trim at Crossings shows the stretch a click would remove

Hovering with the Trim at Crossings Tool draws in red the stretch a click
there would remove, on the same paths and by the same rules as the click,
and nothing over empty canvas or hidden and locked paths. A drag draws
every stretch its rectangle or freehand line would remove while it
reaches at most 32 paths. In isolation mode only paths inside the
isolated object are highlighted.

What a pick removes moves from the command into
vectorcraft_tools::addons::trim::plan, which the command and the tool
both use. A preview spends at most a twentieth of the crossing work a
click may (Work::share); past that it shows nothing, and the click or
release still removes what it reaches. The tool keeps the crossings it
found for the document as it is, so moving along one path does not
search again, and kept crossings still count against a pick's work
budget. Work::spent_since and Work::draw in vectorcraft-pathops measure
and charge that work.

Docs: docs/mcp.md, docs/ui-parity.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-15 11:24:17 -08:00
parent 5bd8acfce9
commit 5bba196c4f
12 changed files with 941 additions and 222 deletions
@@ -226,6 +226,27 @@ impl Default for Work {
}
}
impl Work {
/// One `n`th of the work of [`Work::default`] (all of it for `n` of 0 or 1).
pub const fn share(n: usize) -> Work {
let n = if n == 0 { 1 } else { n };
Work { pairs: MAX_PAIRS / n, steps: MAX_STEPS / n }
}
/// The work done since the budget was `before`.
pub fn spent_since(self, before: Work) -> Work {
Work { pairs: before.pairs.saturating_sub(self.pairs), steps: before.steps.saturating_sub(self.steps) }
}
/// Take `cost` (from [`Work::spent_since`]) out of what is left, as if that work were done
/// again. `None`, leaving the budget as it was, when less than `cost` is left.
pub fn draw(&mut self, cost: Work) -> Option<()> {
let (pairs, steps) = (self.pairs.checked_sub(cost.pairs)?, self.steps.checked_sub(cost.steps)?);
*self = Work { pairs, steps };
Some(())
}
}
/// Where `others` cross `path`, and where `path` crosses itself (a segment that loops over itself
/// included): the places on `path`, in order, within the work of [`Work::default`].
pub fn crossings_on(path: &PathData, others: &[&PathData]) -> Option<Vec<Place>> {
@@ -515,6 +515,29 @@ fn one_work_budget_bounds_several_calls_together() {
assert!(crossings_on(&path, &[]).is_some(), "a call of its own has its own budget");
}
#[test]
fn work_done_once_can_be_drawn_again_from_another_budget() {
let row: Vec<(f64, f64)> = (0..=1000).map(|i| (i as f64, 0.0)).collect();
let path = PathData::single(line(&row, false));
let start = Work::default();
let mut work = start;
crossings_on_within(&path, &[], &mut work).unwrap();
let cost = work.spent_since(start);
// Drawing a call's cost leaves what the call itself leaves, 120 times and no more.
let mut again = Work::default();
assert_eq!(again.draw(cost), Some(()));
assert_eq!(again, work);
let draws = (1..200).take_while(|_| again.draw(cost).is_some()).count();
assert_eq!(draws, 119);
let left = again;
assert_eq!(again.draw(cost), None);
assert_eq!(again, left, "a draw that fails takes nothing");
// A twentieth of the budget pays for the call 6 times.
assert_eq!((Work::share(0), Work::share(1)), (Work::default(), Work::default()));
let mut part = Work::share(20);
assert_eq!((0..200).take_while(|_| part.draw(cost).is_some()).count(), 6);
}
#[test]
fn a_segment_that_loops_over_itself_crosses_itself() {
// One cubic that meets itself at t = 0.25 and t = 0.75.