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
use super::Quaternion;

// ---

impl Default for Quaternion {
    #[inline]
    fn default() -> Self {
        Self::IDENTITY
    }
}

impl Quaternion {
    /// The identity quaternion representing no rotation.
    pub const IDENTITY: Self = Self([0.0, 0.0, 0.0, 1.0]);

    /// From XYZW.
    #[inline]
    pub const fn from_xyzw(xyzw: [f32; 4]) -> Self {
        Self(xyzw)
    }

    /// From WXYZ.
    #[inline]
    pub const fn from_wxyz([w, x, y, z]: [f32; 4]) -> Self {
        Self([x, y, z, w])
    }
}

#[cfg(feature = "glam")]
impl From<Quaternion> for glam::Quat {
    #[inline]
    fn from(q: Quaternion) -> Self {
        let [x, y, z, w] = q.0;
        Self::from_xyzw(x, y, z, w).normalize()
    }
}

#[cfg(feature = "glam")]
impl From<glam::Quat> for Quaternion {
    #[inline]
    fn from(q: glam::Quat) -> Self {
        Self::from_xyzw(q.to_array())
    }
}

#[cfg(feature = "mint")]
impl From<Quaternion> for mint::Quaternion<f32> {
    #[inline]
    fn from(val: Quaternion) -> Self {
        val.0.into()
    }
}

#[cfg(feature = "mint")]
impl From<mint::Quaternion<f32>> for Quaternion {
    #[inline]
    fn from(val: mint::Quaternion<f32>) -> Self {
        Self::from_xyzw(val.into())
    }
}