graphene/
box_.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, Box, Point3D, Vec3};
8
9impl Box {
10    #[doc(alias = "graphene_box_get_vertices")]
11    #[doc(alias = "get_vertices")]
12    pub fn vertices(&self) -> &[Vec3; 8] {
13        unsafe {
14            let mut out: [ffi::graphene_vec3_t; 8] = std::mem::zeroed();
15            ffi::graphene_box_get_vertices(self.to_glib_none().0, &mut out as *mut _);
16            &*(&out as *const [ffi::graphene_vec3_t; 8] as *const [Vec3; 8])
17        }
18    }
19
20    #[doc(alias = "graphene_box_init")]
21    pub fn new(min: Option<&Point3D>, max: Option<&Point3D>) -> Self {
22        assert_initialized_main_thread!();
23        unsafe {
24            let mut b = Self::uninitialized();
25            ffi::graphene_box_init(
26                b.to_glib_none_mut().0,
27                min.to_glib_none().0,
28                max.to_glib_none().0,
29            );
30            b
31        }
32    }
33
34    #[doc(alias = "graphene_box_init_from_points")]
35    #[doc(alias = "init_from_points")]
36    pub fn from_points(points: &[Point3D]) -> Self {
37        assert_initialized_main_thread!();
38
39        let n = points.len() as u32;
40
41        unsafe {
42            let mut b = Self::uninitialized();
43            ffi::graphene_box_init_from_points(b.to_glib_none_mut().0, n, points.to_glib_none().0);
44            b
45        }
46    }
47
48    #[doc(alias = "graphene_box_init_from_vec3")]
49    #[doc(alias = "init_from_vec3")]
50    pub fn from_vec3(min: Option<&Vec3>, max: Option<&Vec3>) -> Self {
51        assert_initialized_main_thread!();
52        unsafe {
53            let mut b = Self::uninitialized();
54            ffi::graphene_box_init_from_vec3(
55                b.to_glib_none_mut().0,
56                min.to_glib_none().0,
57                max.to_glib_none().0,
58            );
59            b
60        }
61    }
62
63    #[doc(alias = "graphene_box_init_from_vectors")]
64    #[doc(alias = "init_from_vectors")]
65    pub fn from_vectors(vectors: &[Vec3]) -> Self {
66        assert_initialized_main_thread!();
67
68        let n = vectors.len() as u32;
69
70        unsafe {
71            let mut b = Self::uninitialized();
72            ffi::graphene_box_init_from_vectors(
73                b.to_glib_none_mut().0,
74                n,
75                vectors.to_glib_none().0,
76            );
77            b
78        }
79    }
80}
81
82impl Default for Box {
83    fn default() -> Self {
84        Self::zero()
85    }
86}
87
88impl fmt::Debug for Box {
89    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90        f.debug_struct("Box")
91            .field("min", &self.min())
92            .field("max", &self.max())
93            .finish()
94    }
95}