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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
// 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::{Point3D, Sphere, Vec3};
use glib::translate::*;

glib::wrapper! {
    /// A 3D box, described as the volume between a minimum and
    /// a maximum vertices.
    pub struct Box(BoxedInline<ffi::graphene_box_t>);

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

impl Box {
    /// Checks whether the [`Box`][crate::Box] `self` contains the given
    /// [`Box`][crate::Box] `b`.
    /// ## `b`
    /// a [`Box`][crate::Box]
    ///
    /// # Returns
    ///
    /// `true` if the box is contained in the given box
    #[doc(alias = "graphene_box_contains_box")]
    pub fn contains_box(&self, b: &Box) -> bool {
        unsafe { ffi::graphene_box_contains_box(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Checks whether `self` contains the given `point`.
    /// ## `point`
    /// the coordinates to check
    ///
    /// # Returns
    ///
    /// `true` if the point is contained in the given box
    #[doc(alias = "graphene_box_contains_point")]
    pub fn contains_point(&self, point: &Point3D) -> bool {
        unsafe { ffi::graphene_box_contains_point(self.to_glib_none().0, point.to_glib_none().0) }
    }

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

    /// Expands the dimensions of `self` to include the coordinates at `point`.
    /// ## `point`
    /// the coordinates of the point to include
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the expanded box
    #[doc(alias = "graphene_box_expand")]
    #[must_use]
    pub fn expand(&self, point: &Point3D) -> Box {
        unsafe {
            let mut res = Box::uninitialized();
            ffi::graphene_box_expand(
                self.to_glib_none().0,
                point.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Expands the dimensions of `self` by the given `scalar` value.
    ///
    /// If `scalar` is positive, the [`Box`][crate::Box] will grow; if `scalar` is
    /// negative, the [`Box`][crate::Box] will shrink.
    /// ## `scalar`
    /// a scalar value
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the expanded box
    #[doc(alias = "graphene_box_expand_scalar")]
    #[must_use]
    pub fn expand_scalar(&self, scalar: f32) -> Box {
        unsafe {
            let mut res = Box::uninitialized();
            ffi::graphene_box_expand_scalar(
                self.to_glib_none().0,
                scalar,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Expands the dimensions of `self` to include the coordinates of the
    /// given vector.
    /// ## `vec`
    /// the coordinates of the point to include, as a [`Vec3`][crate::Vec3]
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the expanded box
    #[doc(alias = "graphene_box_expand_vec3")]
    #[must_use]
    pub fn expand_vec3(&self, vec: &Vec3) -> Box {
        unsafe {
            let mut res = Box::uninitialized();
            ffi::graphene_box_expand_vec3(
                self.to_glib_none().0,
                vec.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Computes the bounding [`Sphere`][crate::Sphere] capable of containing the given
    /// [`Box`][crate::Box].
    ///
    /// # Returns
    ///
    ///
    /// ## `sphere`
    /// return location for the bounding sphere
    #[doc(alias = "graphene_box_get_bounding_sphere")]
    #[doc(alias = "get_bounding_sphere")]
    pub fn bounding_sphere(&self) -> Sphere {
        unsafe {
            let mut sphere = Sphere::uninitialized();
            ffi::graphene_box_get_bounding_sphere(
                self.to_glib_none().0,
                sphere.to_glib_none_mut().0,
            );
            sphere
        }
    }

    /// Retrieves the coordinates of the center of a [`Box`][crate::Box].
    ///
    /// # Returns
    ///
    ///
    /// ## `center`
    /// return location for the coordinates of
    ///  the center
    #[doc(alias = "graphene_box_get_center")]
    #[doc(alias = "get_center")]
    pub fn center(&self) -> Point3D {
        unsafe {
            let mut center = Point3D::uninitialized();
            ffi::graphene_box_get_center(self.to_glib_none().0, center.to_glib_none_mut().0);
            center
        }
    }

    /// Retrieves the size of the `self` on the Z axis.
    ///
    /// # Returns
    ///
    /// the depth of the box
    #[doc(alias = "graphene_box_get_depth")]
    #[doc(alias = "get_depth")]
    pub fn depth(&self) -> f32 {
        unsafe { ffi::graphene_box_get_depth(self.to_glib_none().0) }
    }

    /// Retrieves the size of the `self` on the Y axis.
    ///
    /// # Returns
    ///
    /// the height of the box
    #[doc(alias = "graphene_box_get_height")]
    #[doc(alias = "get_height")]
    pub fn height(&self) -> f32 {
        unsafe { ffi::graphene_box_get_height(self.to_glib_none().0) }
    }

    /// Retrieves the coordinates of the maximum point of the given
    /// [`Box`][crate::Box].
    ///
    /// # Returns
    ///
    ///
    /// ## `max`
    /// return location for the maximum point
    #[doc(alias = "graphene_box_get_max")]
    #[doc(alias = "get_max")]
    pub fn max(&self) -> Point3D {
        unsafe {
            let mut max = Point3D::uninitialized();
            ffi::graphene_box_get_max(self.to_glib_none().0, max.to_glib_none_mut().0);
            max
        }
    }

    /// Retrieves the coordinates of the minimum point of the given
    /// [`Box`][crate::Box].
    ///
    /// # Returns
    ///
    ///
    /// ## `min`
    /// return location for the minimum point
    #[doc(alias = "graphene_box_get_min")]
    #[doc(alias = "get_min")]
    pub fn min(&self) -> Point3D {
        unsafe {
            let mut min = Point3D::uninitialized();
            ffi::graphene_box_get_min(self.to_glib_none().0, min.to_glib_none_mut().0);
            min
        }
    }

    /// Retrieves the size of the box on all three axes, and stores
    /// it into the given `size` vector.
    ///
    /// # Returns
    ///
    ///
    /// ## `size`
    /// return location for the size
    #[doc(alias = "graphene_box_get_size")]
    #[doc(alias = "get_size")]
    pub fn size(&self) -> Vec3 {
        unsafe {
            let mut size = Vec3::uninitialized();
            ffi::graphene_box_get_size(self.to_glib_none().0, size.to_glib_none_mut().0);
            size
        }
    }

    /// Retrieves the size of the `self` on the X axis.
    ///
    /// # Returns
    ///
    /// the width of the box
    #[doc(alias = "graphene_box_get_width")]
    #[doc(alias = "get_width")]
    pub fn width(&self) -> f32 {
        unsafe { ffi::graphene_box_get_width(self.to_glib_none().0) }
    }

    /// Intersects the two given [`Box`][crate::Box].
    ///
    /// If the two boxes do not intersect, `res` will contain a degenerate box
    /// initialized with [`empty()`][Self::empty()].
    /// ## `b`
    /// a [`Box`][crate::Box]
    ///
    /// # Returns
    ///
    /// true if the two boxes intersect
    ///
    /// ## `res`
    /// return location for the result
    #[doc(alias = "graphene_box_intersection")]
    pub fn intersection(&self, b: &Box) -> Option<Box> {
        unsafe {
            let mut res = Box::uninitialized();
            let ret = ffi::graphene_box_intersection(
                self.to_glib_none().0,
                b.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            if ret {
                Some(res)
            } else {
                None
            }
        }
    }

    /// Unions the two given [`Box`][crate::Box].
    /// ## `b`
    /// the box to union to `self`
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the result
    #[doc(alias = "graphene_box_union")]
    #[must_use]
    pub fn union(&self, b: &Box) -> Box {
        unsafe {
            let mut res = Box::uninitialized();
            ffi::graphene_box_union(
                self.to_glib_none().0,
                b.to_glib_none().0,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// A degenerate [`Box`][crate::Box] that can only be expanded.
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_empty")]
    pub fn empty() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_empty()) }
    }

    /// A degenerate [`Box`][crate::Box] that cannot be expanded.
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_infinite")]
    pub fn infinite() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_infinite()) }
    }

    /// A [`Box`][crate::Box] with the minimum vertex set at (-1, -1, -1) and the
    /// maximum vertex set at (0, 0, 0).
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_minus_one")]
    pub fn minus_one() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_minus_one()) }
    }

    /// A [`Box`][crate::Box] with the minimum vertex set at (0, 0, 0) and the
    /// maximum vertex set at (1, 1, 1).
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_one")]
    pub fn one() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_one()) }
    }

    /// A [`Box`][crate::Box] with the minimum vertex set at (-1, -1, -1) and the
    /// maximum vertex set at (1, 1, 1).
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_one_minus_one")]
    pub fn one_minus_one() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_one_minus_one()) }
    }

    /// A [`Box`][crate::Box] with both the minimum and maximum vertices set at (0, 0, 0).
    ///
    /// The returned value is owned by Graphene and should not be modified or freed.
    ///
    /// # Returns
    ///
    /// a [`Box`][crate::Box]
    #[doc(alias = "graphene_box_zero")]
    pub fn zero() -> Box {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_box_zero()) }
    }
}

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

impl Eq for Box {}