mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-24 10:09:32 -06:00
Return None from Mat4::inverse for non-finite input
Found while testing crates/geom/src/lib.rs:362-390 (pivot check at line 367) 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
b55cb5bc15
commit
ed532afe72
@@ -360,6 +360,9 @@ impl Mat4 {
|
||||
}
|
||||
/// General inverse (Gauss-Jordan with partial pivoting).
|
||||
pub fn inverse(&self) -> Option<Mat4> {
|
||||
if !self.0.iter().flatten().all(|v| v.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let mut a = self.0;
|
||||
let mut inv = Mat4::IDENTITY.0;
|
||||
for col in 0..4 {
|
||||
@@ -450,6 +453,16 @@ mod tests {
|
||||
(a - b).length() < 1e-9
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mat4_inverse_rejects_non_finite() {
|
||||
for (r, c, v) in [(0, 0, f64::NAN), (2, 1, f64::NAN), (1, 3, f64::INFINITY)] {
|
||||
let mut m = Mat4::IDENTITY;
|
||||
m.0[r][c] = v;
|
||||
assert!(m.inverse().is_none(), "{r},{c},{v}");
|
||||
}
|
||||
assert!(Mat4::IDENTITY.inverse().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_2d_maps_anchor_to_position() {
|
||||
let m = Mat3::layer_2d(vec2(50.0, 25.0), vec2(960.0, 540.0), vec2(200.0, 50.0), 30.0);
|
||||
|
||||
Reference in New Issue
Block a user