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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use super::TranslationRotationScale3D;

use crate::datatypes::{Rotation3D, Scale3D, Vec3D};

impl TranslationRotationScale3D {
    /// The identity transform, representing no transform.
    pub const IDENTITY: Self = Self {
        translation: None,
        rotation: None,
        scale: None,
        from_parent: false,
    };

    /// From a translation.
    #[inline]
    pub fn from_translation(translation: impl Into<Vec3D>) -> Self {
        Self {
            translation: Some(translation.into()),
            rotation: None,
            scale: None,
            from_parent: false,
        }
    }

    /// From a rotation
    #[inline]
    pub fn from_rotation(rotation: impl Into<Rotation3D>) -> Self {
        Self {
            translation: None,
            rotation: Some(rotation.into()),
            scale: None,
            from_parent: false,
        }
    }

    /// From a rotation & scale
    #[inline]
    pub fn from_scale(scale: impl Into<Scale3D>) -> Self {
        Self {
            translation: None,
            rotation: None,
            scale: Some(scale.into()),
            from_parent: false,
        }
    }

    /// From a translation applied after a rotation, known as a rigid transformation.
    #[inline]
    pub fn from_translation_rotation(
        translation: impl Into<Vec3D>,
        rotation: impl Into<Rotation3D>,
    ) -> Self {
        Self {
            translation: Some(translation.into()),
            rotation: Some(rotation.into()),
            scale: None,
            from_parent: false,
        }
    }

    /// From a rotation & scale
    #[inline]
    pub fn from_rotation_scale(rotation: impl Into<Rotation3D>, scale: impl Into<Scale3D>) -> Self {
        Self {
            translation: None,
            rotation: Some(rotation.into()),
            scale: Some(scale.into()),
            from_parent: false,
        }
    }

    /// From a translation, applied after a rotation & scale, known as an affine transformation.
    #[inline]
    pub fn from_translation_rotation_scale(
        translation: impl Into<Vec3D>,
        rotation: impl Into<Rotation3D>,
        scale: impl Into<Scale3D>,
    ) -> Self {
        Self {
            translation: Some(translation.into()),
            rotation: Some(rotation.into()),
            scale: Some(scale.into()),
            from_parent: false,
        }
    }

    /// Indicate that this transform is from parent to child.
    /// This is the opposite of the default, which is from child to parent.
    #[allow(clippy::wrong_self_convention)]
    #[inline]
    pub fn from_parent(mut self) -> Self {
        self.from_parent = true;
        self
    }
}

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

impl From<Vec3D> for TranslationRotationScale3D {
    #[inline]
    fn from(v: Vec3D) -> Self {
        Self {
            translation: Some(v),
            ..Default::default()
        }
    }
}

#[cfg(feature = "glam")]
impl From<glam::Vec3> for TranslationRotationScale3D {
    #[inline]
    fn from(v: glam::Vec3) -> Self {
        Self {
            translation: Some(v.into()),
            ..Default::default()
        }
    }
}

impl From<Rotation3D> for TranslationRotationScale3D {
    #[inline]
    fn from(v: Rotation3D) -> Self {
        Self {
            rotation: Some(v),
            ..Default::default()
        }
    }
}

impl From<Scale3D> for TranslationRotationScale3D {
    #[inline]
    fn from(v: Scale3D) -> Self {
        Self {
            scale: Some(v),
            ..Default::default()
        }
    }
}