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 /// Initializes a [`Triangle`][crate::Triangle] using the three given arrays
11 /// of floating point values, each representing the coordinates of
12 /// a point in 3D space.
13 /// ## `a`
14 /// an array of 3 floating point values
15 /// ## `b`
16 /// an array of 3 floating point values
17 /// ## `c`
18 /// an array of 3 floating point values
19 ///
20 /// # Returns
21 ///
22 /// the initialized [`Triangle`][crate::Triangle]
23 #[doc(alias = "graphene_triangle_init_from_float")]
24 #[doc(alias = "init_from_float")]
25 pub fn from_float(a: [f32; 3], b: [f32; 3], c: [f32; 3]) -> Self {
26 assert_initialized_main_thread!();
27 unsafe {
28 let mut tri = Self::uninitialized();
29 ffi::graphene_triangle_init_from_float(
30 tri.to_glib_none_mut().0,
31 a.as_ptr() as *const _,
32 b.as_ptr() as *const _,
33 c.as_ptr() as *const _,
34 );
35 tri
36 }
37 }
38
39 /// Initializes a [`Triangle`][crate::Triangle] using the three given 3D points.
40 /// ## `a`
41 /// a [`Point3D`][crate::Point3D]
42 /// ## `b`
43 /// a [`Point3D`][crate::Point3D]
44 /// ## `c`
45 /// a [`Point3D`][crate::Point3D]
46 ///
47 /// # Returns
48 ///
49 /// the initialized [`Triangle`][crate::Triangle]
50 #[doc(alias = "graphene_triangle_init_from_point3d")]
51 #[doc(alias = "init_from_point3d")]
52 pub fn from_point3d(a: Option<&Point3D>, b: Option<&Point3D>, c: Option<&Point3D>) -> Self {
53 assert_initialized_main_thread!();
54 unsafe {
55 let mut tri = Self::uninitialized();
56 ffi::graphene_triangle_init_from_point3d(
57 tri.to_glib_none_mut().0,
58 a.to_glib_none().0,
59 b.to_glib_none().0,
60 c.to_glib_none().0,
61 );
62 tri
63 }
64 }
65
66 /// Initializes a [`Triangle`][crate::Triangle] using the three given vectors.
67 /// ## `a`
68 /// a [`Vec3`][crate::Vec3]
69 /// ## `b`
70 /// a [`Vec3`][crate::Vec3]
71 /// ## `c`
72 /// a [`Vec3`][crate::Vec3]
73 ///
74 /// # Returns
75 ///
76 /// the initialized [`Triangle`][crate::Triangle]
77 #[doc(alias = "graphene_triangle_init_from_vec3")]
78 #[doc(alias = "init_from_vec3")]
79 pub fn from_vec3(a: Option<&Vec3>, b: Option<&Vec3>, c: Option<&Vec3>) -> Self {
80 assert_initialized_main_thread!();
81 unsafe {
82 let mut tri = Self::uninitialized();
83 ffi::graphene_triangle_init_from_vec3(
84 tri.to_glib_none_mut().0,
85 a.to_glib_none().0,
86 b.to_glib_none().0,
87 c.to_glib_none().0,
88 );
89 tri
90 }
91 }
92}
93
94impl fmt::Debug for Triangle {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 f.debug_struct("Triangle")
97 .field("points", &self.points())
98 .finish()
99 }
100}