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