array_matrix/vector/
cross.rs1use std::ops::Add;
2
3use crate::{Det, Vector};
4
5pub trait Cross<Rhs: Vector>: Vector
6where Self::Output: Vector
7{
8 type Output;
9
10 fn cross(self, rhs: Rhs) -> Self::Output;
27}
28
29impl<F> Cross<[F; 3]> for [F; 3]
30where
31 Self: Vector,
32 [<[[F; 2]; 2] as Det>::Output; 3]: Vector,
33 [[F; 2]; 2]: Det,
34 F: Clone
35{
36 type Output = [<[[F; 2]; 2] as Det>::Output; 3];
37 fn cross(self, rhs: [F; 3]) -> Self::Output {
38 use array_init::array_init;
39 array_init(|i| [
40 [self[(1 + i)%3].clone(), self[(2 + i)%3].clone()],
41 [rhs[(1 + i)%3].clone(), rhs[(2 + i)%3].clone()]
42 ].det())
43 }
44}
45
46impl<F> Cross<[F; 7]> for [F; 7]
47where
48 Self: Vector,
49 [<<<[[F; 2]; 2] as Det>::Output
50 as Add<<[[F; 2]; 2] as Det>::Output>>::Output
51 as Add<<[[F; 2]; 2] as Det>::Output>>::Output; 7]: Vector,
52 [[F; 2]; 2]: Det,
53 <[[F; 2]; 2] as Det>::Output: Add,
54 <<[[F; 2]; 2] as Det>::Output as Add<<[[F; 2]; 2] as Det>::Output>>::Output:
55 Add<<[[F; 2]; 2] as Det>::Output>,
56 F: Clone
57{
58 type Output = [
59 <<<[[F; 2]; 2] as Det>::Output
60 as Add<<[[F; 2]; 2] as Det>::Output>>::Output
61 as Add<<[[F; 2]; 2] as Det>::Output>>::Output; 7];
62 fn cross(self, rhs: [F; 7]) -> Self::Output {
63 use array_init::array_init;
64 array_init(|i| [
65 [self[(1 + i)%7].clone(), self[(3 + i)%7].clone()],
66 [rhs[(1 + i)%7].clone(), rhs[(3 + i)%7].clone()]
67 ].det() + [
68 [self[(2 + i)%7].clone(), self[(6 + i)%7].clone()],
69 [rhs[(2 + i)%7].clone(), rhs[(6 + i)%7].clone()]
70 ].det() + [
71 [self[(4 + i)%7].clone(), self[(5 + i)%7].clone()],
72 [rhs[(4 + i)%7].clone(), rhs[(5 + i)%7].clone()]
73 ].det())
74 }
75}