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
// Generated by gir (https://github.com/gtk-rs/gir @ d7c0763cacbc)
// from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
// DO NOT EDIT

use crate::{ffi, Buffer, RectangleAlignment};
use glib::translate::*;

glib::wrapper! {
    pub struct Rectangle(BoxedInline<ffi::GeglRectangle>);

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

impl Rectangle {
    /// Creates a new rectangle set with the values from `x`, `y`, `width` and `height`.
    /// ## `x`
    /// upper left x coordinate
    /// ## `y`
    /// upper left y coordinate
    /// ## `width`
    /// width in pixels.
    /// ## `height`
    /// height in pixels.
    #[doc(alias = "gegl_rectangle_new")]
    pub fn new(x: i32, y: i32, width: u32, height: u32) -> Rectangle {
        unsafe { from_glib_full(ffi::gegl_rectangle_new(x, y, width, height)) }
    }

    /// Aligns `rectangle` to a regular tile grid, of which `tile` is a representative
    /// tile, and stores the result in `self`.
    ///
    /// `alignment` can be one of:
    ///
    ///  GEGL_RECTANGLE_ALIGNMENT_SUBSET: Calculate the biggest aligned rectangle
    ///  contained in `rectangle`.
    ///
    ///  GEGL_RECTANGLE_ALIGNMENT_SUPERSET: Calculate the smallest aligned
    ///  rectangle containing `rectangle`.
    ///
    ///  GEGL_RECTANGLE_ALIGNMENT_NEAREST: Calculate the nearest aligned rectangle
    ///  to `rectangle`.
    ///
    /// `self` may point to the same object as `rectangle` or `tile`.
    ///
    /// Returns TRUE if the result is not empty.
    /// ## `rectangle`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `tile`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `alignment`
    /// a [`RectangleAlignment`][crate::RectangleAlignment] value
    #[doc(alias = "gegl_rectangle_align")]
    pub fn align(
        &mut self,
        rectangle: &Rectangle,
        tile: &Rectangle,
        alignment: RectangleAlignment,
    ) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_align(
                self.to_glib_none_mut().0,
                rectangle.to_glib_none().0,
                tile.to_glib_none().0,
                alignment.into_glib(),
            ))
        }
    }

    /// Aligns `rectangle` to the tile grid of `buffer`, and stores the result in
    /// `self`.
    ///
    /// `alignment` has the same meaning as for [`align()`][Self::align()].
    ///
    /// `self` may point to the same object as `rectangle`.
    ///
    /// Returns TRUE if the result is not empty.
    /// ## `rectangle`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `buffer`
    /// a [`Buffer`][crate::Buffer]
    /// ## `alignment`
    /// a [`RectangleAlignment`][crate::RectangleAlignment] value
    #[doc(alias = "gegl_rectangle_align_to_buffer")]
    pub fn align_to_buffer(
        &mut self,
        rectangle: &Rectangle,
        buffer: &Buffer,
        alignment: RectangleAlignment,
    ) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_align_to_buffer(
                self.to_glib_none_mut().0,
                rectangle.to_glib_none().0,
                buffer.to_glib_none().0,
                alignment.into_glib(),
            ))
        }
    }

    /// Computes the bounding box of the rectangles `source1` and `source2` and stores the
    /// resulting bounding box in `self`.
    ///
    /// `self` may point to the same object as `source1` or `source2`.
    /// ## `source1`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `source2`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_bounding_box")]
    pub fn bounding_box(&mut self, source1: &Rectangle, source2: &Rectangle) {
        unsafe {
            ffi::gegl_rectangle_bounding_box(
                self.to_glib_none_mut().0,
                source1.to_glib_none().0,
                source2.to_glib_none().0,
            );
        }
    }

    /// Checks if the [`Rectangle`][crate::Rectangle] `child` is fully contained within `self`.
    ///
    /// Returns TRUE if the `child` is fully contained in `self`.
    /// ## `child`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_contains")]
    pub fn contains(&self, child: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_contains(
                self.to_glib_none().0,
                child.to_glib_none().0,
            ))
        }
    }

    /// For debugging purposes, not stable API.
    #[doc(alias = "gegl_rectangle_dump")]
    pub fn dump(&self) {
        unsafe {
            ffi::gegl_rectangle_dump(self.to_glib_none().0);
        }
    }

    /// Create a new copy of `self`.
    ///
    /// # Returns
    ///
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_dup")]
    #[must_use]
    pub fn dup(&self) -> Option<Rectangle> {
        unsafe { from_glib_full(ffi::gegl_rectangle_dup(self.to_glib_none().0)) }
    }

    #[doc(alias = "gegl_rectangle_equal")]
    fn equal(&self, rectangle2: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_equal(
                self.to_glib_none().0,
                rectangle2.to_glib_none().0,
            ))
        }
    }

    /// Check if a rectangle is equal to a set of parameters.
    ///
    /// Returns TRUE if `self` and `x`,`y` `width` x `height` are equal.
    /// ## `x`
    /// X coordinate
    /// ## `y`
    /// Y coordinate
    /// ## `width`
    /// width of rectangle
    /// ## `height`
    /// height of rectangle
    #[doc(alias = "gegl_rectangle_equal_coords")]
    pub fn equal_coords(&self, x: i32, y: i32, width: i32, height: i32) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_equal_coords(
                self.to_glib_none().0,
                x,
                y,
                width,
                height,
            ))
        }
    }

    /// Calculates the intersection of two rectangles. If the rectangles do not
    /// intersect, dest's width and height are set to 0 and its x and y values
    /// are undefined.
    ///
    /// `self` may point to the same object as `src1` or `src2`.
    ///
    /// Returns TRUE if the rectangles intersect.
    /// ## `src1`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `src2`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_intersect")]
    pub fn intersect(&mut self, src1: &Rectangle, src2: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_intersect(
                self.to_glib_none_mut().0,
                src1.to_glib_none().0,
                src2.to_glib_none().0,
            ))
        }
    }

    /// Check if a rectangle has zero area.
    ///
    /// Returns TRUE if the width or height of `self` is 0.
    #[doc(alias = "gegl_rectangle_is_empty")]
    pub fn is_empty(&self) -> bool {
        unsafe { from_glib(ffi::gegl_rectangle_is_empty(self.to_glib_none().0)) }
    }

    /// Returns TRUE if the GeglRectangle represents an infininte plane,
    /// FALSE otherwise.
    #[doc(alias = "gegl_rectangle_is_infinite_plane")]
    pub fn is_infinite_plane(&self) -> bool {
        unsafe { from_glib(ffi::gegl_rectangle_is_infinite_plane(self.to_glib_none().0)) }
    }

    /// Sets the `x`, `y`, `width` and `height` on `self`.
    /// ## `x`
    /// upper left x coordinate
    /// ## `y`
    /// upper left y coordinate
    /// ## `width`
    /// width in pixels.
    /// ## `height`
    /// height in pixels.
    #[doc(alias = "gegl_rectangle_set")]
    pub fn set(&mut self, x: i32, y: i32, width: u32, height: u32) {
        unsafe {
            ffi::gegl_rectangle_set(self.to_glib_none_mut().0, x, y, width, height);
        }
    }

    /// Subtracts `subtrahend` from `minuend`, and stores the resulting rectangles in
    /// `self`. Between 0 and 4 disjoint rectangles may be produced.
    ///
    /// `self` may contain `minuend` or `subtrahend`.
    ///
    /// Returns the number of resulting rectangles.
    /// ## `minuend`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `subtrahend`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_subtract")]
    pub fn subtract(&mut self, minuend: &Rectangle, subtrahend: &Rectangle) -> i32 {
        unsafe {
            ffi::gegl_rectangle_subtract(
                self.to_glib_none_mut().0,
                minuend.to_glib_none().0,
                subtrahend.to_glib_none().0,
            )
        }
    }

    /// Computes the bounding box of the area formed by subtracting `subtrahend`
    /// from `minuend`, and stores the result in `self`.
    ///
    /// `self` may point to the same object as `minuend` or `subtrahend`.
    ///
    /// Returns TRUE if the result is not empty.
    /// ## `minuend`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `subtrahend`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_subtract_bounding_box")]
    pub fn subtract_bounding_box(&mut self, minuend: &Rectangle, subtrahend: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gegl_rectangle_subtract_bounding_box(
                self.to_glib_none_mut().0,
                minuend.to_glib_none().0,
                subtrahend.to_glib_none().0,
            ))
        }
    }

    /// Computes the symmetric difference of the rectangles `source1` and `source2`,
    /// and stores the resulting rectangles in `self`. Between 0 and 4
    /// disjoint rectangles may be produced.
    ///
    /// `self` may contain `rectangle1` or `rectangle2`.
    ///
    /// Returns the number of resulting rectangles.
    /// ## `source1`
    /// a [`Rectangle`][crate::Rectangle]
    /// ## `source2`
    /// a [`Rectangle`][crate::Rectangle]
    #[doc(alias = "gegl_rectangle_xor")]
    pub fn xor(&mut self, source1: &Rectangle, source2: &Rectangle) -> i32 {
        unsafe {
            ffi::gegl_rectangle_xor(
                self.to_glib_none_mut().0,
                source1.to_glib_none().0,
                source2.to_glib_none().0,
            )
        }
    }
}

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

impl Eq for Rectangle {}