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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// 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::Matrix;
use crate::Vec3;
use crate::Vec4;
use glib::translate::*;
use std::mem;

glib::wrapper! {
    /// A quaternion.
    ///
    /// The contents of the [`Quaternion`][crate::Quaternion] structure are private
    /// and should never be accessed directly.
    pub struct Quaternion(BoxedInline<ffi::graphene_quaternion_t>);

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

impl Quaternion {
    /// Adds two [`Quaternion`][crate::Quaternion] `self` and `b`.
    /// ## `b`
    /// a [`Quaternion`][crate::Quaternion]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the result of the operation
    #[doc(alias = "graphene_quaternion_add")]
    #[must_use]
    pub fn add(&self, b: &Quaternion) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_add(
                self.to_glib_none().0,
                b.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Computes the dot product of two [`Quaternion`][crate::Quaternion].
    /// ## `b`
    /// a [`Quaternion`][crate::Quaternion]
    ///
    /// # Returns
    ///
    /// the value of the dot products
    #[doc(alias = "graphene_quaternion_dot")]
    pub fn dot(&self, b: &Quaternion) -> f32 {
        unsafe { ffi::graphene_quaternion_dot(self.to_glib_none().0, b.to_glib_none().0) }
    }

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

    /// Inverts a [`Quaternion`][crate::Quaternion], and returns the conjugate
    /// quaternion of `self`.
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the inverted
    ///  quaternion
    #[doc(alias = "graphene_quaternion_invert")]
    #[must_use]
    pub fn invert(&self) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_invert(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Multiplies two [`Quaternion`][crate::Quaternion] `self` and `b`.
    /// ## `b`
    /// a [`Quaternion`][crate::Quaternion]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the result of the operation
    #[doc(alias = "graphene_quaternion_multiply")]
    #[must_use]
    pub fn multiply(&self, b: &Quaternion) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_multiply(
                self.to_glib_none().0,
                b.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Normalizes a [`Quaternion`][crate::Quaternion].
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the normalized
    ///  quaternion
    #[doc(alias = "graphene_quaternion_normalize")]
    #[must_use]
    pub fn normalize(&self) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Scales all the elements of a [`Quaternion`][crate::Quaternion] `self` using
    /// the given scalar factor.
    /// ## `factor`
    /// a scaling factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the result of the operation
    #[doc(alias = "graphene_quaternion_scale")]
    #[must_use]
    pub fn scale(&self, factor: f32) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
            res
        }
    }

    /// Interpolates between the two given quaternions using a spherical
    /// linear interpolation, or [SLERP](http://en.wikipedia.org/wiki/Slerp),
    /// using the given interpolation `factor`.
    /// ## `b`
    /// a [`Quaternion`][crate::Quaternion]
    /// ## `factor`
    /// the linear interpolation factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the interpolated
    ///  quaternion
    #[doc(alias = "graphene_quaternion_slerp")]
    #[must_use]
    pub fn slerp(&self, b: &Quaternion, factor: f32) -> Quaternion {
        unsafe {
            let mut res = Quaternion::uninitialized();
            ffi::graphene_quaternion_slerp(
                self.to_glib_none().0,
                b.to_glib_none().0,
                factor,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Converts a quaternion into an `angle`, `axis` pair.
    ///
    /// # Returns
    ///
    ///
    /// ## `angle`
    /// return location for the angle, in degrees
    ///
    /// ## `axis`
    /// return location for the rotation axis
    #[doc(alias = "graphene_quaternion_to_angle_vec3")]
    pub fn to_angle_vec3(&self) -> (f32, Vec3) {
        unsafe {
            let mut angle = mem::MaybeUninit::uninit();
            let mut axis = Vec3::uninitialized();
            ffi::graphene_quaternion_to_angle_vec3(
                self.to_glib_none().0,
                angle.as_mut_ptr(),
                axis.to_glib_none_mut().0,
            );
            let angle = angle.assume_init();
            (angle, axis)
        }
    }

    /// Converts a [`Quaternion`][crate::Quaternion] to its corresponding rotations
    /// on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
    /// on each axis.
    ///
    /// # Returns
    ///
    ///
    /// ## `deg_x`
    /// return location for the rotation angle on
    ///  the X axis (yaw), in degrees
    ///
    /// ## `deg_y`
    /// return location for the rotation angle on
    ///  the Y axis (pitch), in degrees
    ///
    /// ## `deg_z`
    /// return location for the rotation angle on
    ///  the Z axis (roll), in degrees
    #[doc(alias = "graphene_quaternion_to_angles")]
    pub fn to_angles(&self) -> (f32, f32, f32) {
        unsafe {
            let mut deg_x = mem::MaybeUninit::uninit();
            let mut deg_y = mem::MaybeUninit::uninit();
            let mut deg_z = mem::MaybeUninit::uninit();
            ffi::graphene_quaternion_to_angles(
                self.to_glib_none().0,
                deg_x.as_mut_ptr(),
                deg_y.as_mut_ptr(),
                deg_z.as_mut_ptr(),
            );
            let deg_x = deg_x.assume_init();
            let deg_y = deg_y.assume_init();
            let deg_z = deg_z.assume_init();
            (deg_x, deg_y, deg_z)
        }
    }

    /// Converts a quaternion into a transformation matrix expressing
    /// the rotation defined by the [`Quaternion`][crate::Quaternion].
    ///
    /// # Returns
    ///
    ///
    /// ## `m`
    /// a [`Matrix`][crate::Matrix]
    #[doc(alias = "graphene_quaternion_to_matrix")]
    pub fn to_matrix(&self) -> Matrix {
        unsafe {
            let mut m = Matrix::uninitialized();
            ffi::graphene_quaternion_to_matrix(self.to_glib_none().0, m.to_glib_none_mut().0);
            m
        }
    }

    /// Converts a [`Quaternion`][crate::Quaternion] to its corresponding rotations
    /// on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
    /// on each axis.
    ///
    /// # Returns
    ///
    ///
    /// ## `rad_x`
    /// return location for the rotation angle on
    ///  the X axis (yaw), in radians
    ///
    /// ## `rad_y`
    /// return location for the rotation angle on
    ///  the Y axis (pitch), in radians
    ///
    /// ## `rad_z`
    /// return location for the rotation angle on
    ///  the Z axis (roll), in radians
    #[doc(alias = "graphene_quaternion_to_radians")]
    pub fn to_radians(&self) -> (f32, f32, f32) {
        unsafe {
            let mut rad_x = mem::MaybeUninit::uninit();
            let mut rad_y = mem::MaybeUninit::uninit();
            let mut rad_z = mem::MaybeUninit::uninit();
            ffi::graphene_quaternion_to_radians(
                self.to_glib_none().0,
                rad_x.as_mut_ptr(),
                rad_y.as_mut_ptr(),
                rad_z.as_mut_ptr(),
            );
            let rad_x = rad_x.assume_init();
            let rad_y = rad_y.assume_init();
            let rad_z = rad_z.assume_init();
            (rad_x, rad_y, rad_z)
        }
    }

    /// Copies the components of a [`Quaternion`][crate::Quaternion] into a
    /// [`Vec4`][crate::Vec4].
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for a
    ///  [`Vec4`][crate::Vec4]
    #[doc(alias = "graphene_quaternion_to_vec4")]
    pub fn to_vec4(&self) -> Vec4 {
        unsafe {
            let mut res = Vec4::uninitialized();
            ffi::graphene_quaternion_to_vec4(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }
}

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

impl Eq for Quaternion {}