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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::EulerOrder;
use crate::Matrix;
use crate::Quaternion;
use crate::Vec3;
use glib::translate::*;

glib::wrapper! {
    /// Describe a rotation using Euler angles.
    ///
    /// The contents of the [`Euler`][crate::Euler] structure are private
    /// and should never be accessed directly.
    pub struct Euler(BoxedInline<ffi::graphene_euler_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_euler_get_type(), ptr as *mut _) as *mut ffi::graphene_euler_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_euler_get_type(), ptr as *mut _),
        type_ => || ffi::graphene_euler_get_type(),
    }
}

impl Euler {
    #[doc(alias = "graphene_euler_equal")]
    fn equal(&self, b: &Euler) -> bool {
        unsafe { ffi::graphene_euler_equal(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Retrieves the first component of the Euler angle vector,
    /// depending on the order of rotation.
    ///
    /// See also: [`x()`][Self::x()]
    ///
    /// # Returns
    ///
    /// the first component of the Euler angle vector, in radians
    #[doc(alias = "graphene_euler_get_alpha")]
    #[doc(alias = "get_alpha")]
    pub fn alpha(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_alpha(self.to_glib_none().0) }
    }

    /// Retrieves the second component of the Euler angle vector,
    /// depending on the order of rotation.
    ///
    /// See also: [`y()`][Self::y()]
    ///
    /// # Returns
    ///
    /// the second component of the Euler angle vector, in radians
    #[doc(alias = "graphene_euler_get_beta")]
    #[doc(alias = "get_beta")]
    pub fn beta(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_beta(self.to_glib_none().0) }
    }

    /// Retrieves the third component of the Euler angle vector,
    /// depending on the order of rotation.
    ///
    /// See also: [`z()`][Self::z()]
    ///
    /// # Returns
    ///
    /// the third component of the Euler angle vector, in radians
    #[doc(alias = "graphene_euler_get_gamma")]
    #[doc(alias = "get_gamma")]
    pub fn gamma(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_gamma(self.to_glib_none().0) }
    }

    /// Retrieves the order used to apply the rotations described in the
    /// [`Euler`][crate::Euler] structure, when converting to and from other
    /// structures, like [`Quaternion`][crate::Quaternion] and [`Matrix`][crate::Matrix].
    ///
    /// This function does not return the [`EulerOrder::Default`][crate::EulerOrder::Default]
    /// enumeration value; it will return the effective order of rotation
    /// instead.
    ///
    /// # Returns
    ///
    /// the order used to apply the rotations
    #[doc(alias = "graphene_euler_get_order")]
    #[doc(alias = "get_order")]
    pub fn order(&self) -> EulerOrder {
        unsafe { from_glib(ffi::graphene_euler_get_order(self.to_glib_none().0)) }
    }

    /// Retrieves the rotation angle on the X axis, in degrees.
    ///
    /// # Returns
    ///
    /// the rotation angle
    #[doc(alias = "graphene_euler_get_x")]
    #[doc(alias = "get_x")]
    pub fn x(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_x(self.to_glib_none().0) }
    }

    /// Retrieves the rotation angle on the Y axis, in degrees.
    ///
    /// # Returns
    ///
    /// the rotation angle
    #[doc(alias = "graphene_euler_get_y")]
    #[doc(alias = "get_y")]
    pub fn y(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_y(self.to_glib_none().0) }
    }

    /// Retrieves the rotation angle on the Z axis, in degrees.
    ///
    /// # Returns
    ///
    /// the rotation angle
    #[doc(alias = "graphene_euler_get_z")]
    #[doc(alias = "get_z")]
    pub fn z(&self) -> f32 {
        unsafe { ffi::graphene_euler_get_z(self.to_glib_none().0) }
    }

    /// Reorders a [`Euler`][crate::Euler] using `order`.
    ///
    /// This function is equivalent to creating a [`Quaternion`][crate::Quaternion] from the
    /// given [`Euler`][crate::Euler], and then converting the quaternion into another
    /// [`Euler`][crate::Euler].
    /// ## `order`
    /// the new order
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the reordered
    ///  [`Euler`][crate::Euler]
    #[doc(alias = "graphene_euler_reorder")]
    #[must_use]
    pub fn reorder(&self, order: EulerOrder) -> Euler {
        unsafe {
            let mut res = Euler::uninitialized();
            ffi::graphene_euler_reorder(
                self.to_glib_none().0,
                order.into_glib(),
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Converts a [`Euler`][crate::Euler] into a transformation matrix expressing
    /// the extrinsic composition of rotations described by the Euler angles.
    ///
    /// The rotations are applied over the reference frame axes in the order
    /// associated with the [`Euler`][crate::Euler]; for instance, if the order
    /// used to initialize `self` is [`EulerOrder::Xyz`][crate::EulerOrder::Xyz]:
    ///
    ///  * the first rotation moves the body around the X axis with
    ///  an angle φ
    ///  * the second rotation moves the body around the Y axis with
    ///  an angle of ϑ
    ///  * the third rotation moves the body around the Z axis with
    ///  an angle of ψ
    ///
    /// The rotation sign convention is right-handed, to preserve compatibility
    /// between Euler-based, quaternion-based, and angle-axis-based rotations.
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for a [`Matrix`][crate::Matrix]
    #[doc(alias = "graphene_euler_to_matrix")]
    pub fn to_matrix(&self) -> Matrix {
        unsafe {
            let mut res = Matrix::uninitialized();
            ffi::graphene_euler_to_matrix(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Converts a [`Euler`][crate::Euler] into a [`Quaternion`][crate::Quaternion].
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for a [`Quaternion`][crate::Quaternion]
    #[doc(alias = "graphene_euler_to_quaternion")]
    pub fn to_quaternion(&self) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_euler_to_quaternion(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Retrieves the angles of a [`Euler`][crate::Euler] and initializes a
    /// [`Vec3`][crate::Vec3] with them.
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for a [`Vec3`][crate::Vec3]
    #[doc(alias = "graphene_euler_to_vec3")]
    pub fn to_vec3(&self) -> Vec3 {
        unsafe {
            let mut res = Vec3::uninitialized();
            ffi::graphene_euler_to_vec3(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }
}

impl PartialEq for Euler {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Euler {}