perf(guides): start a bounds walk with no segment budget

A bounds walk gathers no segments, so its unspent segment budget kept the
walk measuring every object after its anchors and bounds ran out.
This commit is contained in:
HassanKhan committed 2026-11-20 12:45:18 +05:00
1 parent 3c6b879d44
commit 0d8e8a25a6
2 files changed
+15 -2

No files matched your search

+9 -2
View File
@@ -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<T>(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
+6
View File
@@ -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();