graphene/
frustum.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Frustum, Matrix, Plane};
8
9impl Frustum {
10    /// Retrieves the planes that define the given [`Frustum`][crate::Frustum].
11    ///
12    /// # Returns
13    ///
14    ///
15    /// ## `planes`
16    /// return location for an array
17    ///  of 6 [`Plane`][crate::Plane]
18    #[doc(alias = "graphene_frustum_get_planes")]
19    #[doc(alias = "get_planes")]
20    pub fn planes(&self) -> &[Plane; 6] {
21        unsafe {
22            let mut out: [ffi::graphene_plane_t; 6] = std::mem::zeroed();
23            ffi::graphene_frustum_get_planes(self.to_glib_none().0, &mut out as *mut _);
24            &*(&out as *const [ffi::graphene_plane_t; 6] as *const [Plane; 6])
25        }
26    }
27
28    /// Initializes the given [`Frustum`][crate::Frustum] using the provided
29    /// clipping planes.
30    /// ## `p0`
31    /// a clipping plane
32    /// ## `p1`
33    /// a clipping plane
34    /// ## `p2`
35    /// a clipping plane
36    /// ## `p3`
37    /// a clipping plane
38    /// ## `p4`
39    /// a clipping plane
40    /// ## `p5`
41    /// a clipping plane
42    ///
43    /// # Returns
44    ///
45    /// the initialized frustum
46    #[doc(alias = "graphene_frustum_init")]
47    pub fn new(p0: &Plane, p1: &Plane, p2: &Plane, p3: &Plane, p4: &Plane, p5: &Plane) -> Self {
48        assert_initialized_main_thread!();
49        unsafe {
50            let mut fru = Self::uninitialized();
51            ffi::graphene_frustum_init(
52                fru.to_glib_none_mut().0,
53                p0.to_glib_none().0,
54                p1.to_glib_none().0,
55                p2.to_glib_none().0,
56                p3.to_glib_none().0,
57                p4.to_glib_none().0,
58                p5.to_glib_none().0,
59            );
60            fru
61        }
62    }
63
64    /// Initializes a [`Frustum`][crate::Frustum] using the given `matrix`.
65    /// ## `matrix`
66    /// a [`Matrix`][crate::Matrix]
67    ///
68    /// # Returns
69    ///
70    /// the initialized frustum
71    #[doc(alias = "graphene_frustum_init_from_matrix")]
72    #[doc(alias = "init_from_matrix")]
73    pub fn from_matrix(matrix: &Matrix) -> Self {
74        assert_initialized_main_thread!();
75        unsafe {
76            let mut fru = Self::uninitialized();
77            ffi::graphene_frustum_init_from_matrix(
78                fru.to_glib_none_mut().0,
79                matrix.to_glib_none().0,
80            );
81            fru
82        }
83    }
84}
85
86impl fmt::Debug for Frustum {
87    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88        f.debug_struct("Frustum")
89            .field("planes", &self.planes())
90            .finish()
91    }
92}