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