mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-24 10:09:32 -06:00
Fix panic in path::rect when both size components are NaN
Found while testing crates/path/src/lib.rs:136 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
9db7f3b217
commit
798b8a98e6
@@ -133,7 +133,9 @@ pub fn from_kurbo(path: &BezPath) -> Vec<ShapePath> {
|
||||
/// Rectangle path centred at `pos` with corner `roundness` (AE draws clockwise from the top-right).
|
||||
pub fn rect(size: [f64; 2], pos: [f64; 2], roundness: f64) -> BezPath {
|
||||
let r = kurbo::Rect::from_center_size(Point::new(pos[0], pos[1]), (size[0].abs(), size[1].abs()));
|
||||
let rad = roundness.clamp(0.0, size[0].abs().min(size[1].abs()) / 2.0);
|
||||
let max_rad = size[0].abs().min(size[1].abs()) / 2.0;
|
||||
// `f64::clamp` panics on a NaN bound (both size components NaN): fall back to no roundness.
|
||||
let rad = if max_rad.is_nan() { 0.0 } else { roundness.clamp(0.0, max_rad) };
|
||||
if rad > 0.0 { r.to_rounded_rect(rad).to_path(0.1) } else { r.to_path(0.1) }
|
||||
}
|
||||
|
||||
@@ -354,6 +356,11 @@ pub fn transform(paths: &[BezPath], m: &Mat3) -> Vec<BezPath> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rect_with_nan_size_does_not_panic() {
|
||||
let _ = rect([f64::NAN, f64::NAN], [0.0, 0.0], 5.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip_vertex_model() {
|
||||
let sp = ShapePath::ellipse([10.0, 20.0], 40.0, 30.0);
|
||||
|
||||
Reference in New Issue
Block a user