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
// 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 glib::translate::*;

glib::wrapper! {
    /// Defines the position and size of a rectangle. It is identical to
    /// `cairo_rectangle_int_t`.
    pub struct Rectangle(BoxedInline<ffi::GdkRectangle>);

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

impl Rectangle {
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
    #[doc(alias = "gdk_rectangle_equal")]
    fn equal(&self, rect2: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gdk_rectangle_equal(
                self.to_glib_none().0,
                rect2.to_glib_none().0,
            ))
        }
    }

    /// Calculates the intersection of two rectangles. It is allowed for
    /// `dest` to be the same as either `self` or `src2`. If the rectangles
    /// do not intersect, `dest`’s width and height is set to 0 and its x
    /// and y values are undefined. If you are only interested in whether
    /// the rectangles intersect, but not in the intersecting area itself,
    /// pass [`None`] for `dest`.
    /// ## `src2`
    /// a [`Rectangle`][crate::Rectangle]
    ///
    /// # Returns
    ///
    /// [`true`] if the rectangles intersect.
    ///
    /// ## `dest`
    /// return location for the
    /// intersection of `self` and `src2`, or [`None`]
    #[doc(alias = "gdk_rectangle_intersect")]
    pub fn intersect(&self, src2: &Rectangle) -> Option<Rectangle> {
        unsafe {
            let mut dest = Rectangle::uninitialized();
            let ret = from_glib(ffi::gdk_rectangle_intersect(
                self.to_glib_none().0,
                src2.to_glib_none().0,
                dest.to_glib_none_mut().0,
            ));
            if ret {
                Some(dest)
            } else {
                None
            }
        }
    }

    /// Calculates the union of two rectangles.
    /// The union of rectangles `self` and `src2` is the smallest rectangle which
    /// includes both `self` and `src2` within it.
    /// It is allowed for `dest` to be the same as either `self` or `src2`.
    ///
    /// Note that this function does not ignore 'empty' rectangles (ie. with
    /// zero width or height).
    /// ## `src2`
    /// a [`Rectangle`][crate::Rectangle]
    ///
    /// # Returns
    ///
    ///
    /// ## `dest`
    /// return location for the union of `self` and `src2`
    #[doc(alias = "gdk_rectangle_union")]
    #[must_use]
    pub fn union(&self, src2: &Rectangle) -> Rectangle {
        unsafe {
            let mut dest = Rectangle::uninitialized();
            ffi::gdk_rectangle_union(
                self.to_glib_none().0,
                src2.to_glib_none().0,
                dest.to_glib_none_mut().0,
            );
            dest
        }
    }
}

#[cfg(any(feature = "v3_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
impl PartialEq for Rectangle {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Rectangle {}