mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-11 12:55:16 +00:00
Preserve finite values at large rounding precision
Found while testing crates/geom/src/transform.rs:59 Co-Authored-By: GPT-5.6-Luna <noreply@openai.com> Co-Authored-By: GPT-6-Luna <noreply@openai.com>
This commit is contained in:
1 parent
53259cf50e
commit
a46e2369bc
2 files changed
+10
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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