#![allow(bad_style)] #![allow(clippy::float_cmp)] #![allow(clippy::unreadable_literal)] use hektor::*; #[test] fn Mat2_transpose() { assert!(Mat2::default().inverse().is_none()); // let m = Mat2::from([4.0, 3.0, 6.0, 8.0]); assert!(m.determinant() != 0.0); let actual_arr: [f32; 4] = (m.inverse().unwrap() * m).into(); let expected_arr: [f32; 4] = Mat2::diagonal(1.0, 1.0).into(); // TODO(Lokathor): how do we approx good? actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); // let actual_arr: [f32; 4] = (m * m.inverse().unwrap()).into(); let expected_arr: [f32; 4] = Mat2::diagonal(1.0, 1.0).into(); actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); } #[test] fn Mat3_transpose() { assert!(Mat3::default().inverse().is_none()); // let m = Mat3::from([6.0, 4.0, 2.0, 1.0, -2.0, 8.0, 1.0, 5.0, 7.0]); assert!(m.determinant() != 0.0); let actual_arr: [f32; 9] = (m.inverse().unwrap() * m).into(); let expected_arr: [f32; 9] = Mat3::diagonal(1.0, 1.0, 1.0).into(); // TODO(Lokathor): how do we approx good? actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); // let actual_arr: [f32; 9] = (m * m.inverse().unwrap()).into(); let expected_arr: [f32; 9] = Mat3::diagonal(1.0, 1.0, 1.0).into(); actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); } #[test] fn Mat4_transpose() { assert!(Mat4::default().inverse().is_none()); // let m = Mat4::from([ 1.0, 2.0, 3.0, 4.0, -1.0, 10.0, 6.0, 5.0, 20.0, 12.0, -8.0, -2.0, 4.0, -5.0, 2.0, 3.0, ]); assert!(m.determinant() != 0.0); let actual_arr: [f32; 16] = (m.inverse().unwrap() * m).into(); let expected_arr: [f32; 16] = Mat4::diagonal(1.0, 1.0, 1.0, 1.0).into(); // TODO(Lokathor): how do we approx good? actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); // let actual_arr: [f32; 16] = (m * m.inverse().unwrap()).into(); let expected_arr: [f32; 16] = Mat4::diagonal(1.0, 1.0, 1.0, 1.0).into(); actual_arr .iter() .zip(expected_arr.iter()) .for_each(|(a, e)| assert!((*a - *e).abs() <= 0.000001, "a:{}, e:{}", *a, *e)); }