From 33f32c11665de8befc5cc87711a5c5e3073be99f Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sun, 1 Nov 2026 00:14:06 -0400 Subject: [PATCH] Geom: the bounded-sizes test also covers the cap itself, NaN, infinities and negative sizes Review follow-up on #1774. Co-Authored-By: Claude Fable 5.1 --- crates/geom/src/tests.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/geom/src/tests.rs b/crates/geom/src/tests.rs index cbc5f0bc0..f50ea229b 100644 --- a/crates/geom/src/tests.rs +++ b/crates/geom/src/tests.rs @@ -59,7 +59,8 @@ fn absurd_sizes_build_bounded_paths() { // kurbo subdivides an arc in proportion to the sixth root of its radius, so without a cap the // segment count grows without bound with the input: a 1e36 ellipse was about a million // elements and 1e60 never returned. Sizes are untrusted (files, commands), so they are capped. - for mag in [1e36, 1e300, f64::MAX] { + // At the cap itself (1e9) an arc is still a few dozen segments. + for mag in [MAX_COORD, 1e36, 1e300, f64::MAX] { let paths = [ ("ellipse", ellipse(mag, mag, 0.0, PI, 0.0)), ("ring", ellipse(mag, mag, 0.0, TAU, 0.5)), @@ -76,6 +77,19 @@ fn absurd_sizes_build_bounded_paths() { let p = smoothed_polygon(&[Point::new(0.0, 0.0), Point::new(mag, 0.0), Point::new(mag, mag)], mag, 0.6); assert!(p.elements().len() < 1_000, "huge points at {mag:e}: {} elements", p.elements().len()); } + // NaN, infinities and negative sizes build nothing or a bounded path with a finite box. + for v in [f64::NAN, f64::INFINITY, f64::NEG_INFINITY, -1e36, -1.0] { + let paths = [ + ("ellipse", ellipse(v, v, v, v, v)), + ("rounded_rect", rounded_rect(v, v, [v; 4], v)), + ("smoothed_polygon", smoothed_polygon(&polygon_points(100.0, 100.0, 5), v, v)), + ]; + for (name, p) in paths { + assert!(p.elements().len() < 1_000, "{name} at {v}: {} elements", p.elements().len()); + let b = p.bounding_box(); + assert!([b.x0, b.y0, b.x1, b.y1].iter().all(|x| x.is_finite()), "{name} at {v}: {b:?}"); + } + } // Sizes a document can hold are untouched. let p = rounded_rect(1e6, 1e6, [1e5; 4], 0.6); let b = p.bounding_box();