graphene/auto/
plane.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Matrix, Point3D, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A 2D plane that extends infinitely in a 3D volume.
10    ///
11    /// The contents of the [`Plane`][crate::Plane] are private, and should not be
12    /// modified directly.
13    pub struct Plane(BoxedInline<ffi::graphene_plane_t>);
14
15    match fn {
16        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_plane_get_type(), ptr as *mut _) as *mut ffi::graphene_plane_t,
17        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_plane_get_type(), ptr as *mut _),
18        type_ => || ffi::graphene_plane_get_type(),
19    }
20}
21
22impl Plane {
23    /// Computes the distance of `point` from a [`Plane`][crate::Plane].
24    /// ## `point`
25    /// a [`Point3D`][crate::Point3D]
26    ///
27    /// # Returns
28    ///
29    /// the distance of the given [`Point3D`][crate::Point3D] from the plane
30    #[doc(alias = "graphene_plane_distance")]
31    pub fn distance(&self, point: &Point3D) -> f32 {
32        unsafe { ffi::graphene_plane_distance(self.to_glib_none().0, point.to_glib_none().0) }
33    }
34
35    #[doc(alias = "graphene_plane_equal")]
36    fn equal(&self, b: &Plane) -> bool {
37        unsafe { ffi::graphene_plane_equal(self.to_glib_none().0, b.to_glib_none().0) }
38    }
39
40    /// Retrieves the distance along the normal vector of the
41    /// given [`Plane`][crate::Plane] from the origin.
42    ///
43    /// # Returns
44    ///
45    /// the constant value of the plane
46    #[doc(alias = "graphene_plane_get_constant")]
47    #[doc(alias = "get_constant")]
48    pub fn constant(&self) -> f32 {
49        unsafe { ffi::graphene_plane_get_constant(self.to_glib_none().0) }
50    }
51
52    /// Retrieves the normal vector pointing towards the origin of the
53    /// given [`Plane`][crate::Plane].
54    ///
55    /// # Returns
56    ///
57    ///
58    /// ## `normal`
59    /// return location for the normal vector
60    #[doc(alias = "graphene_plane_get_normal")]
61    #[doc(alias = "get_normal")]
62    pub fn normal(&self) -> Vec3 {
63        unsafe {
64            let mut normal = Vec3::uninitialized();
65            ffi::graphene_plane_get_normal(self.to_glib_none().0, normal.to_glib_none_mut().0);
66            normal
67        }
68    }
69
70    /// Negates the normal vector and constant of a [`Plane`][crate::Plane], effectively
71    /// mirroring the plane across the origin.
72    ///
73    /// # Returns
74    ///
75    ///
76    /// ## `res`
77    /// return location for the negated plane
78    #[doc(alias = "graphene_plane_negate")]
79    #[must_use]
80    pub fn negate(&self) -> Plane {
81        unsafe {
82            let mut res = Plane::uninitialized();
83            ffi::graphene_plane_negate(self.to_glib_none().0, res.to_glib_none_mut().0);
84            res
85        }
86    }
87
88    /// Normalizes the vector of the given [`Plane`][crate::Plane],
89    /// and adjusts the constant accordingly.
90    ///
91    /// # Returns
92    ///
93    ///
94    /// ## `res`
95    /// return location for the normalized plane
96    #[doc(alias = "graphene_plane_normalize")]
97    #[must_use]
98    pub fn normalize(&self) -> Plane {
99        unsafe {
100            let mut res = Plane::uninitialized();
101            ffi::graphene_plane_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
102            res
103        }
104    }
105
106    /// Transforms a [`Plane`][crate::Plane] `self` using the given `matrix`
107    /// and `normal_matrix`.
108    ///
109    /// If `normal_matrix` is [`None`], a transformation matrix for the plane
110    /// normal will be computed from `matrix`. If you are transforming
111    /// multiple planes using the same `matrix` it's recommended to compute
112    /// the normal matrix beforehand to avoid incurring in the cost of
113    /// recomputing it every time.
114    /// ## `matrix`
115    /// a [`Matrix`][crate::Matrix]
116    /// ## `normal_matrix`
117    /// a [`Matrix`][crate::Matrix]
118    ///
119    /// # Returns
120    ///
121    ///
122    /// ## `res`
123    /// the transformed plane
124    #[doc(alias = "graphene_plane_transform")]
125    #[must_use]
126    pub fn transform(&self, matrix: &Matrix, normal_matrix: Option<&Matrix>) -> Plane {
127        unsafe {
128            let mut res = Plane::uninitialized();
129            ffi::graphene_plane_transform(
130                self.to_glib_none().0,
131                matrix.to_glib_none().0,
132                normal_matrix.to_glib_none().0,
133                res.to_glib_none_mut().0,
134            );
135            res
136        }
137    }
138}
139
140impl PartialEq for Plane {
141    #[inline]
142    fn eq(&self, other: &Self) -> bool {
143        self.equal(other)
144    }
145}
146
147impl Eq for Plane {}