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
use crate::ops::Skew;
use crate::ops::{Norm, NormSquared};
use math::{BaseFloat, InnerSpace, Matrix3, Vector3};
use num_traits::Zero;
use std::ops::Neg;
impl<T: BaseFloat> Norm for Vector3<T> {
type Output = T;
fn norm(self) -> T {
self.magnitude()
}
}
impl<T: BaseFloat> NormSquared for Vector3<T> {
type Output = T;
fn norm_squared(self) -> T {
self.magnitude2()
}
}
impl<T: Zero + Copy + Neg<Output = T>> Skew for [T; 3] {
type Output = [[T; 3]; 3];
fn skew(self) -> Self::Output {
[
[T::zero(), self[2], -self[1]],
[-self[2], T::zero(), self[0]],
[self[1], -self[0], T::zero()],
]
}
}
impl<T: Zero + Copy + Neg<Output = T>> Skew for Vector3<T> {
type Output = Matrix3<T>;
fn skew(self) -> Self::Output {
let arr: [T; 3] = self.into();
Matrix3::from(arr.skew())
}
}
#[cfg(test)]
mod tests {
use super::*;
use math::{Matrix3, Vector3};
#[test]
fn skew() {
let a = [1.0, 2.0, 3.0];
let b = [4.0, 5.0, 6.0];
assert_eq!(
Matrix3::from(a.skew()) * Vector3::from(b),
Vector3::from(a).cross(Vector3::from(b))
);
}
}