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