graphene/auto/quaternion.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Matrix, Vec3, Vec4};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A quaternion.
10 ///
11 /// The contents of the [`Quaternion`][crate::Quaternion] structure are private
12 /// and should never be accessed directly.
13 pub struct Quaternion(BoxedInline<ffi::graphene_quaternion_t>);
14
15 match fn {
16 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_quaternion_get_type(), ptr as *mut _) as *mut ffi::graphene_quaternion_t,
17 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_quaternion_get_type(), ptr as *mut _),
18 type_ => || ffi::graphene_quaternion_get_type(),
19 }
20}
21
22impl Quaternion {
23 /// Adds two [`Quaternion`][crate::Quaternion] `self` and `b`.
24 /// ## `b`
25 /// a [`Quaternion`][crate::Quaternion]
26 ///
27 /// # Returns
28 ///
29 ///
30 /// ## `res`
31 /// the result of the operation
32 #[doc(alias = "graphene_quaternion_add")]
33 #[must_use]
34 pub fn add(&self, b: &Quaternion) -> Quaternion {
35 unsafe {
36 let mut res = Quaternion::uninitialized();
37 ffi::graphene_quaternion_add(
38 self.to_glib_none().0,
39 b.to_glib_none().0,
40 res.to_glib_none_mut().0,
41 );
42 res
43 }
44 }
45
46 /// Computes the dot product of two [`Quaternion`][crate::Quaternion].
47 /// ## `b`
48 /// a [`Quaternion`][crate::Quaternion]
49 ///
50 /// # Returns
51 ///
52 /// the value of the dot products
53 #[doc(alias = "graphene_quaternion_dot")]
54 pub fn dot(&self, b: &Quaternion) -> f32 {
55 unsafe { ffi::graphene_quaternion_dot(self.to_glib_none().0, b.to_glib_none().0) }
56 }
57
58 #[doc(alias = "graphene_quaternion_equal")]
59 fn equal(&self, b: &Quaternion) -> bool {
60 unsafe { ffi::graphene_quaternion_equal(self.to_glib_none().0, b.to_glib_none().0) }
61 }
62
63 /// Inverts a [`Quaternion`][crate::Quaternion], and returns the conjugate
64 /// quaternion of `self`.
65 ///
66 /// # Returns
67 ///
68 ///
69 /// ## `res`
70 /// return location for the inverted
71 /// quaternion
72 #[doc(alias = "graphene_quaternion_invert")]
73 #[must_use]
74 pub fn invert(&self) -> Quaternion {
75 unsafe {
76 let mut res = Quaternion::uninitialized();
77 ffi::graphene_quaternion_invert(self.to_glib_none().0, res.to_glib_none_mut().0);
78 res
79 }
80 }
81
82 /// Multiplies two [`Quaternion`][crate::Quaternion] `self` and `b`.
83 /// ## `b`
84 /// a [`Quaternion`][crate::Quaternion]
85 ///
86 /// # Returns
87 ///
88 ///
89 /// ## `res`
90 /// the result of the operation
91 #[doc(alias = "graphene_quaternion_multiply")]
92 #[must_use]
93 pub fn multiply(&self, b: &Quaternion) -> Quaternion {
94 unsafe {
95 let mut res = Quaternion::uninitialized();
96 ffi::graphene_quaternion_multiply(
97 self.to_glib_none().0,
98 b.to_glib_none().0,
99 res.to_glib_none_mut().0,
100 );
101 res
102 }
103 }
104
105 /// Normalizes a [`Quaternion`][crate::Quaternion].
106 ///
107 /// # Returns
108 ///
109 ///
110 /// ## `res`
111 /// return location for the normalized
112 /// quaternion
113 #[doc(alias = "graphene_quaternion_normalize")]
114 #[must_use]
115 pub fn normalize(&self) -> Quaternion {
116 unsafe {
117 let mut res = Quaternion::uninitialized();
118 ffi::graphene_quaternion_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
119 res
120 }
121 }
122
123 /// Scales all the elements of a [`Quaternion`][crate::Quaternion] `self` using
124 /// the given scalar factor.
125 /// ## `factor`
126 /// a scaling factor
127 ///
128 /// # Returns
129 ///
130 ///
131 /// ## `res`
132 /// the result of the operation
133 #[doc(alias = "graphene_quaternion_scale")]
134 #[must_use]
135 pub fn scale(&self, factor: f32) -> Quaternion {
136 unsafe {
137 let mut res = Quaternion::uninitialized();
138 ffi::graphene_quaternion_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
139 res
140 }
141 }
142
143 /// Interpolates between the two given quaternions using a spherical
144 /// linear interpolation, or [SLERP](http://en.wikipedia.org/wiki/Slerp),
145 /// using the given interpolation `factor`.
146 /// ## `b`
147 /// a [`Quaternion`][crate::Quaternion]
148 /// ## `factor`
149 /// the linear interpolation factor
150 ///
151 /// # Returns
152 ///
153 ///
154 /// ## `res`
155 /// return location for the interpolated
156 /// quaternion
157 #[doc(alias = "graphene_quaternion_slerp")]
158 #[must_use]
159 pub fn slerp(&self, b: &Quaternion, factor: f32) -> Quaternion {
160 unsafe {
161 let mut res = Quaternion::uninitialized();
162 ffi::graphene_quaternion_slerp(
163 self.to_glib_none().0,
164 b.to_glib_none().0,
165 factor,
166 res.to_glib_none_mut().0,
167 );
168 res
169 }
170 }
171
172 /// Converts a quaternion into an `angle`, `axis` pair.
173 ///
174 /// # Returns
175 ///
176 ///
177 /// ## `angle`
178 /// return location for the angle, in degrees
179 ///
180 /// ## `axis`
181 /// return location for the rotation axis
182 #[doc(alias = "graphene_quaternion_to_angle_vec3")]
183 pub fn to_angle_vec3(&self) -> (f32, Vec3) {
184 unsafe {
185 let mut angle = std::mem::MaybeUninit::uninit();
186 let mut axis = Vec3::uninitialized();
187 ffi::graphene_quaternion_to_angle_vec3(
188 self.to_glib_none().0,
189 angle.as_mut_ptr(),
190 axis.to_glib_none_mut().0,
191 );
192 (angle.assume_init(), axis)
193 }
194 }
195
196 /// Converts a [`Quaternion`][crate::Quaternion] to its corresponding rotations
197 /// on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
198 /// on each axis.
199 ///
200 /// # Returns
201 ///
202 ///
203 /// ## `deg_x`
204 /// return location for the rotation angle on
205 /// the X axis (yaw), in degrees
206 ///
207 /// ## `deg_y`
208 /// return location for the rotation angle on
209 /// the Y axis (pitch), in degrees
210 ///
211 /// ## `deg_z`
212 /// return location for the rotation angle on
213 /// the Z axis (roll), in degrees
214 #[doc(alias = "graphene_quaternion_to_angles")]
215 pub fn to_angles(&self) -> (f32, f32, f32) {
216 unsafe {
217 let mut deg_x = std::mem::MaybeUninit::uninit();
218 let mut deg_y = std::mem::MaybeUninit::uninit();
219 let mut deg_z = std::mem::MaybeUninit::uninit();
220 ffi::graphene_quaternion_to_angles(
221 self.to_glib_none().0,
222 deg_x.as_mut_ptr(),
223 deg_y.as_mut_ptr(),
224 deg_z.as_mut_ptr(),
225 );
226 (
227 deg_x.assume_init(),
228 deg_y.assume_init(),
229 deg_z.assume_init(),
230 )
231 }
232 }
233
234 /// Converts a quaternion into a transformation matrix expressing
235 /// the rotation defined by the [`Quaternion`][crate::Quaternion].
236 ///
237 /// # Returns
238 ///
239 ///
240 /// ## `m`
241 /// a [`Matrix`][crate::Matrix]
242 #[doc(alias = "graphene_quaternion_to_matrix")]
243 pub fn to_matrix(&self) -> Matrix {
244 unsafe {
245 let mut m = Matrix::uninitialized();
246 ffi::graphene_quaternion_to_matrix(self.to_glib_none().0, m.to_glib_none_mut().0);
247 m
248 }
249 }
250
251 /// Converts a [`Quaternion`][crate::Quaternion] to its corresponding rotations
252 /// on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles)
253 /// on each axis.
254 ///
255 /// # Returns
256 ///
257 ///
258 /// ## `rad_x`
259 /// return location for the rotation angle on
260 /// the X axis (yaw), in radians
261 ///
262 /// ## `rad_y`
263 /// return location for the rotation angle on
264 /// the Y axis (pitch), in radians
265 ///
266 /// ## `rad_z`
267 /// return location for the rotation angle on
268 /// the Z axis (roll), in radians
269 #[doc(alias = "graphene_quaternion_to_radians")]
270 pub fn to_radians(&self) -> (f32, f32, f32) {
271 unsafe {
272 let mut rad_x = std::mem::MaybeUninit::uninit();
273 let mut rad_y = std::mem::MaybeUninit::uninit();
274 let mut rad_z = std::mem::MaybeUninit::uninit();
275 ffi::graphene_quaternion_to_radians(
276 self.to_glib_none().0,
277 rad_x.as_mut_ptr(),
278 rad_y.as_mut_ptr(),
279 rad_z.as_mut_ptr(),
280 );
281 (
282 rad_x.assume_init(),
283 rad_y.assume_init(),
284 rad_z.assume_init(),
285 )
286 }
287 }
288
289 /// Copies the components of a [`Quaternion`][crate::Quaternion] into a
290 /// [`Vec4`][crate::Vec4].
291 ///
292 /// # Returns
293 ///
294 ///
295 /// ## `res`
296 /// return location for a
297 /// [`Vec4`][crate::Vec4]
298 #[doc(alias = "graphene_quaternion_to_vec4")]
299 pub fn to_vec4(&self) -> Vec4 {
300 unsafe {
301 let mut res = Vec4::uninitialized();
302 ffi::graphene_quaternion_to_vec4(self.to_glib_none().0, res.to_glib_none_mut().0);
303 res
304 }
305 }
306}
307
308impl PartialEq for Quaternion {
309 #[inline]
310 fn eq(&self, other: &Self) -> bool {
311 self.equal(other)
312 }
313}
314
315impl Eq for Quaternion {}