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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use core::ops::{Add, Mul};
use num_traits::real::Real;
#[inline(always)]
pub fn dot_values<T>(ax: &T, ay: &T, az: &T, bx: &T, by: &T, bz: &T) -> T
where
T: Add<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
ax * bx + ay * by + az * bz
}
#[inline]
pub fn len_values_sq<T>(x: &T, y: &T, z: &T) -> T
where
T: Add<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
dot_values(x, y, z, x, y, z)
}
#[inline]
pub fn inv_len_values<T>(x: &T, y: &T, z: &T) -> T
where
T: Real,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
let len_sq = len_values_sq(x, y, z);
if len_sq.is_zero() {
T::zero()
} else {
T::one() / len_sq.sqrt()
}
}
#[inline]
pub fn len_values<T>(x: &T, y: &T, z: &T) -> T
where
T: Real,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
let len_sq = len_values_sq(x, y, z);
if len_sq.is_zero() {
T::zero()
} else {
len_sq.sqrt()
}
}
#[inline(always)]
pub fn len_sq<T>(v: &[T; 3]) -> T
where
T: Add<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
len_values_sq(&v[0], &v[1], &v[2])
}
#[inline(always)]
pub fn dot<T>(a: &[T; 3], b: &[T; 3]) -> T
where
T: Add<T, Output = T>,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
dot_values(&a[0], &a[1], &a[2], &b[0], &b[1], &b[2])
}
#[inline(always)]
pub fn len<T>(v: &[T; 3]) -> T
where
T: Real,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
len_values(&v[0], &v[1], &v[2])
}
#[inline(always)]
pub fn inv_len<T>(v: &[T; 3]) -> T
where
T: Real,
for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
{
inv_len_values(&v[0], &v[1], &v[2])
}