diff --git a/crates/specialized/rtx-cfd/src/mesh/patch_gen.rs b/crates/specialized/rtx-cfd/src/mesh/patch_gen.rs index 162a18f..f040817 100644 --- a/crates/specialized/rtx-cfd/src/mesh/patch_gen.rs +++ b/crates/specialized/rtx-cfd/src/mesh/patch_gen.rs @@ -330,10 +330,21 @@ impl<'a> PolylineIndex<'a> { let pts = self.pts; let n = pts.len(); let (mut best, mut best_d) = (pts[0], f64::INFINITY); + // An UPPER bound on the minimum from each chunk's first vertex (a + // point of the polyline, so no segment can beat it by more than the + // rounding margin): chunks farther than it are pruned from the + // start, and the bound never becomes the answer — the scan below + // keeps the brute-force rule (first segment at the strict minimum). + let mut prune_d = f64::INFINITY; + for c in 0..self.boxes.len() { + let a = pts[c * self.chunk]; + let d = (a[0] - q[0]).powi(2) + (a[1] - q[1]).powi(2); + prune_d = prune_d.min(d); + } for (c, b) in self.boxes.iter().enumerate() { let dx = (b[0] - q[0]).max(0.0).max(q[0] - b[1]); let dy = (b[2] - q[1]).max(0.0).max(q[1] - b[3]); - if dx * dx + dy * dy > best_d * (1.0 + 1e-12) { + if dx * dx + dy * dy > best_d.min(prune_d) * (1.0 + 1e-12) { continue; } let start = c * self.chunk;