graphene/auto/
box_.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, Point3D, Sphere, Vec3};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A 3D box, described as the volume between a minimum and
10    /// a maximum vertices.
11    pub struct Box(BoxedInline<ffi::graphene_box_t>);
12
13    match fn {
14        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_box_get_type(), ptr as *mut _) as *mut ffi::graphene_box_t,
15        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_box_get_type(), ptr as *mut _),
16        type_ => || ffi::graphene_box_get_type(),
17    }
18}
19
20impl Box {
21    /// Checks whether the [`Box`][crate::Box] `self` contains the given
22    /// [`Box`][crate::Box] `b`.
23    /// ## `b`
24    /// a [`Box`][crate::Box]
25    ///
26    /// # Returns
27    ///
28    /// `true` if the box is contained in the given box
29    #[doc(alias = "graphene_box_contains_box")]
30    pub fn contains_box(&self, b: &Box) -> bool {
31        unsafe { ffi::graphene_box_contains_box(self.to_glib_none().0, b.to_glib_none().0) }
32    }
33
34    /// Checks whether `self` contains the given `point`.
35    /// ## `point`
36    /// the coordinates to check
37    ///
38    /// # Returns
39    ///
40    /// `true` if the point is contained in the given box
41    #[doc(alias = "graphene_box_contains_point")]
42    pub fn contains_point(&self, point: &Point3D) -> bool {
43        unsafe { ffi::graphene_box_contains_point(self.to_glib_none().0, point.to_glib_none().0) }
44    }
45
46    #[doc(alias = "graphene_box_equal")]
47    fn equal(&self, b: &Box) -> bool {
48        unsafe { ffi::graphene_box_equal(self.to_glib_none().0, b.to_glib_none().0) }
49    }
50
51    /// Expands the dimensions of `self` to include the coordinates at `point`.
52    /// ## `point`
53    /// the coordinates of the point to include
54    ///
55    /// # Returns
56    ///
57    ///
58    /// ## `res`
59    /// return location for the expanded box
60    #[doc(alias = "graphene_box_expand")]
61    #[must_use]
62    pub fn expand(&self, point: &Point3D) -> Box {
63        unsafe {
64            let mut res = Box::uninitialized();
65            ffi::graphene_box_expand(
66                self.to_glib_none().0,
67                point.to_glib_none().0,
68                res.to_glib_none_mut().0,
69            );
70            res
71        }
72    }
73
74    /// Expands the dimensions of `self` by the given `scalar` value.
75    ///
76    /// If `scalar` is positive, the [`Box`][crate::Box] will grow; if `scalar` is
77    /// negative, the [`Box`][crate::Box] will shrink.
78    /// ## `scalar`
79    /// a scalar value
80    ///
81    /// # Returns
82    ///
83    ///
84    /// ## `res`
85    /// return location for the expanded box
86    #[doc(alias = "graphene_box_expand_scalar")]
87    #[must_use]
88    pub fn expand_scalar(&self, scalar: f32) -> Box {
89        unsafe {
90            let mut res = Box::uninitialized();
91            ffi::graphene_box_expand_scalar(
92                self.to_glib_none().0,
93                scalar,
94                res.to_glib_none_mut().0,
95            );
96            res
97        }
98    }
99
100    /// Expands the dimensions of `self` to include the coordinates of the
101    /// given vector.
102    /// ## `vec`
103    /// the coordinates of the point to include, as a [`Vec3`][crate::Vec3]
104    ///
105    /// # Returns
106    ///
107    ///
108    /// ## `res`
109    /// return location for the expanded box
110    #[doc(alias = "graphene_box_expand_vec3")]
111    #[must_use]
112    pub fn expand_vec3(&self, vec: &Vec3) -> Box {
113        unsafe {
114            let mut res = Box::uninitialized();
115            ffi::graphene_box_expand_vec3(
116                self.to_glib_none().0,
117                vec.to_glib_none().0,
118                res.to_glib_none_mut().0,
119            );
120            res
121        }
122    }
123
124    /// Computes the bounding [`Sphere`][crate::Sphere] capable of containing the given
125    /// [`Box`][crate::Box].
126    ///
127    /// # Returns
128    ///
129    ///
130    /// ## `sphere`
131    /// return location for the bounding sphere
132    #[doc(alias = "graphene_box_get_bounding_sphere")]
133    #[doc(alias = "get_bounding_sphere")]
134    pub fn bounding_sphere(&self) -> Sphere {
135        unsafe {
136            let mut sphere = Sphere::uninitialized();
137            ffi::graphene_box_get_bounding_sphere(
138                self.to_glib_none().0,
139                sphere.to_glib_none_mut().0,
140            );
141            sphere
142        }
143    }
144
145    /// Retrieves the coordinates of the center of a [`Box`][crate::Box].
146    ///
147    /// # Returns
148    ///
149    ///
150    /// ## `center`
151    /// return location for the coordinates of
152    ///  the center
153    #[doc(alias = "graphene_box_get_center")]
154    #[doc(alias = "get_center")]
155    pub fn center(&self) -> Point3D {
156        unsafe {
157            let mut center = Point3D::uninitialized();
158            ffi::graphene_box_get_center(self.to_glib_none().0, center.to_glib_none_mut().0);
159            center
160        }
161    }
162
163    /// Retrieves the size of the `self` on the Z axis.
164    ///
165    /// # Returns
166    ///
167    /// the depth of the box
168    #[doc(alias = "graphene_box_get_depth")]
169    #[doc(alias = "get_depth")]
170    pub fn depth(&self) -> f32 {
171        unsafe { ffi::graphene_box_get_depth(self.to_glib_none().0) }
172    }
173
174    /// Retrieves the size of the `self` on the Y axis.
175    ///
176    /// # Returns
177    ///
178    /// the height of the box
179    #[doc(alias = "graphene_box_get_height")]
180    #[doc(alias = "get_height")]
181    pub fn height(&self) -> f32 {
182        unsafe { ffi::graphene_box_get_height(self.to_glib_none().0) }
183    }
184
185    /// Retrieves the coordinates of the maximum point of the given
186    /// [`Box`][crate::Box].
187    ///
188    /// # Returns
189    ///
190    ///
191    /// ## `max`
192    /// return location for the maximum point
193    #[doc(alias = "graphene_box_get_max")]
194    #[doc(alias = "get_max")]
195    pub fn max(&self) -> Point3D {
196        unsafe {
197            let mut max = Point3D::uninitialized();
198            ffi::graphene_box_get_max(self.to_glib_none().0, max.to_glib_none_mut().0);
199            max
200        }
201    }
202
203    /// Retrieves the coordinates of the minimum point of the given
204    /// [`Box`][crate::Box].
205    ///
206    /// # Returns
207    ///
208    ///
209    /// ## `min`
210    /// return location for the minimum point
211    #[doc(alias = "graphene_box_get_min")]
212    #[doc(alias = "get_min")]
213    pub fn min(&self) -> Point3D {
214        unsafe {
215            let mut min = Point3D::uninitialized();
216            ffi::graphene_box_get_min(self.to_glib_none().0, min.to_glib_none_mut().0);
217            min
218        }
219    }
220
221    /// Retrieves the coordinates of the minimum and maximum points of the
222    /// given [`Box`][crate::Box]
223    ///
224    /// # Returns
225    ///
226    ///
227    /// ## `min`
228    /// return location for the minimum point
229    ///
230    /// ## `max`
231    /// return location for the maximum point
232    #[cfg(feature = "v1_12")]
233    #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
234    #[doc(alias = "graphene_box_get_minmax")]
235    #[doc(alias = "get_minmax")]
236    pub fn minmax(&self) -> (Point3D, Point3D) {
237        unsafe {
238            let mut min = Point3D::uninitialized();
239            let mut max = Point3D::uninitialized();
240            ffi::graphene_box_get_minmax(
241                self.to_glib_none().0,
242                min.to_glib_none_mut().0,
243                max.to_glib_none_mut().0,
244            );
245            (min, max)
246        }
247    }
248
249    /// Retrieves the size of the box on all three axes, and stores
250    /// it into the given `size` vector.
251    ///
252    /// # Returns
253    ///
254    ///
255    /// ## `size`
256    /// return location for the size
257    #[doc(alias = "graphene_box_get_size")]
258    #[doc(alias = "get_size")]
259    pub fn size(&self) -> Vec3 {
260        unsafe {
261            let mut size = Vec3::uninitialized();
262            ffi::graphene_box_get_size(self.to_glib_none().0, size.to_glib_none_mut().0);
263            size
264        }
265    }
266
267    /// Retrieves the size of the `self` on the X axis.
268    ///
269    /// # Returns
270    ///
271    /// the width of the box
272    #[doc(alias = "graphene_box_get_width")]
273    #[doc(alias = "get_width")]
274    pub fn width(&self) -> f32 {
275        unsafe { ffi::graphene_box_get_width(self.to_glib_none().0) }
276    }
277
278    /// Intersects the two given [`Box`][crate::Box].
279    ///
280    /// If the two boxes do not intersect, `res` will contain a degenerate box
281    /// initialized with [`empty()`][Self::empty()].
282    /// ## `b`
283    /// a [`Box`][crate::Box]
284    ///
285    /// # Returns
286    ///
287    /// true if the two boxes intersect
288    ///
289    /// ## `res`
290    /// return location for the result
291    #[doc(alias = "graphene_box_intersection")]
292    pub fn intersection(&self, b: &Box) -> Option<Box> {
293        unsafe {
294            let mut res = Box::uninitialized();
295            let ret = ffi::graphene_box_intersection(
296                self.to_glib_none().0,
297                b.to_glib_none().0,
298                res.to_glib_none_mut().0,
299            );
300            if ret {
301                Some(res)
302            } else {
303                None
304            }
305        }
306    }
307
308    /// Unions the two given [`Box`][crate::Box].
309    /// ## `b`
310    /// the box to union to `self`
311    ///
312    /// # Returns
313    ///
314    ///
315    /// ## `res`
316    /// return location for the result
317    #[doc(alias = "graphene_box_union")]
318    #[must_use]
319    pub fn union(&self, b: &Box) -> Box {
320        unsafe {
321            let mut res = Box::uninitialized();
322            ffi::graphene_box_union(
323                self.to_glib_none().0,
324                b.to_glib_none().0,
325                res.to_glib_none_mut().0,
326            );
327            res
328        }
329    }
330
331    /// A degenerate [`Box`][crate::Box] that can only be expanded.
332    ///
333    /// The returned value is owned by Graphene and should not be modified or freed.
334    ///
335    /// # Returns
336    ///
337    /// a [`Box`][crate::Box]
338    #[doc(alias = "graphene_box_empty")]
339    pub fn empty() -> Box {
340        assert_initialized_main_thread!();
341        unsafe { from_glib_none(ffi::graphene_box_empty()) }
342    }
343
344    /// A degenerate [`Box`][crate::Box] that cannot be expanded.
345    ///
346    /// The returned value is owned by Graphene and should not be modified or freed.
347    ///
348    /// # Returns
349    ///
350    /// a [`Box`][crate::Box]
351    #[doc(alias = "graphene_box_infinite")]
352    pub fn infinite() -> Box {
353        assert_initialized_main_thread!();
354        unsafe { from_glib_none(ffi::graphene_box_infinite()) }
355    }
356
357    /// A [`Box`][crate::Box] with the minimum vertex set at (-1, -1, -1) and the
358    /// maximum vertex set at (0, 0, 0).
359    ///
360    /// The returned value is owned by Graphene and should not be modified or freed.
361    ///
362    /// # Returns
363    ///
364    /// a [`Box`][crate::Box]
365    #[doc(alias = "graphene_box_minus_one")]
366    pub fn minus_one() -> Box {
367        assert_initialized_main_thread!();
368        unsafe { from_glib_none(ffi::graphene_box_minus_one()) }
369    }
370
371    /// A [`Box`][crate::Box] with the minimum vertex set at (0, 0, 0) and the
372    /// maximum vertex set at (1, 1, 1).
373    ///
374    /// The returned value is owned by Graphene and should not be modified or freed.
375    ///
376    /// # Returns
377    ///
378    /// a [`Box`][crate::Box]
379    #[doc(alias = "graphene_box_one")]
380    pub fn one() -> Box {
381        assert_initialized_main_thread!();
382        unsafe { from_glib_none(ffi::graphene_box_one()) }
383    }
384
385    /// A [`Box`][crate::Box] with the minimum vertex set at (-1, -1, -1) and the
386    /// maximum vertex set at (1, 1, 1).
387    ///
388    /// The returned value is owned by Graphene and should not be modified or freed.
389    ///
390    /// # Returns
391    ///
392    /// a [`Box`][crate::Box]
393    #[doc(alias = "graphene_box_one_minus_one")]
394    pub fn one_minus_one() -> Box {
395        assert_initialized_main_thread!();
396        unsafe { from_glib_none(ffi::graphene_box_one_minus_one()) }
397    }
398
399    /// A [`Box`][crate::Box] with both the minimum and maximum vertices set at (0, 0, 0).
400    ///
401    /// The returned value is owned by Graphene and should not be modified or freed.
402    ///
403    /// # Returns
404    ///
405    /// a [`Box`][crate::Box]
406    #[doc(alias = "graphene_box_zero")]
407    pub fn zero() -> Box {
408        assert_initialized_main_thread!();
409        unsafe { from_glib_none(ffi::graphene_box_zero()) }
410    }
411}
412
413impl PartialEq for Box {
414    #[inline]
415    fn eq(&self, other: &Self) -> bool {
416        self.equal(other)
417    }
418}
419
420impl Eq for Box {}