mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-29 12:56:47 -06:00
Clamp Vector Drawable numbers to the f32 range so they stay finite
Found while testing crates/vectordrawable/src/xml.rs:22 (num), reached via stroke_attrs at :189 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
43af145a12
commit
d3bde76baf
@@ -42,6 +42,15 @@ fn a_miter_limit_other_than_four_is_written() {
|
||||
assert_eq!(paths_of(&out.xml)[0].get("strokeMiterLimit"), Some("10"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_huge_miter_limit_is_written_as_a_finite_number() {
|
||||
let (mut d, r) = stroked(StrokeAlign::Center);
|
||||
d.get_mut(r).unwrap().stroke.miter_limit = 1e306;
|
||||
let out = export(&d, &[r], Compat::BestEffort);
|
||||
let v = paths_of(&out.xml)[0].get("strokeMiterLimit").unwrap().to_string();
|
||||
assert!(v.parse::<f32>().unwrap().is_finite(), "{v}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_uniform_scale_scales_the_stroke_width() {
|
||||
let (mut d, r) = stroked(StrokeAlign::Center);
|
||||
|
||||
@@ -19,6 +19,9 @@ pub(crate) fn num(v: f64) -> String {
|
||||
if !v.is_finite() {
|
||||
return "0".into();
|
||||
}
|
||||
// Android reads these as 32-bit floats, so clamp to that range; this also keeps the scaling
|
||||
// below from overflowing to infinity.
|
||||
let v = v.clamp(-f64::from(f32::MAX), f64::from(f32::MAX));
|
||||
let r = (v * 1000.0).round() / 1000.0;
|
||||
let s = format!("{r}");
|
||||
if s == "-0" { "0".into() } else { s }
|
||||
|
||||
Reference in New Issue
Block a user