graphene/auto/rect.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, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// The location and size of a rectangle region.
10 ///
11 /// The width and height of a [`Rect`][crate::Rect] can be negative; for instance,
12 /// a [`Rect`][crate::Rect] with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is
13 /// equivalent to a [`Rect`][crate::Rect] with an origin of [ 10, 10 ] and a size
14 /// of [ -10, -10 ].
15 ///
16 /// Application code can normalize rectangles using [`normalize()`][Self::normalize()];
17 /// this function will ensure that the width and height of a rectangle are
18 /// positive values. All functions taking a [`Rect`][crate::Rect] as an argument
19 /// will internally operate on a normalized copy; all functions returning a
20 /// [`Rect`][crate::Rect] will always return a normalized rectangle.
21 pub struct Rect(BoxedInline<ffi::graphene_rect_t>);
22
23 match fn {
24 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_rect_get_type(), ptr as *mut _) as *mut ffi::graphene_rect_t,
25 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_rect_get_type(), ptr as *mut _),
26 type_ => || ffi::graphene_rect_get_type(),
27 }
28}
29
30impl Rect {
31 /// Checks whether a [`Rect`][crate::Rect] contains the given coordinates.
32 /// ## `p`
33 /// a [`Point`][crate::Point]
34 ///
35 /// # Returns
36 ///
37 /// `true` if the rectangle contains the point
38 #[doc(alias = "graphene_rect_contains_point")]
39 pub fn contains_point(&self, p: &Point) -> bool {
40 unsafe { ffi::graphene_rect_contains_point(self.to_glib_none().0, p.to_glib_none().0) }
41 }
42
43 /// Checks whether a [`Rect`][crate::Rect] fully contains the given
44 /// rectangle.
45 /// ## `b`
46 /// a [`Rect`][crate::Rect]
47 ///
48 /// # Returns
49 ///
50 /// `true` if the rectangle `self` fully contains `b`
51 #[doc(alias = "graphene_rect_contains_rect")]
52 pub fn contains_rect(&self, b: &Rect) -> bool {
53 unsafe { ffi::graphene_rect_contains_rect(self.to_glib_none().0, b.to_glib_none().0) }
54 }
55
56 #[doc(alias = "graphene_rect_equal")]
57 fn equal(&self, b: &Rect) -> bool {
58 unsafe { ffi::graphene_rect_equal(self.to_glib_none().0, b.to_glib_none().0) }
59 }
60
61 /// Expands a [`Rect`][crate::Rect] to contain the given [`Point`][crate::Point].
62 /// ## `p`
63 /// a [`Point`][crate::Point]
64 ///
65 /// # Returns
66 ///
67 ///
68 /// ## `res`
69 /// return location for the expanded rectangle
70 #[doc(alias = "graphene_rect_expand")]
71 #[must_use]
72 pub fn expand(&self, p: &Point) -> Rect {
73 unsafe {
74 let mut res = Rect::uninitialized();
75 ffi::graphene_rect_expand(
76 self.to_glib_none().0,
77 p.to_glib_none().0,
78 res.to_glib_none_mut().0,
79 );
80 res
81 }
82 }
83
84 /// Compute the area of given normalized rectangle.
85 ///
86 /// # Returns
87 ///
88 /// the area of the normalized rectangle
89 #[doc(alias = "graphene_rect_get_area")]
90 #[doc(alias = "get_area")]
91 pub fn area(&self) -> f32 {
92 unsafe { ffi::graphene_rect_get_area(self.to_glib_none().0) }
93 }
94
95 /// Retrieves the coordinates of the bottom-left corner of the given rectangle.
96 ///
97 /// # Returns
98 ///
99 ///
100 /// ## `p`
101 /// return location for a [`Point`][crate::Point]
102 #[doc(alias = "graphene_rect_get_bottom_left")]
103 #[doc(alias = "get_bottom_left")]
104 pub fn bottom_left(&self) -> Point {
105 unsafe {
106 let mut p = Point::uninitialized();
107 ffi::graphene_rect_get_bottom_left(self.to_glib_none().0, p.to_glib_none_mut().0);
108 p
109 }
110 }
111
112 /// Retrieves the coordinates of the bottom-right corner of the given rectangle.
113 ///
114 /// # Returns
115 ///
116 ///
117 /// ## `p`
118 /// return location for a [`Point`][crate::Point]
119 #[doc(alias = "graphene_rect_get_bottom_right")]
120 #[doc(alias = "get_bottom_right")]
121 pub fn bottom_right(&self) -> Point {
122 unsafe {
123 let mut p = Point::uninitialized();
124 ffi::graphene_rect_get_bottom_right(self.to_glib_none().0, p.to_glib_none_mut().0);
125 p
126 }
127 }
128
129 /// Retrieves the coordinates of the center of the given rectangle.
130 ///
131 /// # Returns
132 ///
133 ///
134 /// ## `p`
135 /// return location for a [`Point`][crate::Point]
136 #[doc(alias = "graphene_rect_get_center")]
137 #[doc(alias = "get_center")]
138 pub fn center(&self) -> Point {
139 unsafe {
140 let mut p = Point::uninitialized();
141 ffi::graphene_rect_get_center(self.to_glib_none().0, p.to_glib_none_mut().0);
142 p
143 }
144 }
145
146 /// Retrieves the normalized height of the given rectangle.
147 ///
148 /// # Returns
149 ///
150 /// the normalized height of the rectangle
151 #[doc(alias = "graphene_rect_get_height")]
152 #[doc(alias = "get_height")]
153 pub fn height(&self) -> f32 {
154 unsafe { ffi::graphene_rect_get_height(self.to_glib_none().0) }
155 }
156
157 /// Retrieves the coordinates of the top-left corner of the given rectangle.
158 ///
159 /// # Returns
160 ///
161 ///
162 /// ## `p`
163 /// return location for a [`Point`][crate::Point]
164 #[doc(alias = "graphene_rect_get_top_left")]
165 #[doc(alias = "get_top_left")]
166 pub fn top_left(&self) -> Point {
167 unsafe {
168 let mut p = Point::uninitialized();
169 ffi::graphene_rect_get_top_left(self.to_glib_none().0, p.to_glib_none_mut().0);
170 p
171 }
172 }
173
174 /// Retrieves the coordinates of the top-right corner of the given rectangle.
175 ///
176 /// # Returns
177 ///
178 ///
179 /// ## `p`
180 /// return location for a [`Point`][crate::Point]
181 #[doc(alias = "graphene_rect_get_top_right")]
182 #[doc(alias = "get_top_right")]
183 pub fn top_right(&self) -> Point {
184 unsafe {
185 let mut p = Point::uninitialized();
186 ffi::graphene_rect_get_top_right(self.to_glib_none().0, p.to_glib_none_mut().0);
187 p
188 }
189 }
190
191 /// Retrieves the normalized width of the given rectangle.
192 ///
193 /// # Returns
194 ///
195 /// the normalized width of the rectangle
196 #[doc(alias = "graphene_rect_get_width")]
197 #[doc(alias = "get_width")]
198 pub fn width(&self) -> f32 {
199 unsafe { ffi::graphene_rect_get_width(self.to_glib_none().0) }
200 }
201
202 /// Retrieves the normalized X coordinate of the origin of the given
203 /// rectangle.
204 ///
205 /// # Returns
206 ///
207 /// the normalized X coordinate of the rectangle
208 #[doc(alias = "graphene_rect_get_x")]
209 #[doc(alias = "get_x")]
210 pub fn x(&self) -> f32 {
211 unsafe { ffi::graphene_rect_get_x(self.to_glib_none().0) }
212 }
213
214 /// Retrieves the normalized Y coordinate of the origin of the given
215 /// rectangle.
216 ///
217 /// # Returns
218 ///
219 /// the normalized Y coordinate of the rectangle
220 #[doc(alias = "graphene_rect_get_y")]
221 #[doc(alias = "get_y")]
222 pub fn y(&self) -> f32 {
223 unsafe { ffi::graphene_rect_get_y(self.to_glib_none().0) }
224 }
225
226 /// Changes the given rectangle to be smaller, or larger depending on the
227 /// given inset parameters.
228 ///
229 /// To create an inset rectangle, use positive `d_x` or `d_y` values; to
230 /// create a larger, encompassing rectangle, use negative `d_x` or `d_y`
231 /// values.
232 ///
233 /// The origin of the rectangle is offset by `d_x` and `d_y`, while the size
234 /// is adjusted by `(2 * `d_x`, 2 * `d_y`)`. If `d_x` and `d_y` are positive
235 /// values, the size of the rectangle is decreased; if `d_x` and `d_y` are
236 /// negative values, the size of the rectangle is increased.
237 ///
238 /// If the size of the resulting inset rectangle has a negative width or
239 /// height then the size will be set to zero.
240 /// ## `d_x`
241 /// the horizontal inset
242 /// ## `d_y`
243 /// the vertical inset
244 ///
245 /// # Returns
246 ///
247 /// the inset rectangle
248 #[doc(alias = "graphene_rect_inset")]
249 pub fn inset(&mut self, d_x: f32, d_y: f32) {
250 unsafe {
251 ffi::graphene_rect_inset(self.to_glib_none_mut().0, d_x, d_y);
252 }
253 }
254
255 /// Changes the given rectangle to be smaller, or larger depending on the
256 /// given inset parameters.
257 ///
258 /// To create an inset rectangle, use positive `d_x` or `d_y` values; to
259 /// create a larger, encompassing rectangle, use negative `d_x` or `d_y`
260 /// values.
261 ///
262 /// The origin of the rectangle is offset by `d_x` and `d_y`, while the size
263 /// is adjusted by `(2 * `d_x`, 2 * `d_y`)`. If `d_x` and `d_y` are positive
264 /// values, the size of the rectangle is decreased; if `d_x` and `d_y` are
265 /// negative values, the size of the rectangle is increased.
266 ///
267 /// If the size of the resulting inset rectangle has a negative width or
268 /// height then the size will be set to zero.
269 /// ## `d_x`
270 /// the horizontal inset
271 /// ## `d_y`
272 /// the vertical inset
273 ///
274 /// # Returns
275 ///
276 ///
277 /// ## `res`
278 /// return location for the inset rectangle
279 #[doc(alias = "graphene_rect_inset_r")]
280 #[must_use]
281 pub fn inset_r(&self, d_x: f32, d_y: f32) -> Rect {
282 unsafe {
283 let mut res = Rect::uninitialized();
284 ffi::graphene_rect_inset_r(self.to_glib_none().0, d_x, d_y, res.to_glib_none_mut().0);
285 res
286 }
287 }
288
289 /// Linearly interpolates the origin and size of the two given
290 /// rectangles.
291 /// ## `b`
292 /// a [`Rect`][crate::Rect]
293 /// ## `factor`
294 /// the linear interpolation factor
295 ///
296 /// # Returns
297 ///
298 ///
299 /// ## `res`
300 /// return location for the
301 /// interpolated rectangle
302 #[doc(alias = "graphene_rect_interpolate")]
303 #[must_use]
304 pub fn interpolate(&self, b: &Rect, factor: f64) -> Rect {
305 unsafe {
306 let mut res = Rect::uninitialized();
307 ffi::graphene_rect_interpolate(
308 self.to_glib_none().0,
309 b.to_glib_none().0,
310 factor,
311 res.to_glib_none_mut().0,
312 );
313 res
314 }
315 }
316
317 /// Computes the intersection of the two given rectangles.
318 ///
319 /// 
320 ///
321 /// The intersection in the image above is the blue outline.
322 ///
323 /// If the two rectangles do not intersect, `res` will contain
324 /// a degenerate rectangle with origin in (0, 0) and a size of 0.
325 /// ## `b`
326 /// a [`Rect`][crate::Rect]
327 ///
328 /// # Returns
329 ///
330 /// `true` if the two rectangles intersect
331 ///
332 /// ## `res`
333 /// return location for
334 /// a [`Rect`][crate::Rect]
335 #[doc(alias = "graphene_rect_intersection")]
336 pub fn intersection(&self, b: &Rect) -> Option<Rect> {
337 unsafe {
338 let mut res = Rect::uninitialized();
339 let ret = ffi::graphene_rect_intersection(
340 self.to_glib_none().0,
341 b.to_glib_none().0,
342 res.to_glib_none_mut().0,
343 );
344 if ret { Some(res) } else { None }
345 }
346 }
347
348 /// Normalizes the passed rectangle.
349 ///
350 /// This function ensures that the size of the rectangle is made of
351 /// positive values, and that the origin is the top-left corner of
352 /// the rectangle.
353 ///
354 /// # Returns
355 ///
356 /// the normalized rectangle
357 #[doc(alias = "graphene_rect_normalize")]
358 pub fn normalize(&mut self) {
359 unsafe {
360 ffi::graphene_rect_normalize(self.to_glib_none_mut().0);
361 }
362 }
363
364 /// Normalizes the passed rectangle.
365 ///
366 /// This function ensures that the size of the rectangle is made of
367 /// positive values, and that the origin is in the top-left corner
368 /// of the rectangle.
369 ///
370 /// # Returns
371 ///
372 ///
373 /// ## `res`
374 /// the return location for the
375 /// normalized rectangle
376 #[doc(alias = "graphene_rect_normalize_r")]
377 #[must_use]
378 pub fn normalize_r(&self) -> Rect {
379 unsafe {
380 let mut res = Rect::uninitialized();
381 ffi::graphene_rect_normalize_r(self.to_glib_none().0, res.to_glib_none_mut().0);
382 res
383 }
384 }
385
386 /// Offsets the origin by `d_x` and `d_y`.
387 ///
388 /// The size of the rectangle is unchanged.
389 /// ## `d_x`
390 /// the horizontal offset
391 /// ## `d_y`
392 /// the vertical offset
393 ///
394 /// # Returns
395 ///
396 /// the offset rectangle
397 #[doc(alias = "graphene_rect_offset")]
398 pub fn offset(&mut self, d_x: f32, d_y: f32) {
399 unsafe {
400 ffi::graphene_rect_offset(self.to_glib_none_mut().0, d_x, d_y);
401 }
402 }
403
404 /// Offsets the origin of the given rectangle by `d_x` and `d_y`.
405 ///
406 /// The size of the rectangle is left unchanged.
407 /// ## `d_x`
408 /// the horizontal offset
409 /// ## `d_y`
410 /// the vertical offset
411 ///
412 /// # Returns
413 ///
414 ///
415 /// ## `res`
416 /// return location for the offset
417 /// rectangle
418 #[doc(alias = "graphene_rect_offset_r")]
419 #[must_use]
420 pub fn offset_r(&self, d_x: f32, d_y: f32) -> Rect {
421 unsafe {
422 let mut res = Rect::uninitialized();
423 ffi::graphene_rect_offset_r(self.to_glib_none().0, d_x, d_y, res.to_glib_none_mut().0);
424 res
425 }
426 }
427
428 /// this function will make sure
429 /// that the size is recomputed taking into account the ceiling
430 /// of the coordinates of the bottom-right corner.
431 /// If the difference between the original coordinates and the
432 /// coordinates of the rounded rectangle is greater than the
433 /// difference between the original size and and the rounded
434 /// size, then the move of the origin would not be compensated
435 /// by a move in the anti-origin, leaving the corners of the
436 /// original rectangle outside the rounded one.
437 ///
438 /// # Returns
439 ///
440 ///
441 /// ## `res`
442 /// return location for the
443 /// rectangle with rounded extents
444 #[doc(alias = "graphene_rect_round_extents")]
445 #[must_use]
446 pub fn round_extents(&self) -> Rect {
447 unsafe {
448 let mut res = Rect::uninitialized();
449 ffi::graphene_rect_round_extents(self.to_glib_none().0, res.to_glib_none_mut().0);
450 res
451 }
452 }
453
454 /// Scales the size and origin of a rectangle horizontaly by `s_h`,
455 /// and vertically by `s_v`. The result `res` is normalized.
456 /// ## `s_h`
457 /// horizontal scale factor
458 /// ## `s_v`
459 /// vertical scale factor
460 ///
461 /// # Returns
462 ///
463 ///
464 /// ## `res`
465 /// return location for the
466 /// scaled rectangle
467 #[doc(alias = "graphene_rect_scale")]
468 #[must_use]
469 pub fn scale(&self, s_h: f32, s_v: f32) -> Rect {
470 unsafe {
471 let mut res = Rect::uninitialized();
472 ffi::graphene_rect_scale(self.to_glib_none().0, s_h, s_v, res.to_glib_none_mut().0);
473 res
474 }
475 }
476
477 /// Computes the union of the two given rectangles.
478 ///
479 /// 
480 ///
481 /// The union in the image above is the blue outline.
482 /// ## `b`
483 /// a [`Rect`][crate::Rect]
484 ///
485 /// # Returns
486 ///
487 ///
488 /// ## `res`
489 /// return location for a [`Rect`][crate::Rect]
490 #[doc(alias = "graphene_rect_union")]
491 #[must_use]
492 pub fn union(&self, b: &Rect) -> Rect {
493 unsafe {
494 let mut res = Rect::uninitialized();
495 ffi::graphene_rect_union(
496 self.to_glib_none().0,
497 b.to_glib_none().0,
498 res.to_glib_none_mut().0,
499 );
500 res
501 }
502 }
503
504 /// Returns a degenerate rectangle with origin fixed at (0, 0) and
505 /// a size of 0, 0.
506 ///
507 /// # Returns
508 ///
509 /// a fixed rectangle
510 #[doc(alias = "graphene_rect_zero")]
511 pub fn zero() -> Rect {
512 assert_initialized_main_thread!();
513 unsafe { from_glib_none(ffi::graphene_rect_zero()) }
514 }
515}
516
517impl PartialEq for Rect {
518 #[inline]
519 fn eq(&self, other: &Self) -> bool {
520 self.equal(other)
521 }
522}
523
524impl Eq for Rect {}