graphene/auto/vec3.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, Vec2, Vec4};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A structure capable of holding a vector with three dimensions: x, y, and z.
10 ///
11 /// The contents of the [`Vec3`][crate::Vec3] structure are private and should
12 /// never be accessed directly.
13 pub struct Vec3(BoxedInline<ffi::graphene_vec3_t>);
14
15 match fn {
16 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_vec3_get_type(), ptr as *mut _) as *mut ffi::graphene_vec3_t,
17 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_vec3_get_type(), ptr as *mut _),
18 type_ => || ffi::graphene_vec3_get_type(),
19 }
20}
21
22impl Vec3 {
23 /// Adds each component of the two given vectors.
24 /// ## `b`
25 /// a [`Vec3`][crate::Vec3]
26 ///
27 /// # Returns
28 ///
29 ///
30 /// ## `res`
31 /// return location for the resulting vector
32 #[doc(alias = "graphene_vec3_add")]
33 #[must_use]
34 pub fn add(&self, b: &Vec3) -> Vec3 {
35 unsafe {
36 let mut res = Vec3::uninitialized();
37 ffi::graphene_vec3_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 cross product of the two given vectors.
47 /// ## `b`
48 /// a [`Vec3`][crate::Vec3]
49 ///
50 /// # Returns
51 ///
52 ///
53 /// ## `res`
54 /// return location for the resulting vector
55 #[doc(alias = "graphene_vec3_cross")]
56 #[must_use]
57 pub fn cross(&self, b: &Vec3) -> Vec3 {
58 unsafe {
59 let mut res = Vec3::uninitialized();
60 ffi::graphene_vec3_cross(
61 self.to_glib_none().0,
62 b.to_glib_none().0,
63 res.to_glib_none_mut().0,
64 );
65 res
66 }
67 }
68
69 /// Divides each component of the first operand `self` by the corresponding
70 /// component of the second operand `b`, and places the results into the
71 /// vector `res`.
72 /// ## `b`
73 /// a [`Vec3`][crate::Vec3]
74 ///
75 /// # Returns
76 ///
77 ///
78 /// ## `res`
79 /// return location for the resulting vector
80 #[doc(alias = "graphene_vec3_divide")]
81 #[must_use]
82 pub fn divide(&self, b: &Vec3) -> Vec3 {
83 unsafe {
84 let mut res = Vec3::uninitialized();
85 ffi::graphene_vec3_divide(
86 self.to_glib_none().0,
87 b.to_glib_none().0,
88 res.to_glib_none_mut().0,
89 );
90 res
91 }
92 }
93
94 /// Computes the dot product of the two given vectors.
95 /// ## `b`
96 /// a [`Vec3`][crate::Vec3]
97 ///
98 /// # Returns
99 ///
100 /// the value of the dot product
101 #[doc(alias = "graphene_vec3_dot")]
102 pub fn dot(&self, b: &Vec3) -> f32 {
103 unsafe { ffi::graphene_vec3_dot(self.to_glib_none().0, b.to_glib_none().0) }
104 }
105
106 #[doc(alias = "graphene_vec3_equal")]
107 fn equal(&self, v2: &Vec3) -> bool {
108 unsafe { ffi::graphene_vec3_equal(self.to_glib_none().0, v2.to_glib_none().0) }
109 }
110
111 /// Retrieves the first component of the given vector `self`.
112 ///
113 /// # Returns
114 ///
115 /// the value of the first component of the vector
116 #[doc(alias = "graphene_vec3_get_x")]
117 #[doc(alias = "get_x")]
118 pub fn x(&self) -> f32 {
119 unsafe { ffi::graphene_vec3_get_x(self.to_glib_none().0) }
120 }
121
122 /// Creates a [`Vec2`][crate::Vec2] that contains the first and second
123 /// components of the given [`Vec3`][crate::Vec3].
124 ///
125 /// # Returns
126 ///
127 ///
128 /// ## `res`
129 /// return location for a [`Vec2`][crate::Vec2]
130 #[doc(alias = "graphene_vec3_get_xy")]
131 #[doc(alias = "get_xy")]
132 pub fn xy(&self) -> Vec2 {
133 unsafe {
134 let mut res = Vec2::uninitialized();
135 ffi::graphene_vec3_get_xy(self.to_glib_none().0, res.to_glib_none_mut().0);
136 res
137 }
138 }
139
140 /// Creates a [`Vec3`][crate::Vec3] that contains the first two components of
141 /// the given [`Vec3`][crate::Vec3], and the third component set to 0.
142 ///
143 /// # Returns
144 ///
145 ///
146 /// ## `res`
147 /// return location for a [`Vec3`][crate::Vec3]
148 #[doc(alias = "graphene_vec3_get_xy0")]
149 #[doc(alias = "get_xy0")]
150 #[must_use]
151 pub fn xy0(&self) -> Vec3 {
152 unsafe {
153 let mut res = Vec3::uninitialized();
154 ffi::graphene_vec3_get_xy0(self.to_glib_none().0, res.to_glib_none_mut().0);
155 res
156 }
157 }
158
159 /// Converts a [`Vec3`][crate::Vec3] in a [`Vec4`][crate::Vec4] using 0.0
160 /// as the value for the fourth component of the resulting vector.
161 ///
162 /// # Returns
163 ///
164 ///
165 /// ## `res`
166 /// return location for the vector
167 #[doc(alias = "graphene_vec3_get_xyz0")]
168 #[doc(alias = "get_xyz0")]
169 pub fn xyz0(&self) -> Vec4 {
170 unsafe {
171 let mut res = Vec4::uninitialized();
172 ffi::graphene_vec3_get_xyz0(self.to_glib_none().0, res.to_glib_none_mut().0);
173 res
174 }
175 }
176
177 /// Converts a [`Vec3`][crate::Vec3] in a [`Vec4`][crate::Vec4] using 1.0
178 /// as the value for the fourth component of the resulting vector.
179 ///
180 /// # Returns
181 ///
182 ///
183 /// ## `res`
184 /// return location for the vector
185 #[doc(alias = "graphene_vec3_get_xyz1")]
186 #[doc(alias = "get_xyz1")]
187 pub fn xyz1(&self) -> Vec4 {
188 unsafe {
189 let mut res = Vec4::uninitialized();
190 ffi::graphene_vec3_get_xyz1(self.to_glib_none().0, res.to_glib_none_mut().0);
191 res
192 }
193 }
194
195 /// Converts a [`Vec3`][crate::Vec3] in a [`Vec4`][crate::Vec4] using `w` as
196 /// the value of the fourth component of the resulting vector.
197 /// ## `w`
198 /// the value of the W component
199 ///
200 /// # Returns
201 ///
202 ///
203 /// ## `res`
204 /// return location for the vector
205 #[doc(alias = "graphene_vec3_get_xyzw")]
206 #[doc(alias = "get_xyzw")]
207 pub fn xyzw(&self, w: f32) -> Vec4 {
208 unsafe {
209 let mut res = Vec4::uninitialized();
210 ffi::graphene_vec3_get_xyzw(self.to_glib_none().0, w, res.to_glib_none_mut().0);
211 res
212 }
213 }
214
215 /// Retrieves the second component of the given vector `self`.
216 ///
217 /// # Returns
218 ///
219 /// the value of the second component of the vector
220 #[doc(alias = "graphene_vec3_get_y")]
221 #[doc(alias = "get_y")]
222 pub fn y(&self) -> f32 {
223 unsafe { ffi::graphene_vec3_get_y(self.to_glib_none().0) }
224 }
225
226 /// Retrieves the third component of the given vector `self`.
227 ///
228 /// # Returns
229 ///
230 /// the value of the third component of the vector
231 #[doc(alias = "graphene_vec3_get_z")]
232 #[doc(alias = "get_z")]
233 pub fn z(&self) -> f32 {
234 unsafe { ffi::graphene_vec3_get_z(self.to_glib_none().0) }
235 }
236
237 /// Linearly interpolates `self` and `v2` using the given `factor`.
238 /// ## `v2`
239 /// a [`Vec3`][crate::Vec3]
240 /// ## `factor`
241 /// the interpolation factor
242 ///
243 /// # Returns
244 ///
245 ///
246 /// ## `res`
247 /// the interpolated vector
248 #[doc(alias = "graphene_vec3_interpolate")]
249 #[must_use]
250 pub fn interpolate(&self, v2: &Vec3, factor: f64) -> Vec3 {
251 unsafe {
252 let mut res = Vec3::uninitialized();
253 ffi::graphene_vec3_interpolate(
254 self.to_glib_none().0,
255 v2.to_glib_none().0,
256 factor,
257 res.to_glib_none_mut().0,
258 );
259 res
260 }
261 }
262
263 /// Retrieves the length of the given vector `self`.
264 ///
265 /// # Returns
266 ///
267 /// the value of the length of the vector
268 #[doc(alias = "graphene_vec3_length")]
269 pub fn length(&self) -> f32 {
270 unsafe { ffi::graphene_vec3_length(self.to_glib_none().0) }
271 }
272
273 /// Compares each component of the two given vectors and creates a
274 /// vector that contains the maximum values.
275 /// ## `b`
276 /// a [`Vec3`][crate::Vec3]
277 ///
278 /// # Returns
279 ///
280 ///
281 /// ## `res`
282 /// return location for the result vector
283 #[doc(alias = "graphene_vec3_max")]
284 #[must_use]
285 pub fn max(&self, b: &Vec3) -> Vec3 {
286 unsafe {
287 let mut res = Vec3::uninitialized();
288 ffi::graphene_vec3_max(
289 self.to_glib_none().0,
290 b.to_glib_none().0,
291 res.to_glib_none_mut().0,
292 );
293 res
294 }
295 }
296
297 /// Compares each component of the two given vectors and creates a
298 /// vector that contains the minimum values.
299 /// ## `b`
300 /// a [`Vec3`][crate::Vec3]
301 ///
302 /// # Returns
303 ///
304 ///
305 /// ## `res`
306 /// return location for the result vector
307 #[doc(alias = "graphene_vec3_min")]
308 #[must_use]
309 pub fn min(&self, b: &Vec3) -> Vec3 {
310 unsafe {
311 let mut res = Vec3::uninitialized();
312 ffi::graphene_vec3_min(
313 self.to_glib_none().0,
314 b.to_glib_none().0,
315 res.to_glib_none_mut().0,
316 );
317 res
318 }
319 }
320
321 /// Multiplies each component of the two given vectors.
322 /// ## `b`
323 /// a [`Vec3`][crate::Vec3]
324 ///
325 /// # Returns
326 ///
327 ///
328 /// ## `res`
329 /// return location for the resulting vector
330 #[doc(alias = "graphene_vec3_multiply")]
331 #[must_use]
332 pub fn multiply(&self, b: &Vec3) -> Vec3 {
333 unsafe {
334 let mut res = Vec3::uninitialized();
335 ffi::graphene_vec3_multiply(
336 self.to_glib_none().0,
337 b.to_glib_none().0,
338 res.to_glib_none_mut().0,
339 );
340 res
341 }
342 }
343
344 /// Compares the two given [`Vec3`][crate::Vec3] vectors and checks
345 /// whether their values are within the given `epsilon`.
346 /// ## `v2`
347 /// a [`Vec3`][crate::Vec3]
348 /// ## `epsilon`
349 /// the threshold between the two vectors
350 ///
351 /// # Returns
352 ///
353 /// `true` if the two vectors are near each other
354 #[doc(alias = "graphene_vec3_near")]
355 pub fn near(&self, v2: &Vec3, epsilon: f32) -> bool {
356 unsafe { ffi::graphene_vec3_near(self.to_glib_none().0, v2.to_glib_none().0, epsilon) }
357 }
358
359 /// Negates the given [`Vec3`][crate::Vec3].
360 ///
361 /// # Returns
362 ///
363 ///
364 /// ## `res`
365 /// return location for the result vector
366 #[doc(alias = "graphene_vec3_negate")]
367 #[must_use]
368 pub fn negate(&self) -> Vec3 {
369 unsafe {
370 let mut res = Vec3::uninitialized();
371 ffi::graphene_vec3_negate(self.to_glib_none().0, res.to_glib_none_mut().0);
372 res
373 }
374 }
375
376 /// Normalizes the given [`Vec3`][crate::Vec3].
377 ///
378 /// # Returns
379 ///
380 ///
381 /// ## `res`
382 /// return location for the normalized vector
383 #[doc(alias = "graphene_vec3_normalize")]
384 #[must_use]
385 pub fn normalize(&self) -> Vec3 {
386 unsafe {
387 let mut res = Vec3::uninitialized();
388 ffi::graphene_vec3_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
389 res
390 }
391 }
392
393 /// Multiplies all components of the given vector with the given scalar `factor`.
394 /// ## `factor`
395 /// the scalar factor
396 ///
397 /// # Returns
398 ///
399 ///
400 /// ## `res`
401 /// return location for the result vector
402 #[doc(alias = "graphene_vec3_scale")]
403 #[must_use]
404 pub fn scale(&self, factor: f32) -> Vec3 {
405 unsafe {
406 let mut res = Vec3::uninitialized();
407 ffi::graphene_vec3_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
408 res
409 }
410 }
411
412 /// Subtracts from each component of the first operand `self` the
413 /// corresponding component of the second operand `b` and places
414 /// each result into the components of `res`.
415 /// ## `b`
416 /// a [`Vec3`][crate::Vec3]
417 ///
418 /// # Returns
419 ///
420 ///
421 /// ## `res`
422 /// return location for the resulting vector
423 #[doc(alias = "graphene_vec3_subtract")]
424 #[must_use]
425 pub fn subtract(&self, b: &Vec3) -> Vec3 {
426 unsafe {
427 let mut res = Vec3::uninitialized();
428 ffi::graphene_vec3_subtract(
429 self.to_glib_none().0,
430 b.to_glib_none().0,
431 res.to_glib_none_mut().0,
432 );
433 res
434 }
435 }
436
437 /// Provides a constant pointer to a vector with three components,
438 /// all sets to 1.
439 ///
440 /// # Returns
441 ///
442 /// a constant vector
443 #[doc(alias = "graphene_vec3_one")]
444 pub fn one() -> Vec3 {
445 assert_initialized_main_thread!();
446 unsafe { from_glib_none(ffi::graphene_vec3_one()) }
447 }
448
449 /// Provides a constant pointer to a vector with three components
450 /// with values set to (1, 0, 0).
451 ///
452 /// # Returns
453 ///
454 /// a constant vector
455 #[doc(alias = "graphene_vec3_x_axis")]
456 pub fn x_axis() -> Vec3 {
457 assert_initialized_main_thread!();
458 unsafe { from_glib_none(ffi::graphene_vec3_x_axis()) }
459 }
460
461 /// Provides a constant pointer to a vector with three components
462 /// with values set to (0, 1, 0).
463 ///
464 /// # Returns
465 ///
466 /// a constant vector
467 #[doc(alias = "graphene_vec3_y_axis")]
468 pub fn y_axis() -> Vec3 {
469 assert_initialized_main_thread!();
470 unsafe { from_glib_none(ffi::graphene_vec3_y_axis()) }
471 }
472
473 /// Provides a constant pointer to a vector with three components
474 /// with values set to (0, 0, 1).
475 ///
476 /// # Returns
477 ///
478 /// a constant vector
479 #[doc(alias = "graphene_vec3_z_axis")]
480 pub fn z_axis() -> Vec3 {
481 assert_initialized_main_thread!();
482 unsafe { from_glib_none(ffi::graphene_vec3_z_axis()) }
483 }
484
485 /// Provides a constant pointer to a vector with three components,
486 /// all sets to 0.
487 ///
488 /// # Returns
489 ///
490 /// a constant vector
491 #[doc(alias = "graphene_vec3_zero")]
492 pub fn zero() -> Vec3 {
493 assert_initialized_main_thread!();
494 unsafe { from_glib_none(ffi::graphene_vec3_zero()) }
495 }
496}
497
498impl PartialEq for Vec3 {
499 #[inline]
500 fn eq(&self, other: &Self) -> bool {
501 self.equal(other)
502 }
503}
504
505impl Eq for Vec3 {}