graphene/
triangle.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, Point3D, Triangle, Vec3};
8
9impl Triangle {
10    #[doc(alias = "graphene_triangle_init_from_float")]
11    #[doc(alias = "init_from_float")]
12    pub fn from_float(a: [f32; 3], b: [f32; 3], c: [f32; 3]) -> Self {
13        assert_initialized_main_thread!();
14        unsafe {
15            let mut tri = Self::uninitialized();
16            ffi::graphene_triangle_init_from_float(
17                tri.to_glib_none_mut().0,
18                a.as_ptr() as *const _,
19                b.as_ptr() as *const _,
20                c.as_ptr() as *const _,
21            );
22            tri
23        }
24    }
25
26    #[doc(alias = "graphene_triangle_init_from_point3d")]
27    #[doc(alias = "init_from_point3d")]
28    pub fn from_point3d(a: Option<&Point3D>, b: Option<&Point3D>, c: Option<&Point3D>) -> Self {
29        assert_initialized_main_thread!();
30        unsafe {
31            let mut tri = Self::uninitialized();
32            ffi::graphene_triangle_init_from_point3d(
33                tri.to_glib_none_mut().0,
34                a.to_glib_none().0,
35                b.to_glib_none().0,
36                c.to_glib_none().0,
37            );
38            tri
39        }
40    }
41
42    #[doc(alias = "graphene_triangle_init_from_vec3")]
43    #[doc(alias = "init_from_vec3")]
44    pub fn from_vec3(a: Option<&Vec3>, b: Option<&Vec3>, c: Option<&Vec3>) -> Self {
45        assert_initialized_main_thread!();
46        unsafe {
47            let mut tri = Self::uninitialized();
48            ffi::graphene_triangle_init_from_vec3(
49                tri.to_glib_none_mut().0,
50                a.to_glib_none().0,
51                b.to_glib_none().0,
52                c.to_glib_none().0,
53            );
54            tri
55        }
56    }
57}
58
59impl fmt::Debug for Triangle {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        f.debug_struct("Triangle")
62            .field("points", &self.points())
63            .finish()
64    }
65}