Merge pull request #1797 from TheGalitube/fix/h7835-large-decimal-precision-makes-ro

Preserve finite values at large rounding precision
This commit is contained in:
BFlat authored and GitHub committed 2026-11-07 12:03:46 +08:00
commit 1eef98d610
2 files changed
+10

No files matched your search

+7
View File
@@ -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();
+3
View File
@@ -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 }
}