1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use core::ops::{Mul, Sub};
#[inline]
pub fn cross<'out, T>(out: &'out mut [T; 3], a: &[T; 3], b: &[T; 3]) -> &'out mut [T; 3]
where
T: Sub<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
out[0] = &a[1] * &b[2] - &a[2] * &b[1];
out[1] = &a[2] * &b[0] - &a[0] * &b[2];
out[2] = &a[0] * &b[1] - &a[1] * &b[0];
out
}
#[inline]
pub fn cross_mut<'out, T>(a: &'out mut [T; 3], b: &[T; 3]) -> &'out mut [T; 3]
where
T: Clone + Sub<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
let tmp = a.clone();
cross(a, &tmp.clone(), b)
}