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::{Point, Rect, Vec2, ffi};
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 { Some(res) } else { None }
279        }
280    }
281
282    /// Checks whether two boxes intersect.
283    ///
284    /// See also: [`intersection()`][Self::intersection()]
285    /// ## `b`
286    /// a [`Box2D`][crate::Box2D]
287    ///
288    /// # Returns
289    ///
290    /// true if the boxes intersect, and false otherwise
291    #[doc(alias = "graphene_box2d_intersects")]
292    pub fn intersects(&self, b: &Box2D) -> bool {
293        unsafe { ffi::graphene_box2d_intersects(self.to_glib_none().0, b.to_glib_none().0) }
294    }
295
296    /// Applies a scale and an offset to the vertices of the given box.
297    ///
298    /// If `scale` is [`None`], the box will be scaled by (1.0, 1.0).
299    ///
300    /// If `offset` is [`None`], the box will be offset by (0.0, 0.0).
301    /// ## `scale`
302    /// a vector with two scaling factors to be applied to the box
303    /// ## `offset`
304    /// the offset to apply to the box
305    ///
306    /// # Returns
307    ///
308    ///
309    /// ## `res`
310    /// the transformed box
311    #[doc(alias = "graphene_box2d_scale_offset")]
312    #[must_use]
313    pub fn scale_offset(&self, scale: Option<&Vec2>, offset: Option<&Point>) -> Box2D {
314        unsafe {
315            let mut res = Box2D::uninitialized();
316            ffi::graphene_box2d_scale_offset(
317                self.to_glib_none().0,
318                scale.to_glib_none().0,
319                offset.to_glib_none().0,
320                res.to_glib_none_mut().0,
321            );
322            res
323        }
324    }
325
326    /// Stores the minimum and maximum vertices of the given [`Box2D`][crate::Box2D]
327    /// into a rectangle of equivalent origin and size.
328    ///
329    /// # Returns
330    ///
331    ///
332    /// ## `rect`
333    /// the rectangle to initialize
334    #[doc(alias = "graphene_box2d_to_rect")]
335    pub fn to_rect(&self) -> Rect {
336        unsafe {
337            let mut rect = Rect::uninitialized();
338            ffi::graphene_box2d_to_rect(self.to_glib_none().0, rect.to_glib_none_mut().0);
339            rect
340        }
341    }
342
343    /// Unions the two given [`Box2D`][crate::Box2D].
344    /// ## `b`
345    /// the box to union to `self`
346    ///
347    /// # Returns
348    ///
349    ///
350    /// ## `res`
351    /// return location for the result
352    #[doc(alias = "graphene_box2d_union")]
353    #[must_use]
354    pub fn union(&self, b: &Box2D) -> Box2D {
355        unsafe {
356            let mut res = Box2D::uninitialized();
357            ffi::graphene_box2d_union(
358                self.to_glib_none().0,
359                b.to_glib_none().0,
360                res.to_glib_none_mut().0,
361            );
362            res
363        }
364    }
365
366    /// A degenerate [`Box2D`][crate::Box2D] that can only be expanded.
367    ///
368    /// The returned value is owned by Graphene and should not be modified or freed.
369    ///
370    /// # Returns
371    ///
372    /// a [`Box2D`][crate::Box2D]
373    #[doc(alias = "graphene_box2d_empty")]
374    pub fn empty() -> Box2D {
375        assert_initialized_main_thread!();
376        unsafe { from_glib_none(ffi::graphene_box2d_empty()) }
377    }
378
379    /// A degenerate [`Box2D`][crate::Box2D] that cannot be expanded.
380    ///
381    /// The returned value is owned by Graphene and should not be modified or freed.
382    ///
383    /// # Returns
384    ///
385    /// a [`Box2D`][crate::Box2D]
386    #[doc(alias = "graphene_box2d_infinite")]
387    pub fn infinite() -> Box2D {
388        assert_initialized_main_thread!();
389        unsafe { from_glib_none(ffi::graphene_box2d_infinite()) }
390    }
391
392    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (-1, -1) and the
393    /// maximum vertex set at (0, 0).
394    ///
395    /// The returned value is owned by Graphene and should not be modified or freed.
396    ///
397    /// # Returns
398    ///
399    /// a [`Box2D`][crate::Box2D]
400    #[doc(alias = "graphene_box2d_minus_one")]
401    pub fn minus_one() -> Box2D {
402        assert_initialized_main_thread!();
403        unsafe { from_glib_none(ffi::graphene_box2d_minus_one()) }
404    }
405
406    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (0, 0) and the
407    /// maximum vertex set at (1, 1).
408    ///
409    /// The returned value is owned by Graphene and should not be modified or freed.
410    ///
411    /// # Returns
412    ///
413    /// a [`Box2D`][crate::Box2D]
414    #[doc(alias = "graphene_box2d_one")]
415    pub fn one() -> Box2D {
416        assert_initialized_main_thread!();
417        unsafe { from_glib_none(ffi::graphene_box2d_one()) }
418    }
419
420    /// A [`Box2D`][crate::Box2D] with the minimum vertex set at (-1, -1) and the
421    /// maximum vertex set at (1, 1).
422    ///
423    /// The returned value is owned by Graphene and should not be modified or freed.
424    ///
425    /// # Returns
426    ///
427    /// a [`Box2D`][crate::Box2D]
428    #[doc(alias = "graphene_box2d_one_minus_one")]
429    pub fn one_minus_one() -> Box2D {
430        assert_initialized_main_thread!();
431        unsafe { from_glib_none(ffi::graphene_box2d_one_minus_one()) }
432    }
433
434    /// A [`Box2D`][crate::Box2D] with both the minimum and maximum vertices set at (0, 0).
435    ///
436    /// The returned value is owned by Graphene and should not be modified or freed.
437    ///
438    /// # Returns
439    ///
440    /// a [`Box2D`][crate::Box2D]
441    #[doc(alias = "graphene_box2d_zero")]
442    pub fn zero() -> Box2D {
443        assert_initialized_main_thread!();
444        unsafe { from_glib_none(ffi::graphene_box2d_zero()) }
445    }
446}
447
448impl PartialEq for Box2D {
449    #[inline]
450    fn eq(&self, other: &Self) -> bool {
451        self.equal(other)
452    }
453}
454
455impl Eq for Box2D {}