diff --git a/crates/tools/src/guides/targets.rs b/crates/tools/src/guides/targets.rs index 06dddbbeaa..fdb76832cb 100644 --- a/crates/tools/src/guides/targets.rs +++ b/crates/tools/src/guides/targets.rs @@ -73,7 +73,7 @@ pub(super) const BOUNDS_BUDGET: usize = 100_000; /// What [`Targets::collect_inner`] gathers from each path besides its anchors and bounds. #[derive(Clone, Copy, PartialEq)] -enum Gather { +pub(super) enum Gather { /// Nothing more: a moved or resized selection lines up with bounds. Bounds, /// Its segments, which a dragged anchor lands on. @@ -82,6 +82,13 @@ enum Gather { Drawing, } +/// The anchor, segment and bounds budgets a walk starts with. A walk that gathers no segments +/// starts with none to spend, so it stops once its anchors and bounds run out. +pub(super) fn start_budgets(gather: Gather, bounds_budget: usize) -> (usize, usize, usize) { + let segment_budget = if gather == Gather::Bounds { 0 } else { BUDGET }; + (BUDGET, segment_budget, bounds_budget) +} + /// The entries of `sorted` (ascending by `key`) whose key is within `tol` of `v`, found by /// bisection. fn within(sorted: &[T], key: impl Fn(&T) -> f64, v: f64, tol: f64) -> &[T] { @@ -651,7 +658,7 @@ impl Targets { add_rect(&mut t, doc.setup.bleed_rect(ab.rect), Kind::Bleed); } } - let (mut budget, mut segment_budget, mut bounds_budget) = (BUDGET, BUDGET, bounds_budget); + let (mut budget, mut segment_budget, mut bounds_budget) = start_budgets(gather, bounds_budget); walk_but(&doc.layers, &exclude.iter().copied().collect(), &mut |n| { // Each budget caps only its own targets: the anchors and segments running out leave // the objects visited after that (the topmost, newest ones) their edges and centre diff --git a/crates/tools/src/guides/tests.rs b/crates/tools/src/guides/tests.rs index 2067062c6f..656863ce42 100644 --- a/crates/tools/src/guides/tests.rs +++ b/crates/tools/src/guides/tests.rs @@ -34,6 +34,12 @@ fn objects_past_the_anchor_budget_keep_their_edges_and_centre() { assert_eq!(drawn.snap_point(Point::new(450.0, 298.0), 4.0).0.y, 300.0); } +#[test] +fn a_bounds_walk_has_no_segment_budget_to_keep_it_going() { + assert_eq!(super::targets::start_budgets(super::targets::Gather::Bounds, 7), (super::targets::BUDGET, 0, 7)); + assert_eq!(super::targets::start_budgets(super::targets::Gather::Segments, 7).1, super::targets::BUDGET); +} + #[test] fn objects_past_the_bounds_budget_keep_their_anchors() { let (d, _) = doc_with_rect();