graphene/
plane.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, Plane, Point3D, Vec3, Vec4};
8
9impl Plane {
10    #[doc(alias = "graphene_plane_init")]
11    pub fn new(normal: Option<&Vec3>, constant: f32) -> Self {
12        assert_initialized_main_thread!();
13        unsafe {
14            let mut plane = Self::uninitialized();
15            ffi::graphene_plane_init(
16                plane.to_glib_none_mut().0,
17                normal.to_glib_none().0,
18                constant,
19            );
20            plane
21        }
22    }
23
24    #[doc(alias = "graphene_plane_init_from_point")]
25    #[doc(alias = "init_from_point")]
26    pub fn from_point(normal: &Vec3, point: &Point3D) -> Self {
27        assert_initialized_main_thread!();
28        unsafe {
29            let mut plane = Self::uninitialized();
30            ffi::graphene_plane_init_from_point(
31                plane.to_glib_none_mut().0,
32                normal.to_glib_none().0,
33                point.to_glib_none().0,
34            );
35            plane
36        }
37    }
38
39    #[doc(alias = "graphene_plane_init_from_points")]
40    #[doc(alias = "init_from_points")]
41    pub fn from_points(a: &Point3D, b: &Point3D, c: &Point3D) -> Self {
42        assert_initialized_main_thread!();
43        unsafe {
44            let mut plane = Self::uninitialized();
45            ffi::graphene_plane_init_from_points(
46                plane.to_glib_none_mut().0,
47                a.to_glib_none().0,
48                b.to_glib_none().0,
49                c.to_glib_none().0,
50            );
51            plane
52        }
53    }
54
55    #[doc(alias = "graphene_plane_init_from_vec4")]
56    #[doc(alias = "init_from_vec4")]
57    pub fn from_vec4(src: &Vec4) -> Self {
58        assert_initialized_main_thread!();
59        unsafe {
60            let mut plane = Self::uninitialized();
61            ffi::graphene_plane_init_from_vec4(plane.to_glib_none_mut().0, src.to_glib_none().0);
62            plane
63        }
64    }
65}
66
67impl fmt::Debug for Plane {
68    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69        f.debug_struct("Plane")
70            .field("constant", &self.constant())
71            .field("normal", &self.normal())
72            .finish()
73    }
74}