diff --git a/crates/geom/src/tests.rs b/crates/geom/src/tests.rs index 1a2391a35..f95bdd032 100644 --- a/crates/geom/src/tests.rs +++ b/crates/geom/src/tests.rs @@ -210,6 +210,13 @@ fn set_rotation_keeps_center() { } } +#[test] +fn round_to_handles_large_precision_without_changing_finite_values() { + assert_eq!(round_to(1.25, 400), 1.25); + assert_eq!(round_to(-1.25, 400), -1.25); + assert_eq!(round_to(1.23456, 2), 1.23); +} + #[test] fn reverse_subpaths_preserves_open_and_closed() { let mut open = BezPath::new(); diff --git a/crates/geom/src/transform.rs b/crates/geom/src/transform.rs index f992060fd..69c6c788d 100644 --- a/crates/geom/src/transform.rs +++ b/crates/geom/src/transform.rs @@ -57,6 +57,9 @@ pub fn rotate_about(xf: Affine, pivot: Point, degrees: f64) -> Affine { /// Round a value to `digits` decimals for display (avoids `-0` and float noise). pub fn round_to(v: f64, digits: i32) -> f64 { let f = 10f64.powi(digits); + if v.is_finite() && !f.is_finite() { + return v; + } let r = (v * f).round() / f; if r == 0.0 { 0.0 } else { r } }