Skip to main content

graphene/auto/
matrix.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::{Box, Euler, Point, Point3D, Quad, Quaternion, Ray, Rect, Sphere, Vec3, Vec4, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A structure capable of holding a 4x4 matrix.
10    ///
11    /// The contents of the [`Matrix`][crate::Matrix] structure are private and
12    /// should never be accessed directly.
13    pub struct Matrix(BoxedInline<ffi::graphene_matrix_t>);
14
15    match fn {
16        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_matrix_get_type(), ptr as *mut _) as *mut ffi::graphene_matrix_t,
17        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_matrix_get_type(), ptr as *mut _),
18        type_ => || ffi::graphene_matrix_get_type(),
19    }
20}
21
22impl Matrix {
23    /// Decomposes a transformation matrix into its component transformations.
24    ///
25    /// The algorithm for decomposing a matrix is taken from the
26    /// [CSS3 Transforms specification](http://dev.w3.org/csswg/css-transforms/);
27    /// specifically, the decomposition code is based on the equivalent code
28    /// published in "Graphics Gems II", edited by Jim Arvo, and
29    /// [available online](http://web.archive.org/web/20150512160205/http://tog.acm.org/resources/GraphicsGems/gemsii/unmatrix.c).
30    ///
31    /// # Returns
32    ///
33    /// `true` if the matrix could be decomposed
34    ///
35    /// ## `translate`
36    /// the translation vector
37    ///
38    /// ## `scale`
39    /// the scale vector
40    ///
41    /// ## `rotate`
42    /// the rotation quaternion
43    ///
44    /// ## `shear`
45    /// the shear vector
46    ///
47    /// ## `perspective`
48    /// the perspective vector
49    #[doc(alias = "graphene_matrix_decompose")]
50    pub fn decompose(&self) -> Option<(Vec3, Vec3, Quaternion, Vec3, Vec4)> {
51        unsafe {
52            let mut translate = Vec3::uninitialized();
53            let mut scale = Vec3::uninitialized();
54            let mut rotate = Quaternion::uninitialized();
55            let mut shear = Vec3::uninitialized();
56            let mut perspective = Vec4::uninitialized();
57            let ret = ffi::graphene_matrix_decompose(
58                self.to_glib_none().0,
59                translate.to_glib_none_mut().0,
60                scale.to_glib_none_mut().0,
61                rotate.to_glib_none_mut().0,
62                shear.to_glib_none_mut().0,
63                perspective.to_glib_none_mut().0,
64            );
65            if ret {
66                Some((translate, scale, rotate, shear, perspective))
67            } else {
68                None
69            }
70        }
71    }
72
73    /// Computes the determinant of the given matrix.
74    ///
75    /// # Returns
76    ///
77    /// the value of the determinant
78    #[doc(alias = "graphene_matrix_determinant")]
79    pub fn determinant(&self) -> f32 {
80        unsafe { ffi::graphene_matrix_determinant(self.to_glib_none().0) }
81    }
82
83    #[doc(alias = "graphene_matrix_equal")]
84    fn equal(&self, b: &Matrix) -> bool {
85        unsafe { ffi::graphene_matrix_equal(self.to_glib_none().0, b.to_glib_none().0) }
86    }
87
88    ///
89    ///  if (graphene_matrix_equal_fast (a, b))
90    ///  {
91    ///  // matrices are definitely the same
92    ///  }
93    ///  else
94    ///  {
95    ///  if (graphene_matrix_equal (a, b))
96    ///  // matrices contain the same values within an epsilon of FLT_EPSILON
97    ///  else if (graphene_matrix_near (a, b, 0.0001))
98    ///  // matrices contain the same values within an epsilon of 0.0001
99    ///  else
100    ///  // matrices are not equal
101    ///  }
102    /// ]|
103    /// ## `b`
104    /// a [`Matrix`][crate::Matrix]
105    ///
106    /// # Returns
107    ///
108    /// `true` if the matrices are equal. and `false` otherwise
109    #[doc(alias = "graphene_matrix_equal_fast")]
110    pub fn equal_fast(&self, b: &Matrix) -> bool {
111        unsafe { ffi::graphene_matrix_equal_fast(self.to_glib_none().0, b.to_glib_none().0) }
112    }
113
114    /// Retrieves the given row vector at `index_` inside a matrix.
115    /// ## `index_`
116    /// the index of the row vector, between 0 and 3
117    ///
118    /// # Returns
119    ///
120    ///
121    /// ## `res`
122    /// return location for the [`Vec4`][crate::Vec4]
123    ///  that is used to store the row vector
124    #[doc(alias = "graphene_matrix_get_row")]
125    #[doc(alias = "get_row")]
126    pub fn row(&self, index_: u32) -> Vec4 {
127        unsafe {
128            let mut res = Vec4::uninitialized();
129            ffi::graphene_matrix_get_row(self.to_glib_none().0, index_, res.to_glib_none_mut().0);
130            res
131        }
132    }
133
134    /// Retrieves the value at the given `row` and `col` index.
135    /// ## `row`
136    /// the row index
137    /// ## `col`
138    /// the column index
139    ///
140    /// # Returns
141    ///
142    /// the value at the given indices
143    #[doc(alias = "graphene_matrix_get_value")]
144    #[doc(alias = "get_value")]
145    pub fn value(&self, row: u32, col: u32) -> f32 {
146        unsafe { ffi::graphene_matrix_get_value(self.to_glib_none().0, row, col) }
147    }
148
149    /// Retrieves the scaling factor on the X axis in `self`.
150    ///
151    /// # Returns
152    ///
153    /// the value of the scaling factor
154    #[doc(alias = "graphene_matrix_get_x_scale")]
155    #[doc(alias = "get_x_scale")]
156    pub fn x_scale(&self) -> f32 {
157        unsafe { ffi::graphene_matrix_get_x_scale(self.to_glib_none().0) }
158    }
159
160    /// Retrieves the translation component on the X axis from `self`.
161    ///
162    /// # Returns
163    ///
164    /// the translation component
165    #[doc(alias = "graphene_matrix_get_x_translation")]
166    #[doc(alias = "get_x_translation")]
167    pub fn x_translation(&self) -> f32 {
168        unsafe { ffi::graphene_matrix_get_x_translation(self.to_glib_none().0) }
169    }
170
171    /// Retrieves the scaling factor on the Y axis in `self`.
172    ///
173    /// # Returns
174    ///
175    /// the value of the scaling factor
176    #[doc(alias = "graphene_matrix_get_y_scale")]
177    #[doc(alias = "get_y_scale")]
178    pub fn y_scale(&self) -> f32 {
179        unsafe { ffi::graphene_matrix_get_y_scale(self.to_glib_none().0) }
180    }
181
182    /// Retrieves the translation component on the Y axis from `self`.
183    ///
184    /// # Returns
185    ///
186    /// the translation component
187    #[doc(alias = "graphene_matrix_get_y_translation")]
188    #[doc(alias = "get_y_translation")]
189    pub fn y_translation(&self) -> f32 {
190        unsafe { ffi::graphene_matrix_get_y_translation(self.to_glib_none().0) }
191    }
192
193    /// Retrieves the scaling factor on the Z axis in `self`.
194    ///
195    /// # Returns
196    ///
197    /// the value of the scaling factor
198    #[doc(alias = "graphene_matrix_get_z_scale")]
199    #[doc(alias = "get_z_scale")]
200    pub fn z_scale(&self) -> f32 {
201        unsafe { ffi::graphene_matrix_get_z_scale(self.to_glib_none().0) }
202    }
203
204    /// Retrieves the translation component on the Z axis from `self`.
205    ///
206    /// # Returns
207    ///
208    /// the translation component
209    #[doc(alias = "graphene_matrix_get_z_translation")]
210    #[doc(alias = "get_z_translation")]
211    pub fn z_translation(&self) -> f32 {
212        unsafe { ffi::graphene_matrix_get_z_translation(self.to_glib_none().0) }
213    }
214
215    /// Linearly interpolates the two given [`Matrix`][crate::Matrix] by
216    /// interpolating the decomposed transformations separately.
217    ///
218    /// If either matrix cannot be reduced to their transformations
219    /// then the interpolation cannot be performed, and this function
220    /// will return an identity matrix.
221    /// ## `b`
222    /// a [`Matrix`][crate::Matrix]
223    /// ## `factor`
224    /// the linear interpolation factor
225    ///
226    /// # Returns
227    ///
228    ///
229    /// ## `res`
230    /// return location for the
231    ///  interpolated matrix
232    #[doc(alias = "graphene_matrix_interpolate")]
233    #[must_use]
234    pub fn interpolate(&self, b: &Matrix, factor: f64) -> Matrix {
235        unsafe {
236            let mut res = Matrix::uninitialized();
237            ffi::graphene_matrix_interpolate(
238                self.to_glib_none().0,
239                b.to_glib_none().0,
240                factor,
241                res.to_glib_none_mut().0,
242            );
243            res
244        }
245    }
246
247    /// Inverts the given matrix.
248    ///
249    /// # Returns
250    ///
251    /// `true` if the matrix is invertible
252    ///
253    /// ## `res`
254    /// return location for the
255    ///  inverse matrix
256    #[doc(alias = "graphene_matrix_inverse")]
257    pub fn inverse(&self) -> Option<Matrix> {
258        unsafe {
259            let mut res = Matrix::uninitialized();
260            let ret = ffi::graphene_matrix_inverse(self.to_glib_none().0, res.to_glib_none_mut().0);
261            if ret { Some(res) } else { None }
262        }
263    }
264
265    /// Checks whether the given [`Matrix`][crate::Matrix] is compatible with an
266    /// a 2D affine transformation matrix.
267    ///
268    /// # Returns
269    ///
270    /// `true` if the matrix is compatible with an affine
271    ///  transformation matrix
272    #[doc(alias = "graphene_matrix_is_2d")]
273    pub fn is_2d(&self) -> bool {
274        unsafe { ffi::graphene_matrix_is_2d(self.to_glib_none().0) }
275    }
276
277    /// Checks whether a [`Matrix`][crate::Matrix] has a visible back face.
278    ///
279    /// # Returns
280    ///
281    /// `true` if the back face of the matrix is visible
282    #[doc(alias = "graphene_matrix_is_backface_visible")]
283    pub fn is_backface_visible(&self) -> bool {
284        unsafe { ffi::graphene_matrix_is_backface_visible(self.to_glib_none().0) }
285    }
286
287    /// Checks whether the given [`Matrix`][crate::Matrix] is the identity matrix.
288    ///
289    /// # Returns
290    ///
291    /// `true` if the matrix is the identity matrix
292    #[doc(alias = "graphene_matrix_is_identity")]
293    pub fn is_identity(&self) -> bool {
294        unsafe { ffi::graphene_matrix_is_identity(self.to_glib_none().0) }
295    }
296
297    /// Checks whether a matrix is singular.
298    ///
299    /// # Returns
300    ///
301    /// `true` if the matrix is singular
302    #[doc(alias = "graphene_matrix_is_singular")]
303    pub fn is_singular(&self) -> bool {
304        unsafe { ffi::graphene_matrix_is_singular(self.to_glib_none().0) }
305    }
306
307    /// Multiplies two [`Matrix`][crate::Matrix].
308    ///
309    /// Matrix multiplication is not commutative in general; the order of the factors matters.
310    /// The product of this multiplication is (`self` × `b`)
311    /// ## `b`
312    /// a [`Matrix`][crate::Matrix]
313    ///
314    /// # Returns
315    ///
316    ///
317    /// ## `res`
318    /// return location for the matrix
319    ///  result
320    #[doc(alias = "graphene_matrix_multiply")]
321    #[must_use]
322    pub fn multiply(&self, b: &Matrix) -> Matrix {
323        unsafe {
324            let mut res = Matrix::uninitialized();
325            ffi::graphene_matrix_multiply(
326                self.to_glib_none().0,
327                b.to_glib_none().0,
328                res.to_glib_none_mut().0,
329            );
330            res
331        }
332    }
333
334    /// Compares the two given [`Matrix`][crate::Matrix] matrices and checks
335    /// whether their values are within the given `epsilon` of each
336    /// other.
337    /// ## `b`
338    /// a [`Matrix`][crate::Matrix]
339    /// ## `epsilon`
340    /// the threshold between the two matrices
341    ///
342    /// # Returns
343    ///
344    /// `true` if the two matrices are near each other, and
345    ///  `false` otherwise
346    #[doc(alias = "graphene_matrix_near")]
347    pub fn near(&self, b: &Matrix, epsilon: f32) -> bool {
348        unsafe { ffi::graphene_matrix_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
349    }
350
351    /// Normalizes the given [`Matrix`][crate::Matrix].
352    ///
353    /// # Returns
354    ///
355    ///
356    /// ## `res`
357    /// return location for the normalized matrix
358    #[doc(alias = "graphene_matrix_normalize")]
359    #[must_use]
360    pub fn normalize(&self) -> Matrix {
361        unsafe {
362            let mut res = Matrix::uninitialized();
363            ffi::graphene_matrix_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
364            res
365        }
366    }
367
368    /// Applies a perspective of `depth` to the matrix.
369    /// ## `depth`
370    /// the depth of the perspective
371    ///
372    /// # Returns
373    ///
374    ///
375    /// ## `res`
376    /// return location for the
377    ///  perspective matrix
378    #[doc(alias = "graphene_matrix_perspective")]
379    #[must_use]
380    pub fn perspective(&self, depth: f32) -> Matrix {
381        unsafe {
382            let mut res = Matrix::uninitialized();
383            ffi::graphene_matrix_perspective(
384                self.to_glib_none().0,
385                depth,
386                res.to_glib_none_mut().0,
387            );
388            res
389        }
390    }
391
392    /// Prints the contents of a matrix to the standard error stream.
393    ///
394    /// This function is only useful for debugging; there are no guarantees
395    /// made on the format of the output.
396    #[doc(alias = "graphene_matrix_print")]
397    pub fn print(&self) {
398        unsafe {
399            ffi::graphene_matrix_print(self.to_glib_none().0);
400        }
401    }
402
403    /// Projects a [`Point`][crate::Point] using the matrix `self`.
404    /// ## `p`
405    /// a [`Point`][crate::Point]
406    ///
407    /// # Returns
408    ///
409    ///
410    /// ## `res`
411    /// return location for the projected
412    ///  point
413    #[doc(alias = "graphene_matrix_project_point")]
414    pub fn project_point(&self, p: &Point) -> Point {
415        unsafe {
416            let mut res = Point::uninitialized();
417            ffi::graphene_matrix_project_point(
418                self.to_glib_none().0,
419                p.to_glib_none().0,
420                res.to_glib_none_mut().0,
421            );
422            res
423        }
424    }
425
426    /// Projects all corners of a [`Rect`][crate::Rect] using the given matrix.
427    ///
428    /// See also: [`project_point()`][Self::project_point()]
429    /// ## `r`
430    /// a [`Rect`][crate::Rect]
431    ///
432    /// # Returns
433    ///
434    ///
435    /// ## `res`
436    /// return location for the projected
437    ///  rectangle
438    #[doc(alias = "graphene_matrix_project_rect")]
439    pub fn project_rect(&self, r: &Rect) -> Quad {
440        unsafe {
441            let mut res = Quad::uninitialized();
442            ffi::graphene_matrix_project_rect(
443                self.to_glib_none().0,
444                r.to_glib_none().0,
445                res.to_glib_none_mut().0,
446            );
447            res
448        }
449    }
450
451    /// Projects a [`Rect`][crate::Rect] using the given matrix.
452    ///
453    /// The resulting rectangle is the axis aligned bounding rectangle capable
454    /// of fully containing the projected rectangle.
455    /// ## `r`
456    /// a [`Rect`][crate::Rect]
457    ///
458    /// # Returns
459    ///
460    ///
461    /// ## `res`
462    /// return location for the projected
463    ///  rectangle
464    #[doc(alias = "graphene_matrix_project_rect_bounds")]
465    pub fn project_rect_bounds(&self, r: &Rect) -> Rect {
466        unsafe {
467            let mut res = Rect::uninitialized();
468            ffi::graphene_matrix_project_rect_bounds(
469                self.to_glib_none().0,
470                r.to_glib_none().0,
471                res.to_glib_none_mut().0,
472            );
473            res
474        }
475    }
476
477    /// Adds a rotation transformation to `self`, using the given `angle`
478    /// and `axis` vector.
479    ///
480    /// This is the equivalent of calling [`new_rotate()`][Self::new_rotate()] and
481    /// then multiplying the matrix `self` with the rotation matrix.
482    /// ## `angle`
483    /// the rotation angle, in degrees
484    /// ## `axis`
485    /// the rotation axis, as a [`Vec3`][crate::Vec3]
486    #[doc(alias = "graphene_matrix_rotate")]
487    pub fn rotate(&mut self, angle: f32, axis: &Vec3) {
488        unsafe {
489            ffi::graphene_matrix_rotate(self.to_glib_none_mut().0, angle, axis.to_glib_none().0);
490        }
491    }
492
493    /// Adds a rotation transformation to `self`, using the given
494    /// [`Euler`][crate::Euler].
495    /// ## `e`
496    /// a rotation described by a [`Euler`][crate::Euler]
497    #[doc(alias = "graphene_matrix_rotate_euler")]
498    pub fn rotate_euler(&mut self, e: &Euler) {
499        unsafe {
500            ffi::graphene_matrix_rotate_euler(self.to_glib_none_mut().0, e.to_glib_none().0);
501        }
502    }
503
504    /// Adds a rotation transformation to `self`, using the given
505    /// [`Quaternion`][crate::Quaternion].
506    ///
507    /// This is the equivalent of calling [`Quaternion::to_matrix()`][crate::Quaternion::to_matrix()] and
508    /// then multiplying `self` with the rotation matrix.
509    /// ## `q`
510    /// a rotation described by a [`Quaternion`][crate::Quaternion]
511    #[doc(alias = "graphene_matrix_rotate_quaternion")]
512    pub fn rotate_quaternion(&mut self, q: &Quaternion) {
513        unsafe {
514            ffi::graphene_matrix_rotate_quaternion(self.to_glib_none_mut().0, q.to_glib_none().0);
515        }
516    }
517
518    /// Adds a rotation transformation around the X axis to `self`, using
519    /// the given `angle`.
520    ///
521    /// See also: [`rotate()`][Self::rotate()]
522    /// ## `angle`
523    /// the rotation angle, in degrees
524    #[doc(alias = "graphene_matrix_rotate_x")]
525    pub fn rotate_x(&mut self, angle: f32) {
526        unsafe {
527            ffi::graphene_matrix_rotate_x(self.to_glib_none_mut().0, angle);
528        }
529    }
530
531    /// Adds a rotation transformation around the Y axis to `self`, using
532    /// the given `angle`.
533    ///
534    /// See also: [`rotate()`][Self::rotate()]
535    /// ## `angle`
536    /// the rotation angle, in degrees
537    #[doc(alias = "graphene_matrix_rotate_y")]
538    pub fn rotate_y(&mut self, angle: f32) {
539        unsafe {
540            ffi::graphene_matrix_rotate_y(self.to_glib_none_mut().0, angle);
541        }
542    }
543
544    /// Adds a rotation transformation around the Z axis to `self`, using
545    /// the given `angle`.
546    ///
547    /// See also: [`rotate()`][Self::rotate()]
548    /// ## `angle`
549    /// the rotation angle, in degrees
550    #[doc(alias = "graphene_matrix_rotate_z")]
551    pub fn rotate_z(&mut self, angle: f32) {
552        unsafe {
553            ffi::graphene_matrix_rotate_z(self.to_glib_none_mut().0, angle);
554        }
555    }
556
557    /// Adds a scaling transformation to `self`, using the three
558    /// given factors.
559    ///
560    /// This is the equivalent of calling [`new_scale()`][Self::new_scale()] and then
561    /// multiplying the matrix `self` with the scale matrix.
562    /// ## `factor_x`
563    /// scaling factor on the X axis
564    /// ## `factor_y`
565    /// scaling factor on the Y axis
566    /// ## `factor_z`
567    /// scaling factor on the Z axis
568    #[doc(alias = "graphene_matrix_scale")]
569    pub fn scale(&mut self, factor_x: f32, factor_y: f32, factor_z: f32) {
570        unsafe {
571            ffi::graphene_matrix_scale(self.to_glib_none_mut().0, factor_x, factor_y, factor_z);
572        }
573    }
574
575    /// Adds a skew of `factor` on the X and Y axis to the given matrix.
576    /// ## `factor`
577    /// skew factor
578    #[doc(alias = "graphene_matrix_skew_xy")]
579    pub fn skew_xy(&mut self, factor: f32) {
580        unsafe {
581            ffi::graphene_matrix_skew_xy(self.to_glib_none_mut().0, factor);
582        }
583    }
584
585    /// Adds a skew of `factor` on the X and Z axis to the given matrix.
586    /// ## `factor`
587    /// skew factor
588    #[doc(alias = "graphene_matrix_skew_xz")]
589    pub fn skew_xz(&mut self, factor: f32) {
590        unsafe {
591            ffi::graphene_matrix_skew_xz(self.to_glib_none_mut().0, factor);
592        }
593    }
594
595    /// Adds a skew of `factor` on the Y and Z axis to the given matrix.
596    /// ## `factor`
597    /// skew factor
598    #[doc(alias = "graphene_matrix_skew_yz")]
599    pub fn skew_yz(&mut self, factor: f32) {
600        unsafe {
601            ffi::graphene_matrix_skew_yz(self.to_glib_none_mut().0, factor);
602        }
603    }
604
605    ///
606    ///  ⎛ xx yx ⎞ ⎛ a b 0 ⎞
607    ///  ⎜ xy yy ⎟ = ⎜ c d 0 ⎟
608    ///  ⎝ x0 y0 ⎠ ⎝ tx ty 1 ⎠
609    /// ]|
610    ///
611    /// This function can be used to convert between a [`Matrix`][crate::Matrix]
612    /// and an affine matrix type from other libraries.
613    ///
614    /// # Returns
615    ///
616    /// `true` if the matrix is compatible with an affine
617    ///  transformation matrix
618    ///
619    /// ## `xx`
620    /// return location for the xx member
621    ///
622    /// ## `yx`
623    /// return location for the yx member
624    ///
625    /// ## `xy`
626    /// return location for the xy member
627    ///
628    /// ## `yy`
629    /// return location for the yy member
630    ///
631    /// ## `x_0`
632    /// return location for the x0 member
633    ///
634    /// ## `y_0`
635    /// return location for the y0 member
636    #[doc(alias = "graphene_matrix_to_2d")]
637    pub fn to_2d(&self) -> Option<(f64, f64, f64, f64, f64, f64)> {
638        unsafe {
639            let mut xx = std::mem::MaybeUninit::uninit();
640            let mut yx = std::mem::MaybeUninit::uninit();
641            let mut xy = std::mem::MaybeUninit::uninit();
642            let mut yy = std::mem::MaybeUninit::uninit();
643            let mut x_0 = std::mem::MaybeUninit::uninit();
644            let mut y_0 = std::mem::MaybeUninit::uninit();
645            let ret = ffi::graphene_matrix_to_2d(
646                self.to_glib_none().0,
647                xx.as_mut_ptr(),
648                yx.as_mut_ptr(),
649                xy.as_mut_ptr(),
650                yy.as_mut_ptr(),
651                x_0.as_mut_ptr(),
652                y_0.as_mut_ptr(),
653            );
654            if ret {
655                Some((
656                    xx.assume_init(),
657                    yx.assume_init(),
658                    xy.assume_init(),
659                    yy.assume_init(),
660                    x_0.assume_init(),
661                    y_0.assume_init(),
662                ))
663            } else {
664                None
665            }
666        }
667    }
668
669    /// Transforms each corner of a [`Rect`][crate::Rect] using the given matrix `self`.
670    ///
671    /// The result is the axis aligned bounding rectangle containing the coplanar
672    /// quadrilateral.
673    ///
674    /// See also: [`transform_point()`][Self::transform_point()]
675    /// ## `r`
676    /// a [`Rect`][crate::Rect]
677    ///
678    /// # Returns
679    ///
680    ///
681    /// ## `res`
682    /// return location for the bounds
683    ///  of the transformed rectangle
684    #[doc(alias = "graphene_matrix_transform_bounds")]
685    pub fn transform_bounds(&self, r: &Rect) -> Rect {
686        unsafe {
687            let mut res = Rect::uninitialized();
688            ffi::graphene_matrix_transform_bounds(
689                self.to_glib_none().0,
690                r.to_glib_none().0,
691                res.to_glib_none_mut().0,
692            );
693            res
694        }
695    }
696
697    /// Transforms the vertices of a [`Box`][crate::Box] using the given matrix `self`.
698    ///
699    /// The result is the axis aligned bounding box containing the transformed
700    /// vertices.
701    /// ## `b`
702    /// a [`Box`][crate::Box]
703    ///
704    /// # Returns
705    ///
706    ///
707    /// ## `res`
708    /// return location for the bounds
709    ///  of the transformed box
710    #[doc(alias = "graphene_matrix_transform_box")]
711    pub fn transform_box(&self, b: &Box) -> Box {
712        unsafe {
713            let mut res = Box::uninitialized();
714            ffi::graphene_matrix_transform_box(
715                self.to_glib_none().0,
716                b.to_glib_none().0,
717                res.to_glib_none_mut().0,
718            );
719            res
720        }
721    }
722
723    /// Transforms the given [`Point`][crate::Point] using the matrix `self`.
724    ///
725    /// Unlike [`transform_vec3()`][Self::transform_vec3()], this function will take into
726    /// account the fourth row vector of the [`Matrix`][crate::Matrix] when computing
727    /// the dot product of each row vector of the matrix.
728    ///
729    /// See also: `graphene_simd4x4f_point3_mul()`
730    /// ## `p`
731    /// a [`Point`][crate::Point]
732    ///
733    /// # Returns
734    ///
735    ///
736    /// ## `res`
737    /// return location for the
738    ///  transformed [`Point`][crate::Point]
739    #[doc(alias = "graphene_matrix_transform_point")]
740    pub fn transform_point(&self, p: &Point) -> Point {
741        unsafe {
742            let mut res = Point::uninitialized();
743            ffi::graphene_matrix_transform_point(
744                self.to_glib_none().0,
745                p.to_glib_none().0,
746                res.to_glib_none_mut().0,
747            );
748            res
749        }
750    }
751
752    /// Transforms the given [`Point3D`][crate::Point3D] using the matrix `self`.
753    ///
754    /// Unlike [`transform_vec3()`][Self::transform_vec3()], this function will take into
755    /// account the fourth row vector of the [`Matrix`][crate::Matrix] when computing
756    /// the dot product of each row vector of the matrix.
757    ///
758    /// See also: `graphene_simd4x4f_point3_mul()`
759    /// ## `p`
760    /// a [`Point3D`][crate::Point3D]
761    ///
762    /// # Returns
763    ///
764    ///
765    /// ## `res`
766    /// return location for the result
767    #[doc(alias = "graphene_matrix_transform_point3d")]
768    pub fn transform_point3d(&self, p: &Point3D) -> Point3D {
769        unsafe {
770            let mut res = Point3D::uninitialized();
771            ffi::graphene_matrix_transform_point3d(
772                self.to_glib_none().0,
773                p.to_glib_none().0,
774                res.to_glib_none_mut().0,
775            );
776            res
777        }
778    }
779
780    /// Transform a [`Ray`][crate::Ray] using the given matrix `self`.
781    /// ## `r`
782    /// a [`Ray`][crate::Ray]
783    ///
784    /// # Returns
785    ///
786    ///
787    /// ## `res`
788    /// return location for the
789    ///  transformed ray
790    #[doc(alias = "graphene_matrix_transform_ray")]
791    pub fn transform_ray(&self, r: &Ray) -> Ray {
792        unsafe {
793            let mut res = Ray::uninitialized();
794            ffi::graphene_matrix_transform_ray(
795                self.to_glib_none().0,
796                r.to_glib_none().0,
797                res.to_glib_none_mut().0,
798            );
799            res
800        }
801    }
802
803    /// Transforms each corner of a [`Rect`][crate::Rect] using the given matrix `self`.
804    ///
805    /// The result is a coplanar quadrilateral.
806    ///
807    /// See also: [`transform_point()`][Self::transform_point()]
808    /// ## `r`
809    /// a [`Rect`][crate::Rect]
810    ///
811    /// # Returns
812    ///
813    ///
814    /// ## `res`
815    /// return location for the
816    ///  transformed quad
817    #[doc(alias = "graphene_matrix_transform_rect")]
818    pub fn transform_rect(&self, r: &Rect) -> Quad {
819        unsafe {
820            let mut res = Quad::uninitialized();
821            ffi::graphene_matrix_transform_rect(
822                self.to_glib_none().0,
823                r.to_glib_none().0,
824                res.to_glib_none_mut().0,
825            );
826            res
827        }
828    }
829
830    /// Transforms a [`Sphere`][crate::Sphere] using the given matrix `self`. The
831    /// result is the bounding sphere containing the transformed sphere.
832    /// ## `s`
833    /// a [`Sphere`][crate::Sphere]
834    ///
835    /// # Returns
836    ///
837    ///
838    /// ## `res`
839    /// return location for the bounds
840    ///  of the transformed sphere
841    #[doc(alias = "graphene_matrix_transform_sphere")]
842    pub fn transform_sphere(&self, s: &Sphere) -> Sphere {
843        unsafe {
844            let mut res = Sphere::uninitialized();
845            ffi::graphene_matrix_transform_sphere(
846                self.to_glib_none().0,
847                s.to_glib_none().0,
848                res.to_glib_none_mut().0,
849            );
850            res
851        }
852    }
853
854    /// Transforms the given [`Vec3`][crate::Vec3] using the matrix `self`.
855    ///
856    /// This function will multiply the X, Y, and Z row vectors of the matrix `self`
857    /// with the corresponding components of the vector `v`. The W row vector will
858    /// be ignored.
859    ///
860    /// See also: `graphene_simd4x4f_vec3_mul()`
861    /// ## `v`
862    /// a [`Vec3`][crate::Vec3]
863    ///
864    /// # Returns
865    ///
866    ///
867    /// ## `res`
868    /// return location for a [`Vec3`][crate::Vec3]
869    #[doc(alias = "graphene_matrix_transform_vec3")]
870    pub fn transform_vec3(&self, v: &Vec3) -> Vec3 {
871        unsafe {
872            let mut res = Vec3::uninitialized();
873            ffi::graphene_matrix_transform_vec3(
874                self.to_glib_none().0,
875                v.to_glib_none().0,
876                res.to_glib_none_mut().0,
877            );
878            res
879        }
880    }
881
882    /// Transforms the given [`Vec4`][crate::Vec4] using the matrix `self`.
883    ///
884    /// See also: `graphene_simd4x4f_vec4_mul()`
885    /// ## `v`
886    /// a [`Vec4`][crate::Vec4]
887    ///
888    /// # Returns
889    ///
890    ///
891    /// ## `res`
892    /// return location for a [`Vec4`][crate::Vec4]
893    #[doc(alias = "graphene_matrix_transform_vec4")]
894    pub fn transform_vec4(&self, v: &Vec4) -> Vec4 {
895        unsafe {
896            let mut res = Vec4::uninitialized();
897            ffi::graphene_matrix_transform_vec4(
898                self.to_glib_none().0,
899                v.to_glib_none().0,
900                res.to_glib_none_mut().0,
901            );
902            res
903        }
904    }
905
906    /// Adds a translation transformation to `self` using the coordinates
907    /// of the given [`Point3D`][crate::Point3D].
908    ///
909    /// This is the equivalent of calling [`new_translate()`][Self::new_translate()] and
910    /// then multiplying `self` with the translation matrix.
911    /// ## `pos`
912    /// a [`Point3D`][crate::Point3D]
913    #[doc(alias = "graphene_matrix_translate")]
914    pub fn translate(&mut self, pos: &Point3D) {
915        unsafe {
916            ffi::graphene_matrix_translate(self.to_glib_none_mut().0, pos.to_glib_none().0);
917        }
918    }
919
920    /// Transposes the given matrix.
921    ///
922    /// # Returns
923    ///
924    ///
925    /// ## `res`
926    /// return location for the
927    ///  transposed matrix
928    #[doc(alias = "graphene_matrix_transpose")]
929    #[must_use]
930    pub fn transpose(&self) -> Matrix {
931        unsafe {
932            let mut res = Matrix::uninitialized();
933            ffi::graphene_matrix_transpose(self.to_glib_none().0, res.to_glib_none_mut().0);
934            res
935        }
936    }
937
938    /// Unprojects the given `point` using the `self` matrix and
939    /// a `modelview` matrix.
940    /// ## `modelview`
941    /// a [`Matrix`][crate::Matrix] for the modelview matrix; this is
942    ///  the inverse of the modelview used when projecting the point
943    /// ## `point`
944    /// a [`Point3D`][crate::Point3D] with the coordinates of the point
945    ///
946    /// # Returns
947    ///
948    ///
949    /// ## `res`
950    /// return location for the unprojected
951    ///  point
952    #[doc(alias = "graphene_matrix_unproject_point3d")]
953    pub fn unproject_point3d(&self, modelview: &Matrix, point: &Point3D) -> Point3D {
954        unsafe {
955            let mut res = Point3D::uninitialized();
956            ffi::graphene_matrix_unproject_point3d(
957                self.to_glib_none().0,
958                modelview.to_glib_none().0,
959                point.to_glib_none().0,
960                res.to_glib_none_mut().0,
961            );
962            res
963        }
964    }
965
966    /// Undoes the transformation on the corners of a [`Rect`][crate::Rect] using the
967    /// given matrix, within the given axis aligned rectangular `bounds`.
968    /// ## `r`
969    /// a [`Rect`][crate::Rect]
970    /// ## `bounds`
971    /// the bounds of the transformation
972    ///
973    /// # Returns
974    ///
975    ///
976    /// ## `res`
977    /// return location for the
978    ///  untransformed rectangle
979    #[doc(alias = "graphene_matrix_untransform_bounds")]
980    pub fn untransform_bounds(&self, r: &Rect, bounds: &Rect) -> Rect {
981        unsafe {
982            let mut res = Rect::uninitialized();
983            ffi::graphene_matrix_untransform_bounds(
984                self.to_glib_none().0,
985                r.to_glib_none().0,
986                bounds.to_glib_none().0,
987                res.to_glib_none_mut().0,
988            );
989            res
990        }
991    }
992
993    /// Undoes the transformation of a [`Point`][crate::Point] using the
994    /// given matrix, within the given axis aligned rectangular `bounds`.
995    /// ## `p`
996    /// a [`Point`][crate::Point]
997    /// ## `bounds`
998    /// the bounds of the transformation
999    ///
1000    /// # Returns
1001    ///
1002    /// `true` if the point was successfully untransformed
1003    ///
1004    /// ## `res`
1005    /// return location for the
1006    ///  untransformed point
1007    #[doc(alias = "graphene_matrix_untransform_point")]
1008    pub fn untransform_point(&self, p: &Point, bounds: &Rect) -> Option<Point> {
1009        unsafe {
1010            let mut res = Point::uninitialized();
1011            let ret = ffi::graphene_matrix_untransform_point(
1012                self.to_glib_none().0,
1013                p.to_glib_none().0,
1014                bounds.to_glib_none().0,
1015                res.to_glib_none_mut().0,
1016            );
1017            if ret { Some(res) } else { None }
1018        }
1019    }
1020}
1021
1022impl PartialEq for Matrix {
1023    #[inline]
1024    fn eq(&self, other: &Self) -> bool {
1025        self.equal(other)
1026    }
1027}
1028
1029impl Eq for Matrix {}