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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// 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 crate::Vec4;
use glib::translate::*;

glib::wrapper! {
    /// A 2D plane that extends infinitely in a 3D volume.
    ///
    /// The contents of the `graphene_plane_t` are private, and should not be
    /// modified directly.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Plane(Boxed<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 _),
        init => |_ptr| (),
        clear => |_ptr| (),
        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) }
    }

    /// Checks whether the two given [`Plane`][crate::Plane] are equal.
    /// ## `b`
    /// a [`Plane`][crate::Plane]
    ///
    /// # Returns
    ///
    /// `true` if the given planes are equal
    #[doc(alias = "graphene_plane_equal")]
    fn equal(&self, b: &Plane) -> bool {
        unsafe {
            from_glib(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
        }
    }

    /// Initializes the given [`Plane`][crate::Plane] using the given `normal` vector
    /// and `constant` values.
    /// ## `normal`
    /// a unit length normal vector defining the plane
    ///  pointing towards the origin; if unset, we use the X axis by default
    /// ## `constant`
    /// the distance from the origin to the plane along the
    ///  normal vector; the sign determines the half-space occupied by the
    ///  plane
    ///
    /// # Returns
    ///
    /// the initialized plane
    #[doc(alias = "graphene_plane_init")]
    pub fn init(&mut self, normal: Option<&Vec3>, constant: f32) {
        unsafe {
            ffi::graphene_plane_init(self.to_glib_none_mut().0, normal.to_glib_none().0, constant);
        }
    }

    /// Initializes the given [`Plane`][crate::Plane] using the normal
    /// vector and constant of another [`Plane`][crate::Plane].
    /// ## `src`
    /// a [`Plane`][crate::Plane]
    ///
    /// # Returns
    ///
    /// the initialized plane
    #[doc(alias = "graphene_plane_init_from_plane")]
    pub fn init_from_plane(&mut self, src: &Plane) {
        unsafe {
            ffi::graphene_plane_init_from_plane(self.to_glib_none_mut().0, src.to_glib_none().0);
        }
    }

    /// Initializes the given [`Plane`][crate::Plane] using the given normal vector
    /// and an arbitrary co-planar point.
    /// ## `normal`
    /// a normal vector defining the plane pointing towards the origin
    /// ## `point`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the initialized plane
    #[doc(alias = "graphene_plane_init_from_point")]
    pub fn init_from_point(&mut self, normal: &Vec3, point: &Point3D) {
        unsafe {
            ffi::graphene_plane_init_from_point(
                self.to_glib_none_mut().0,
                normal.to_glib_none().0,
                point.to_glib_none().0,
            );
        }
    }

    /// Initializes the given [`Plane`][crate::Plane] using the 3 provided co-planar
    /// points.
    ///
    /// The winding order is counter-clockwise, and determines which direction
    /// the normal vector will point.
    /// ## `a`
    /// a [`Point3D`][crate::Point3D]
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    /// ## `c`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the initialized plane
    #[doc(alias = "graphene_plane_init_from_points")]
    pub fn init_from_points(&mut self, a: &Point3D, b: &Point3D, c: &Point3D) {
        unsafe {
            ffi::graphene_plane_init_from_points(
                self.to_glib_none_mut().0,
                a.to_glib_none().0,
                b.to_glib_none().0,
                c.to_glib_none().0,
            );
        }
    }

    /// Initializes the given [`Plane`][crate::Plane] using the components of
    /// the given [`Vec4`][crate::Vec4] vector.
    /// ## `src`
    /// a [`Vec4`][crate::Vec4] containing the normal vector in its first
    ///  three components, and the distance in its fourth component
    ///
    /// # Returns
    ///
    /// the initialized plane
    #[doc(alias = "graphene_plane_init_from_vec4")]
    pub fn init_from_vec4(&mut self, src: &Vec4) {
        unsafe {
            ffi::graphene_plane_init_from_vec4(self.to_glib_none_mut().0, src.to_glib_none().0);
        }
    }

    /// 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")]
    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")]
    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")]
    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 {}