mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-09 03:51:42 +00:00
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:
2 files changed
+10
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
Reference in new issue
Block a user