#![allow(bad_style)] #![allow(clippy::float_cmp)] //! "Mat Mul-mat" belongs in a Dune novel. use hektor::*; #[test] fn Mat2_mul_Mat2() { let m1 = Mat2::diagonal(1.0, 1.0); let m2 = Mat2::diagonal(1.0, 1.0); assert_eq!(m1 * m2, Mat2::diagonal(1.0, 1.0)); // let m1 = Mat2::from([1.0, 2.0, 3.0, 4.0]); let m2 = Mat2::from([2.0, 1.0, 0.0, 2.0]); assert_eq!(m1 * m2, Mat2::from([5.0, 8.0, 6.0, 8.0])); assert_eq!(m2 * m1, Mat2::from([2.0, 5.0, 6.0, 11.0])); } #[test] fn Mat3_mul_Mat3() { let m1 = Mat3::diagonal(1.0, 1.0, 1.0); let m2 = Mat3::diagonal(1.0, 1.0, 1.0); assert_eq!(m1 * m2, Mat3::diagonal(1.0, 1.0, 1.0)); // let m1 = Mat3::from([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]); let m2 = Mat3::from([7.0, 6.0, 5.0, -2.0, -8.0, 12.0, 20.0, 0.0, 4.0]); assert_eq!( m1 * m2, Mat3::from([66.0, 84.0, 102.0, 50.0, 52.0, 54.0, 48.0, 72.0, 96.0]) ); assert_eq!( m2 * m1, Mat3::from([63.0, -10.0, 41.0, 138.0, -16.0, 104.0, 213.0, -22.0, 167.0]) ); } #[test] fn Mat4_mul_Mat4() { let m1 = Mat4::diagonal(1.0, 1.0, 1.0, 1.0); let m2 = Mat4::diagonal(1.0, 1.0, 1.0, 1.0); assert_eq!(m1 * m2, Mat4::diagonal(1.0, 1.0, 1.0, 1.0)); // let m1 = Mat4::from([ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, ]); let m2 = Mat4::from([ 7.0, 6.0, 5.0, -2.0, -8.0, 12.0, 20.0, 0.0, 4.0, -1.0, 2.0, -3.0, 4.0, 1.0, 0.0, -1.0, ]); assert_eq!( m1 * m2, Mat4::from([ 56.0, 72.0, 88.0, 104.0, 232.0, 256.0, 280.0, 304.0, -22.0, -20.0, -18.0, -16.0, -4.0, 0.0, 4.0, 8.0 ]) ); assert_eq!( m2 * m1, Mat4::from([ 19.0, 31.0, 51.0, -15.0, 47.0, 103.0, 159.0, -39.0, 75.0, 175.0, 267.0, -63.0, 103.0, 247.0, 375.0, -87.0 ]) ); }