graphene/auto/
box2_d.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, Point, Rect, Vec2};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A 2D box, described as the axis-aligned area between a minimum and
10    /// a maximum vertices lying on the same plane.
11    pub struct Box2D(BoxedInline<ffi::graphene_box2d_t>);
12
13    match fn {
14        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_box2d_get_type(), ptr as *mut _) as *mut ffi::graphene_box2d_t,
15        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_box2d_get_type(), ptr as *mut _),
16        type_ => || ffi::graphene_box2d_get_type(),
17    }
18}
19
20impl Box2D {
21    /// Checks whether the [`Box2D`][crate::Box2D] `self` contains the given
22    /// [`Box2D`][crate::Box2D] `b`.
23    /// ## `b`
24    /// a [`Box2D`][crate::Box2D]
25    ///
26    /// # Returns
27    ///
28    /// `true` if the box is contained in the given box
29    #[doc(alias = "graphene_box2d_contains_box")]
30    pub fn contains_box(&self, b: &Box2D) -> bool {
31        unsafe { ffi::graphene_box2d_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_box2d_contains_point")]
42    pub fn contains_point(&self, point: &Point) -> bool {
43        unsafe { ffi::graphene_box2d_contains_point(self.to_glib_none().0, point.to_glib_none().0) }
44    }
45
46    /// Checks whether `self` contains the given `rect`.
47    /// ## `rect`
48    /// the rectangle to check
49    ///
50    /// # Returns
51    ///
52    /// `true` if the rectangle is contained in the given box
53    #[doc(alias = "graphene_box2d_contains_rect")]
54    pub fn contains_rect(&self, rect: &Rect) -> bool {
55        unsafe { ffi::graphene_box2d_contains_rect(self.to_glib_none().0, rect.to_glib_none().0) }
56    }
57
58    #[doc(alias = "graphene_box2d_equal")]
59    fn equal(&self, b: &Box2D) -> bool {
60        unsafe { ffi::graphene_box2d_equal(self.to_glib_none().0, b.to_glib_none().0) }
61    }
62
63    /// Expands the dimensions of `self` to include the coordinates at `point`.
64    /// ## `point`
65    /// the coordinates of the point to include
66    ///
67    /// # Returns
68    ///
69    ///
70    /// ## `res`
71    /// return location for the expanded box
72    #[doc(alias = "graphene_box2d_expand")]
73    #[must_use]
74    pub fn expand(&self, point: &Point) -> Box2D {
75        unsafe {
76            let mut res = Box2D::uninitialized();
77            ffi::graphene_box2d_expand(
78                self.to_glib_none().0,
79                point.to_glib_none().0,
80                res.to_glib_none_mut().0,
81            );
82            res
83        }
84    }
85
86    /// Expands the dimensions of `self` by the given `scalar` value.
87    ///
88    /// If `scalar` is positive, the [`Box2D`][crate::Box2D] will grow; if `scalar` is
89    /// negative, the [`Box2D`][crate::Box2D] will shrink.
90    /// ## `scalar`
91    /// a scalar value
92    ///
93    /// # Returns
94    ///
95    ///
96    /// ## `res`
97    /// return location for the expanded box
98    #[doc(alias = "graphene_box2d_expand_scalar")]
99    #[must_use]
100    pub fn expand_scalar(&self, scalar: f32) -> Box2D {
101        unsafe {
102            let mut res = Box2D::uninitialized();
103            ffi::graphene_box2d_expand_scalar(
104                self.to_glib_none().0,
105                scalar,
106                res.to_glib_none_mut().0,
107            );
108            res
109        }
110    }
111
112    /// Expands the dimensions of `self` to include the coordinates of the
113    /// given vector.
114    /// ## `vec`
115    /// the coordinates of the point to include, as a [`Vec2`][crate::Vec2]
116    ///
117    /// # Returns
118    ///
119    ///
120    /// ## `res`
121    /// return location for the expanded box
122    #[doc(alias = "graphene_box2d_expand_vec2")]
123    #[must_use]
124    pub fn expand_vec2(&self, vec: &Vec2) -> Box2D {
125        unsafe {
126            let mut res = Box2D::uninitialized();
127            ffi::graphene_box2d_expand_vec2(
128                self.to_glib_none().0,
129                vec.to_glib_none().0,
130                res.to_glib_none_mut().0,
131            );
132            res
133        }
134    }
135
136    /// Retrieves the coordinates of the center of a [`Box2D`][crate::Box2D].
137    ///
138    /// # Returns
139    ///
140    ///
141    /// ## `center`
142    /// return location for the coordinates of
143    ///  the center
144    #[doc(alias = "graphene_box2d_get_center")]
145    #[doc(alias = "get_center")]
146    pub fn center(&self) -> Point {
147        unsafe {
148            let mut center = Point::uninitialized();
149            ffi::graphene_box2d_get_center(self.to_glib_none().0, center.to_glib_none_mut().0);
150            center
151        }
152    }
153
154    /// Retrieves the size of the `self` on the Y axis.
155    ///
156    /// # Returns
157    ///
158    /// the height of the box
159    #[doc(alias = "graphene_box2d_get_height")]
160    #[doc(alias = "get_height")]
161    pub fn height(&self) -> f32 {
162        unsafe { ffi::graphene_box2d_get_height(self.to_glib_none().0) }
163    }
164
165    /// Retrieves the coordinates of the maximum point of the given
166    /// [`Box2D`][crate::Box2D].
167    ///
168    /// # Returns
169    ///
170    ///
171    /// ## `max`
172    /// return location for the maximum point
173    #[doc(alias = "graphene_box2d_get_max")]
174    #[doc(alias = "get_max")]
175    pub fn max(&self) -> Point {
176        unsafe {
177            let mut max = Point::uninitialized();
178            ffi::graphene_box2d_get_max(self.to_glib_none().0, max.to_glib_none_mut().0);
179            max
180        }
181    }
182
183    /// Retrieves the coordinates of the minimum point of the given
184    /// [`Box2D`][crate::Box2D].
185    ///
186    /// # Returns
187    ///
188    ///
189    /// ## `min`
190    /// return location for the minimum point
191    #[doc(alias = "graphene_box2d_get_min")]
192    #[doc(alias = "get_min")]
193    pub fn min(&self) -> Point {
194        unsafe {
195            let mut min = Point::uninitialized();
196            ffi::graphene_box2d_get_min(self.to_glib_none().0, min.to_glib_none_mut().0);
197            min
198        }
199    }
200
201    /// Retrieves the coordinates of the minimum and maximum points of the
202    /// given [`Box2D`][crate::Box2D].
203    ///
204    /// # Returns
205    ///
206    ///
207    /// ## `min`
208    /// return location for the minimum point
209    ///
210    /// ## `max`
211    /// return location for the maximum point
212    #[doc(alias = "graphene_box2d_get_minmax")]
213    #[doc(alias = "get_minmax")]
214    pub fn minmax(&self) -> (Point, Point) {
215        unsafe {
216            let mut min = Point::uninitialized();
217            let mut max = Point::uninitialized();
218            ffi::graphene_box2d_get_minmax(
219                self.to_glib_none().0,
220                min.to_glib_none_mut().0,
221                max.to_glib_none_mut().0,
222            );
223            (min, max)
224        }
225    }
226
227    /// Retrieves the size of the box on all three axes, and stores
228    /// it into the given `size` vector.
229    ///
230    /// # Returns
231    ///
232    ///
233    /// ## `size`
234    /// return location for the size
235    #[doc(alias = "graphene_box2d_get_size")]
236    #[doc(alias = "get_size")]
237    pub fn size(&self) -> Vec2 {
238        unsafe {
239            let mut size = Vec2::uninitialized();
240            ffi::graphene_box2d_get_size(self.to_glib_none().0, size.to_glib_none_mut().0);
241            size
242        }
243    }
244
245    /// Retrieves the size of the `self` on the X axis.
246    ///
247    /// # Returns
248    ///
249    /// the width of the box
250    #[doc(alias = "graphene_box2d_get_width")]
251    #[doc(alias = "get_width")]
252    pub fn width(&self) -> f32 {
253        unsafe { ffi::graphene_box2d_get_width(self.to_glib_none().0) }
254    }
255
256    /// Intersects the two given [`Box2D`][crate::Box2D].
257    ///
258    /// If the two boxes do not intersect, `res` will contain a degenerate box
259    /// initialized with [`empty()`][Self::empty()].
260    /// ## `b`
261    /// a [`Box2D`][crate::Box2D]
262    ///
263    /// # Returns
264    ///
265    /// true if the two boxes intersect
266    ///
267    /// ## `res`
268    /// return location for the result
269    #[doc(alias = "graphene_box2d_intersection")]
270    pub fn intersection(&self, b: &Box2D) -> Option<Box2D> {
271        unsafe {
272            let mut res = Box2D::uninitialized();
273            let ret = ffi::graphene_box2d_intersection(
274                self.to_glib_none().0,
275                b.to_glib_none().0,
276                res.to_glib_none_mut().0,
277            );
278            if ret {
279                Some(res)
280            } else {
281                None
282            }
283        }
284    }
285
286    /// Checks whether two boxes intersect.
287    ///
288    /// See also: [`intersection()`][Self::intersection()]
289    /// ## `b`
290    /// a [`Box2D`][crate::Box2D]
291    ///
292    /// # Returns
293    ///
294    /// true if the boxes intersect, and false otherwise
295    #[doc(alias = "graphene_box2d_intersects")]
296    pub fn intersects(&self, b: &Box2D) -> bool {
297        unsafe { ffi::graphene_box2d_intersects(self.to_glib_none().0, b.to_glib_none().0) }
298    }
299
300    /// Applies a scale and an offset to the vertices of the given box.
301    ///
302    /// If `scale` is [`None`], the box will be scaled by (1.0, 1.0).
303    ///
304    /// If `offset` is [`None`], the box will be offset by (0.0, 0.0).
305    /// ## `scale`
306    /// a vector with two scaling factors to be applied to the box
307    /// ## `offset`
308    /// the offset to apply to the box
309    ///
310    /// # Returns
311    ///
312    ///
313    /// ## `res`
314    /// the transformed box
315    #[doc(alias = "graphene_box2d_scale_offset")]
316    #[must_use]
317    pub fn scale_offset(&self, scale: Option<&Vec2>, offset: Option<&Point>) -> Box2D {
318        unsafe {
319            let mut res = Box2D::uninitialized();
320            ffi::graphene_box2d_scale_offset(
321                self.to_glib_none().0,
322                scale.to_glib_none().0,
323                offset.to_glib_none().0,
324                res.to_glib_none_mut().0,
325            );
326            res
327        }
328    }
329
330    /// Stores the minimum and maximum vertices of the given [`Box2D`][crate::Box2D]
331    /// into a rectangle of equivalent origin and size.
332    ///
333    /// # Returns
334    ///
335    ///
336    /// ## `rect`
337    /// the rectangle to initialize
338    #[doc(alias = "graphene_box2d_to_rect")]
339    pub fn to_rect(&self) -> Rect {
340        unsafe {
341            let mut rect = Rect::uninitialized();
342            ffi::graphene_box2d_to_rect(self.to_glib_none().0, rect.to_glib_none_mut().0);
343            rect
344        }
345    }
346
347    /// Unions the two given [`Box2D`][crate::Box2D].
348    /// ## `b`
349    /// the box to union to `self`
350    ///
351    /// # Returns
352    ///
353    ///
354    /// ## `res`
355    /// return location for the result
356    #[doc(alias = "graphene_box2d_union")]
357    #[must_use]
358    pub fn union(&self, b: &Box2D) -> Box2D {
359        unsafe {
360            let mut res = Box2D::uninitialized();
361            ffi::graphene_box2d_union(
362                self.to_glib_none().0,
363                b.to_glib_none().0,
364                res.to_glib_none_mut().0,
365            );
366            res
367        }
368    }
369
370    /// A degenerate [`Box2D`][crate::Box2D] that can only be expanded.
371    ///
372    /// The returned value is owned by Graphene and should not be modified or freed.
373    ///
374    /// # Returns
375    ///
376    /// a [`Box2D`][crate::Box2D]
377    #[doc(alias = "graphene_box2d_empty")]
378    pub fn empty() -> Box2D {
379        assert_initialized_main_thread!();
380        unsafe { from_glib_none(ffi::graphene_box2d_empty()) }
381    }
382
383    /// A degenerate [`Box2D`][crate::Box2D] that cannot be expanded.
384    ///
385    /// The returned value is owned by Graphene and should not be modified or freed.
386    ///
387    /// # Returns
388    ///
389    /// a [`Box2D`][crate::Box2D]
390    #[doc(alias = "graphene_box2d_infinite")]
391    pub fn infinite() -> Box2D {
392        assert_initialized_main_thread!();
393        unsafe { from_glib_none(ffi::graphene_box2d_infinite()) }
394    }
395
396    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (-1, -1) and the
397    /// maximum vertex set at (0, 0).
398    ///
399    /// The returned value is owned by Graphene and should not be modified or freed.
400    ///
401    /// # Returns
402    ///
403    /// a [`Box2D`][crate::Box2D]
404    #[doc(alias = "graphene_box2d_minus_one")]
405    pub fn minus_one() -> Box2D {
406        assert_initialized_main_thread!();
407        unsafe { from_glib_none(ffi::graphene_box2d_minus_one()) }
408    }
409
410    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (0, 0) and the
411    /// maximum vertex set at (1, 1).
412    ///
413    /// The returned value is owned by Graphene and should not be modified or freed.
414    ///
415    /// # Returns
416    ///
417    /// a [`Box2D`][crate::Box2D]
418    #[doc(alias = "graphene_box2d_one")]
419    pub fn one() -> Box2D {
420        assert_initialized_main_thread!();
421        unsafe { from_glib_none(ffi::graphene_box2d_one()) }
422    }
423
424    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (-1, -1) and the
425    /// maximum vertex set at (1, 1).
426    ///
427    /// The returned value is owned by Graphene and should not be modified or freed.
428    ///
429    /// # Returns
430    ///
431    /// a [`Box2D`][crate::Box2D]
432    #[doc(alias = "graphene_box2d_one_minus_one")]
433    pub fn one_minus_one() -> Box2D {
434        assert_initialized_main_thread!();
435        unsafe { from_glib_none(ffi::graphene_box2d_one_minus_one()) }
436    }
437
438    /// A [`Box2D`][crate::Box2D] with both the minimum and maximum vertices set at (0, 0).
439    ///
440    /// The returned value is owned by Graphene and should not be modified or freed.
441    ///
442    /// # Returns
443    ///
444    /// a [`Box2D`][crate::Box2D]
445    #[doc(alias = "graphene_box2d_zero")]
446    pub fn zero() -> Box2D {
447        assert_initialized_main_thread!();
448        unsafe { from_glib_none(ffi::graphene_box2d_zero()) }
449    }
450}
451
452impl PartialEq for Box2D {
453    #[inline]
454    fn eq(&self, other: &Self) -> bool {
455        self.equal(other)
456    }
457}
458
459impl Eq for Box2D {}