97 lines
2.8 KiB
Rust
Raw Normal View History

2024-09-26 15:06:01 -07:00
use crate::types::{Matrix3,Matrix3x2,Matrix3x4,Matrix4x2,Vector3};
2024-08-28 13:36:17 -07:00
type Planar64=fixed_wide::types::I32F32;
type Planar64Wide1=fixed_wide::types::I64F64;
2024-08-28 13:36:17 -07:00
//type Planar64Wide2=fixed_wide::types::I128F128;
type Planar64Wide3=fixed_wide::types::I256F256;
#[test]
fn wide_vec3(){
let v=Vector3::from_value(Planar64::from(3));
2024-09-10 14:50:35 -07:00
let v1=v*v.x;
let v2=v1*v1.y;
let v3=v2*v2.z;
2024-08-28 13:36:17 -07:00
2024-09-06 11:25:51 -07:00
assert_eq!(v3.array,Vector3::from_value(Planar64Wide3::from(3i128.pow(8))).array);
2024-08-28 13:36:17 -07:00
}
#[test]
fn wide_vec3_dot(){
let v=Vector3::from_value(Planar64::from(3));
2024-09-10 14:50:35 -07:00
let v1=v*v.x;
let v2=v1*v1.y;
2024-09-09 16:55:44 -07:00
let v3=v2.dot(v2);
2024-08-28 13:36:17 -07:00
assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3));
}
#[test]
fn wide_vec3_length_squared(){
let v=Vector3::from_value(Planar64::from(3));
2024-09-10 14:50:35 -07:00
let v1=v*v.x;
let v2=v1*v1.y;
2024-09-09 16:55:44 -07:00
let v3=v2.length_squared();
2024-08-28 13:36:17 -07:00
assert_eq!(v3,Planar64Wide3::from(3i128.pow(8)*3));
}
2024-08-30 13:07:56 -07:00
#[test]
fn wide_matrix_dot(){
2024-09-26 15:06:01 -07:00
let lhs=Matrix3x4::new([
2024-09-05 13:53:03 -07:00
[Planar64::from(1),Planar64::from(2),Planar64::from(3),Planar64::from(4)],
[Planar64::from(5),Planar64::from(6),Planar64::from(7),Planar64::from(8)],
[Planar64::from(9),Planar64::from(10),Planar64::from(11),Planar64::from(12)],
2024-09-26 15:06:01 -07:00
]).transpose();
let rhs=Matrix4x2::new([
2024-09-05 13:53:03 -07:00
[Planar64::from(1),Planar64::from(2)],
[Planar64::from(3),Planar64::from(4)],
[Planar64::from(5),Planar64::from(6)],
[Planar64::from(7),Planar64::from(8)],
2024-09-26 15:06:01 -07:00
]).transpose();
2024-09-03 10:43:07 -07:00
// Mat3<Vec4>.dot(Mat4<Vec2>) -> Mat3<Vec2>
2024-09-09 17:01:52 -07:00
let m_dot=lhs*rhs;
2024-09-03 10:43:07 -07:00
//In[1]:= {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} . {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
//Out[1]= {{50, 60}, {114, 140}, {178, 220}}
assert_eq!(
2024-09-06 11:25:51 -07:00
m_dot.array,
2024-09-26 15:06:01 -07:00
Matrix3x2::new([
2024-09-05 13:53:03 -07:00
[Planar64Wide1::from(50),Planar64Wide1::from(60)],
[Planar64Wide1::from(114),Planar64Wide1::from(140)],
[Planar64Wide1::from(178),Planar64Wide1::from(220)],
2024-09-26 15:06:01 -07:00
]).transpose().array
2024-09-03 10:43:07 -07:00
);
}
2024-09-04 13:55:11 -07:00
#[test]
2024-09-10 11:32:42 -07:00
#[cfg(feature="named-fields")]
2024-09-04 13:55:11 -07:00
fn wide_matrix_det(){
2024-09-05 13:53:03 -07:00
let m=Matrix3::new([
[Planar64::from(1),Planar64::from(2),Planar64::from(3)],
[Planar64::from(4),Planar64::from(5),Planar64::from(7)],
[Planar64::from(6),Planar64::from(8),Planar64::from(9)],
2024-09-04 13:55:11 -07:00
]);
// In[2]:= Det[{{1, 2, 3}, {4, 5, 7}, {6, 8, 9}}]
// Out[2]= 7
2024-09-09 18:02:05 -07:00
assert_eq!(m.det(),fixed_wide::fixed::Fixed::<3,96>::from(7));
2024-09-04 13:55:11 -07:00
}
#[test]
2024-09-10 11:32:42 -07:00
#[cfg(feature="named-fields")]
2024-09-04 13:55:11 -07:00
fn wide_matrix_adjugate(){
2024-09-05 13:53:03 -07:00
let m=Matrix3::new([
[Planar64::from(1),Planar64::from(2),Planar64::from(3)],
[Planar64::from(4),Planar64::from(5),Planar64::from(7)],
[Planar64::from(6),Planar64::from(8),Planar64::from(9)],
2024-09-04 13:55:11 -07:00
]);
// In[6]:= Adjugate[{{1, 2, 3}, {4, 5, 7}, {6, 8, 9}}]
// Out[6]= {{-11, 6, -1}, {6, -9, 5}, {2, 4, -3}}
assert_eq!(
2024-09-09 18:02:05 -07:00
m.adjugate().array,
2024-09-05 13:53:03 -07:00
Matrix3::new([
[Planar64Wide1::from(-11),Planar64Wide1::from(6),Planar64Wide1::from(-1)],
[Planar64Wide1::from(6),Planar64Wide1::from(-9),Planar64Wide1::from(5)],
[Planar64Wide1::from(2),Planar64Wide1::from(4),Planar64Wide1::from(-3)],
2024-09-06 11:25:51 -07:00
]).array
2024-09-04 13:55:11 -07:00
);
}