From bd3f69f23347df3caa7007f9659d4b4892885fed Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 20:09:25 -0800 Subject: [PATCH] Path Precision Tools: Common Tangents finds a run's sample by binary search The touching-run search looked up the sample before each angle with a linear scan over the run, so a long run of samples within the tolerance cost time in proportion to the square of its length. It now collects the run's sample angles once and uses partition_point, which gives the same sample at every angle. --- crates/pathops/src/addons/pathtools/tangents.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/pathops/src/addons/pathtools/tangents.rs b/crates/pathops/src/addons/pathtools/tangents.rs index e893a93997..e10d8df5b7 100644 --- a/crates/pathops/src/addons/pathtools/tangents.rs +++ b/crates/pathops/src/addons/pathtools/tangents.rs @@ -613,8 +613,10 @@ fn roots(at: &[f64], f: &dyn Fn(f64, usize) -> f64, tol: f64) -> Result = (1..=len + 1).map(|j| ang(k, j)).collect(); let piece = |t: f64| { - let j = (1..=len + 1).take_while(|j| ang(k, *j) <= t).count(); + let j = edges.partition_point(|a| *a <= t); f(t, (k + j) % n) }; let mut marks = vec![(theta, val(k))];