1use core::ops::Mul;
2
3use num_traits::real::Real;
4use num_traits::Zero;
5use vec3;
6
7use super::{dot, len, len_values};
8
9#[inline]
16pub fn position_mat32<'out, T>(out: &'out mut [T; 2], m: &[T; 6]) -> &'out mut [T; 2]
17where
18 T: Clone + Zero,
19{
20 out[0] = m[4].clone();
21 out[1] = m[5].clone();
22 out
23}
24#[inline]
33pub fn position_mat4<'out, T>(out: &'out mut [T; 2], m: &[T; 16]) -> &'out mut [T; 2]
34where
35 T: Clone,
36{
37 out[0] = m[12].clone();
38 out[1] = m[13].clone();
39 out
40}
41#[inline]
48pub fn scale_mat2<'out, T>(out: &'out mut [T; 2], m: &[T; 4]) -> &'out mut [T; 2]
49where
50 T: Real,
51 for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
52{
53 out[0] = len_values(&m[0], &m[2]);
54 out[1] = len_values(&m[1], &m[3]);
55 out
56}
57#[inline]
64pub fn scale_mat32<'out, T>(out: &'out mut [T; 2], m: &[T; 6]) -> &'out mut [T; 2]
65where
66 T: Real,
67 for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
68{
69 out[0] = len_values(&m[0], &m[2]);
70 out[1] = len_values(&m[1], &m[3]);
71 out
72}
73#[inline]
80pub fn scale_mat3<'out, T>(out: &'out mut [T; 2], m: &[T; 9]) -> &'out mut [T; 2]
81where
82 T: Real,
83 for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
84{
85 out[0] = vec3::len_values(&m[0], &m[3], &m[6]);
86 out[1] = vec3::len_values(&m[1], &m[4], &m[7]);
87 out
88}
89#[inline]
98pub fn scale_mat4<'out, T>(out: &'out mut [T; 2], m: &[T; 16]) -> &'out mut [T; 2]
99where
100 T: Real,
101 for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
102{
103 out[0] = vec3::len_values(&m[0], &m[4], &m[8]);
104 out[1] = vec3::len_values(&m[1], &m[5], &m[9]);
105 out
106}
107#[inline]
114pub fn angle<T>(a: &[T; 2], b: &[T; 2]) -> T
115where
116 T: Real,
117 for<'a, 'b> &'a T: Mul<&'b T, Output = T>,
118{
119 (dot(a, b) / (len(a) * len(b))).acos()
120}