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