From 9d8611299b13ec492d6bb454e08f36bdc7a65a67 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 4 Nov 2026 03:43:26 +0000 Subject: [PATCH] address review: count open-subpath overhead as one element in the operator budget --- crates/path/src/ops.rs | 13 ++++++++++--- crates/path/src/ops/tests.rs | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/path/src/ops.rs b/crates/path/src/ops.rs index 7969b8877..826554a5d 100644 --- a/crates/path/src/ops.rs +++ b/crates/path/src/ops.rs @@ -390,8 +390,10 @@ pub fn twist(paths: &[BezPath], angle_deg: f64, center: [f64; 2]) -> Vec usize { + if sub.closed { 2 } else { 1 } +} + /// `want` pieces (or copies) per input segment, reduced so the whole output (segments times /// pieces, plus per-subpath overhead) stays within [`MAX_OPERATOR_SEGMENTS`] (never below 1, so the input itself always passes through). fn pieces_within_budget(paths: &[BezPath], want: usize) -> usize { @@ -460,7 +467,7 @@ fn pieces_within_budget(paths: &[BezPath], want: usize) -> usize { let (mut segs, mut overhead) = (0usize, 0usize); for sub in paths.iter().flat_map(subs) { segs = segs.saturating_add(sub.segs.len()); - overhead = overhead.saturating_add(2); + overhead = overhead.saturating_add(overhead_of(&sub)); } want.min(MAX_OPERATOR_SEGMENTS.saturating_sub(overhead) / segs.max(1)).max(1) } diff --git a/crates/path/src/ops/tests.rs b/crates/path/src/ops/tests.rs index 903524944..2de236e0c 100644 --- a/crates/path/src/ops/tests.rs +++ b/crates/path/src/ops/tests.rs @@ -469,3 +469,12 @@ fn many_short_open_paths_keep_their_requested_detail_within_the_budget() { let z = zigzag(&lines, 1.0, 1000.0, false); assert!(z.iter().all(|q| q.elements().len() == 1 + 1001)); } + +#[test] +fn open_subpaths_reserve_one_element_of_overhead() { + // 349,525 open lines: the move-to is the only extra element, so 2 copies fit the budget + // (a closed subpath's extra close-path would leave room for 1). + let line = BezPath::from_vec(vec![PathEl::MoveTo((0.0, 0.0).into()), PathEl::LineTo((1.0, 0.0).into())]); + let lines = vec![line; 349_525]; + assert_eq!(pieces_within_budget(&lines, 3), 2); +}