Crates.io | det |
lib.rs | det |
version | 0.1.0 |
source | src |
created_at | 2016-08-25 20:34:18.768833 |
updated_at | 2016-08-25 20:34:18.768833 |
description | Calculate the determinant using a macro |
homepage | |
repository | https://github.com/Limeth/det-rs |
max_upload_size | |
id | 6104 |
size | 38,944 |
Calculate the determinant of a square matrix using a Rust macro
This macro should not be used directly. Instead, it should be called inside a function that is used elsewhere.
Calculate the area of a parallelogram:
pub fn find_orthonormal_4(a: &Vector2<f32>, b: &Vector2<f32>) -> f32 {
det_copy!(a.x, a.y,
b.x, b.y)
}
Calculate a 4D orthogonal vector using nalgebra:
pub fn find_orthonormal_4(a: &Vector4<f32>, b: &Vector4<f32>, c: &Vector4<f32>) -> Vector4<f32> {
det_copy!(Vector4::x(), Vector4::y(), Vector4::z(), Vector4::w(),
a.x, a.y, a.z, a.w,
b.x, b.y, b.z, b.w,
c.x, c.y, c.z, c.w )
}
Usually det!
should be used in these cases, but strangely, it causes a type recursion error,
so we use det_copy!
instead. Note, that the constructors (eg. Vector4::x()
) are executed multiple times.
To avoid this, bind the vectors to a variable first and pass in the variable instead.
There are various macros for various types of values.
det_copy!
T: Copy
T: Mul<T, Output=T>
T: Sub<T, Output=T>
T: Add<T, Output=T>
det_clone!
T: Clone
T: Mul<T, Output=T>
T: Sub<T, Output=T>
T: Add<T, Output=T>
det!
T: Mul<T, Output=T>
for<'a> &'a T: Mul<T, Output=T>
for<'a, 'b> &'a T: Mul<&'b T, Output=T>
T: Sub<T, Output=T>
T: Add<T, Output=T>