1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Matrix;
use crate::Point3D;
use crate::Vec3;
use glib::translate::*;

glib::wrapper! {
    /// A 2D plane that extends infinitely in a 3D volume.
    ///
    /// The contents of the [`Plane`][crate::Plane] are private, and should not be
    /// modified directly.
    pub struct Plane(BoxedInline<ffi::graphene_plane_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_plane_get_type(), ptr as *mut _) as *mut ffi::graphene_plane_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_plane_get_type(), ptr as *mut _),
        type_ => || ffi::graphene_plane_get_type(),
    }
}

impl Plane {
    /// Computes the distance of `point` from a [`Plane`][crate::Plane].
    /// ## `point`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the distance of the given [`Point3D`][crate::Point3D] from the plane
    #[doc(alias = "graphene_plane_distance")]
    pub fn distance(&self, point: &Point3D) -> f32 {
        unsafe { ffi::graphene_plane_distance(self.to_glib_none().0, point.to_glib_none().0) }
    }

    #[doc(alias = "graphene_plane_equal")]
    fn equal(&self, b: &Plane) -> bool {
        unsafe { ffi::graphene_plane_equal(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Retrieves the distance along the normal vector of the
    /// given [`Plane`][crate::Plane] from the origin.
    ///
    /// # Returns
    ///
    /// the constant value of the plane
    #[doc(alias = "graphene_plane_get_constant")]
    #[doc(alias = "get_constant")]
    pub fn constant(&self) -> f32 {
        unsafe { ffi::graphene_plane_get_constant(self.to_glib_none().0) }
    }

    /// Retrieves the normal vector pointing towards the origin of the
    /// given [`Plane`][crate::Plane].
    ///
    /// # Returns
    ///
    ///
    /// ## `normal`
    /// return location for the normal vector
    #[doc(alias = "graphene_plane_get_normal")]
    #[doc(alias = "get_normal")]
    pub fn normal(&self) -> Vec3 {
        unsafe {
            let mut normal = Vec3::uninitialized();
            ffi::graphene_plane_get_normal(self.to_glib_none().0, normal.to_glib_none_mut().0);
            normal
        }
    }

    /// Negates the normal vector and constant of a [`Plane`][crate::Plane], effectively
    /// mirroring the plane across the origin.
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the negated plane
    #[doc(alias = "graphene_plane_negate")]
    #[must_use]
    pub fn negate(&self) -> Plane {
        unsafe {
            let mut res = Plane::uninitialized();
            ffi::graphene_plane_negate(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Normalizes the vector of the given [`Plane`][crate::Plane],
    /// and adjusts the constant accordingly.
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the normalized plane
    #[doc(alias = "graphene_plane_normalize")]
    #[must_use]
    pub fn normalize(&self) -> Plane {
        unsafe {
            let mut res = Plane::uninitialized();
            ffi::graphene_plane_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Transforms a [`Plane`][crate::Plane] `self` using the given `matrix`
    /// and `normal_matrix`.
    ///
    /// If `normal_matrix` is [`None`], a transformation matrix for the plane
    /// normal will be computed from `matrix`. If you are transforming
    /// multiple planes using the same `matrix` it's recommended to compute
    /// the normal matrix beforehand to avoid incurring in the cost of
    /// recomputing it every time.
    /// ## `matrix`
    /// a [`Matrix`][crate::Matrix]
    /// ## `normal_matrix`
    /// a [`Matrix`][crate::Matrix]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the transformed plane
    #[doc(alias = "graphene_plane_transform")]
    #[must_use]
    pub fn transform(&self, matrix: &Matrix, normal_matrix: Option<&Matrix>) -> Plane {
        unsafe {
            let mut res = Plane::uninitialized();
            ffi::graphene_plane_transform(
                self.to_glib_none().0,
                matrix.to_glib_none().0,
                normal_matrix.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }
}

impl PartialEq for Plane {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Plane {}