conspire/math/tensor/rank_1/cross/
mod.rs1#[cfg(test)]
2mod test;
3
4use super::TensorRank1;
5use crate::units::UnitMul;
6
7pub trait CrossProduct<T> {
9 type Output;
11 fn cross(self, other: T) -> Self::Output;
13}
14
15impl<I, U, V> CrossProduct<TensorRank1<3, I, V>> for &TensorRank1<3, I, U>
16where
17 U: UnitMul<V>,
18{
19 type Output = TensorRank1<3, I, <U as UnitMul<V>>::Output>;
20 fn cross(self, other: TensorRank1<3, I, V>) -> Self::Output {
21 TensorRank1::from([
22 self[1] * other[2] - self[2] * other[1],
23 self[2] * other[0] - self[0] * other[2],
24 self[0] * other[1] - self[1] * other[0],
25 ])
26 }
27}
28
29impl<'a, I, U, V> CrossProduct<&'a TensorRank1<3, I, V>> for &TensorRank1<3, I, U>
30where
31 U: UnitMul<V>,
32{
33 type Output = TensorRank1<3, I, <U as UnitMul<V>>::Output>;
34 fn cross(self, other: &'a TensorRank1<3, I, V>) -> Self::Output {
35 TensorRank1::from([
36 self[1] * other[2] - self[2] * other[1],
37 self[2] * other[0] - self[0] * other[2],
38 self[0] * other[1] - self[1] * other[0],
39 ])
40 }
41}