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
// 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::{Rect, Vec3};
use glib::translate::*;

glib::wrapper! {
    /// A point with three components: X, Y, and Z.
    pub struct Point3D(BoxedInline<ffi::graphene_point3d_t>);

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

impl Point3D {
    /// Computes the cross product of the two given [`Point3D`][crate::Point3D].
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the cross
    ///  product
    #[doc(alias = "graphene_point3d_cross")]
    #[must_use]
    pub fn cross(&self, b: &Point3D) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_point3d_cross(
                self.to_glib_none().0,
                b.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Computes the distance between the two given [`Point3D`][crate::Point3D].
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the distance between two points
    ///
    /// ## `delta`
    /// return location for the distance
    ///  components on the X, Y, and Z axis
    #[doc(alias = "graphene_point3d_distance")]
    pub fn distance(&self, b: &Point3D) -> (f32, Vec3) {
        unsafe {
            let mut delta = Vec3::uninitialized();
            let ret = ffi::graphene_point3d_distance(
                self.to_glib_none().0,
                b.to_glib_none().0,
                delta.to_glib_none_mut().0,
            );
            (ret, delta)
        }
    }

    /// Computes the dot product of the two given [`Point3D`][crate::Point3D].
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    ///
    /// # Returns
    ///
    /// the value of the dot product
    #[doc(alias = "graphene_point3d_dot")]
    pub fn dot(&self, b: &Point3D) -> f32 {
        unsafe { ffi::graphene_point3d_dot(self.to_glib_none().0, b.to_glib_none().0) }
    }

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

    /// Linearly interpolates each component of `self` and `b` using the
    /// provided `factor`, and places the result in `res`.
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    /// ## `factor`
    /// the interpolation factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the return location for the
    ///  interpolated [`Point3D`][crate::Point3D]
    #[doc(alias = "graphene_point3d_interpolate")]
    #[must_use]
    pub fn interpolate(&self, b: &Point3D, factor: f64) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_point3d_interpolate(
                self.to_glib_none().0,
                b.to_glib_none().0,
                factor,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Computes the length of the vector represented by the
    /// coordinates of the given [`Point3D`][crate::Point3D].
    ///
    /// # Returns
    ///
    /// the length of the vector represented by the point
    #[doc(alias = "graphene_point3d_length")]
    pub fn length(&self) -> f32 {
        unsafe { ffi::graphene_point3d_length(self.to_glib_none().0) }
    }

    /// Checks whether the two points are near each other, within
    /// an `epsilon` factor.
    /// ## `b`
    /// a [`Point3D`][crate::Point3D]
    /// ## `epsilon`
    /// fuzzyness factor
    ///
    /// # Returns
    ///
    /// `true` if the points are near each other
    #[doc(alias = "graphene_point3d_near")]
    pub fn near(&self, b: &Point3D, epsilon: f32) -> bool {
        unsafe { ffi::graphene_point3d_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
    }

    /// Computes the normalization of the vector represented by the
    /// coordinates of the given [`Point3D`][crate::Point3D].
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the normalized
    ///  [`Point3D`][crate::Point3D]
    #[doc(alias = "graphene_point3d_normalize")]
    #[must_use]
    pub fn normalize(&self) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_point3d_normalize(self.to_glib_none().0, res.to_glib_none_mut().0);
            res
        }
    }

    /// Normalizes the coordinates of a [`Point3D`][crate::Point3D] using the
    /// given viewport and clipping planes.
    ///
    /// The coordinates of the resulting [`Point3D`][crate::Point3D] will be
    /// in the [ -1, 1 ] range.
    /// ## `viewport`
    /// a [`Rect`][crate::Rect] representing a viewport
    /// ## `z_near`
    /// the coordinate of the near clipping plane, or 0 for
    ///  the default near clipping plane
    /// ## `z_far`
    /// the coordinate of the far clipping plane, or 1 for the
    ///  default far clipping plane
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// the return location for the
    ///  normalized [`Point3D`][crate::Point3D]
    #[doc(alias = "graphene_point3d_normalize_viewport")]
    #[must_use]
    pub fn normalize_viewport(&self, viewport: &Rect, z_near: f32, z_far: f32) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_point3d_normalize_viewport(
                self.to_glib_none().0,
                viewport.to_glib_none().0,
                z_near,
                z_far,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Scales the coordinates of the given [`Point3D`][crate::Point3D] by
    /// the given `factor`.
    /// ## `factor`
    /// the scaling factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the scaled point
    #[doc(alias = "graphene_point3d_scale")]
    #[must_use]
    pub fn scale(&self, factor: f32) -> Point3D {
        unsafe {
            let mut res = Point3D::uninitialized();
            ffi::graphene_point3d_scale(self.to_glib_none().0, factor, res.to_glib_none_mut().0);
            res
        }
    }

    /// Stores the coordinates of a [`Point3D`][crate::Point3D] into a
    /// [`Vec3`][crate::Vec3].
    ///
    /// # Returns
    ///
    ///
    /// ## `v`
    /// return location for a [`Vec3`][crate::Vec3]
    #[doc(alias = "graphene_point3d_to_vec3")]
    pub fn to_vec3(&self) -> Vec3 {
        unsafe {
            let mut v = Vec3::uninitialized();
            ffi::graphene_point3d_to_vec3(self.to_glib_none().0, v.to_glib_none_mut().0);
            v
        }
    }

    /// Retrieves a constant point with all three coordinates set to 0.
    ///
    /// # Returns
    ///
    /// a zero point
    #[doc(alias = "graphene_point3d_zero")]
    pub fn zero() -> Point3D {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_point3d_zero()) }
    }
}

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

impl Eq for Point3D {}