From a46e2369bcd86afa8f8c859f6e914250606d4a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Mittelst=C3=A4dt?= <62167861+TheGalitube@users.noreply.github.com> Date: Sun, 1 Nov 2026 09:31:20 +0000 Subject: [PATCH] Preserve finite values at large rounding precision Found while testing crates/geom/src/transform.rs:59 Co-Authored-By: GPT-5.6-Luna Co-Authored-By: GPT-6-Luna --- crates/geom/src/tests.rs | 7 +++++++ crates/geom/src/transform.rs | 3 +++ 2 files changed, 10 insertions(+) diff --git a/crates/geom/src/tests.rs b/crates/geom/src/tests.rs index 37e6ccab7..509db9779 100644 --- a/crates/geom/src/tests.rs +++ b/crates/geom/src/tests.rs @@ -163,6 +163,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 } }