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    #[doc(alias = "graphene_frustum_get_planes")]
11    #[doc(alias = "get_planes")]
12    pub fn planes(&self) -> &[Plane; 6] {
13        unsafe {
14            let mut out: [ffi::graphene_plane_t; 6] = std::mem::zeroed();
15            ffi::graphene_frustum_get_planes(self.to_glib_none().0, &mut out as *mut _);
16            &*(&out as *const [ffi::graphene_plane_t; 6] as *const [Plane; 6])
17        }
18    }
19
20    #[doc(alias = "graphene_frustum_init")]
21    pub fn new(p0: &Plane, p1: &Plane, p2: &Plane, p3: &Plane, p4: &Plane, p5: &Plane) -> Self {
22        assert_initialized_main_thread!();
23        unsafe {
24            let mut fru = Self::uninitialized();
25            ffi::graphene_frustum_init(
26                fru.to_glib_none_mut().0,
27                p0.to_glib_none().0,
28                p1.to_glib_none().0,
29                p2.to_glib_none().0,
30                p3.to_glib_none().0,
31                p4.to_glib_none().0,
32                p5.to_glib_none().0,
33            );
34            fru
35        }
36    }
37
38    #[doc(alias = "graphene_frustum_init_from_matrix")]
39    #[doc(alias = "init_from_matrix")]
40    pub fn from_matrix(matrix: &Matrix) -> Self {
41        assert_initialized_main_thread!();
42        unsafe {
43            let mut fru = Self::uninitialized();
44            ffi::graphene_frustum_init_from_matrix(
45                fru.to_glib_none_mut().0,
46                matrix.to_glib_none().0,
47            );
48            fru
49        }
50    }
51}
52
53impl fmt::Debug for Frustum {
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        f.debug_struct("Frustum")
56            .field("planes", &self.planes())
57            .finish()
58    }
59}