clutter/auto/point.rs
1use glib::translate::*;
2use std::mem;
3
4glib_wrapper! {
5 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
6 pub struct Point(Boxed<ffi::ClutterPoint>);
7
8 match fn {
9 copy => |ptr| ffi::clutter_point_copy(mut_override(ptr)),
10 free => |ptr| ffi::clutter_point_free(ptr),
11 get_type => || ffi::clutter_point_get_type(),
12 }
13}
14
15impl Point {
16 /// Allocates a new `Point`.
17 ///
18 /// # Returns
19 ///
20 /// the newly allocated `Point`.
21 /// Use `Point::free` to free its resources.
22 pub fn alloc() -> Point {
23 unsafe { from_glib_full(ffi::clutter_point_alloc()) }
24 }
25
26 /// Computes the distance between two `Point`.
27 /// ## `b`
28 /// a `Point`
29 /// ## `x_distance`
30 /// return location for the horizontal
31 /// distance between the points
32 /// ## `y_distance`
33 /// return location for the vertical
34 /// distance between the points
35 ///
36 /// # Returns
37 ///
38 /// the distance between the points.
39 pub fn distance(&self, b: &Point) -> (f32, f32, f32) {
40 unsafe {
41 let mut x_distance = mem::MaybeUninit::uninit();
42 let mut y_distance = mem::MaybeUninit::uninit();
43 let ret = ffi::clutter_point_distance(
44 self.to_glib_none().0,
45 b.to_glib_none().0,
46 x_distance.as_mut_ptr(),
47 y_distance.as_mut_ptr(),
48 );
49 let x_distance = x_distance.assume_init();
50 let y_distance = y_distance.assume_init();
51 (ret, x_distance, y_distance)
52 }
53 }
54
55 /// Compares two `Point` for equality.
56 /// ## `b`
57 /// the second `Point` to compare
58 ///
59 /// # Returns
60 ///
61 /// `true` if the `ClutterPoints` are equal
62 pub fn equals(&self, b: &Point) -> bool {
63 unsafe {
64 from_glib(ffi::clutter_point_equals(
65 self.to_glib_none().0,
66 b.to_glib_none().0,
67 ))
68 }
69 }
70
71 /// Initializes `self` with the given coordinates.
72 /// ## `x`
73 /// the X coordinate of the point
74 /// ## `y`
75 /// the Y coordinate of the point
76 ///
77 /// # Returns
78 ///
79 /// the initialized `Point`
80 pub fn init(&mut self, x: f32, y: f32) -> Option<Point> {
81 unsafe { from_glib_none(ffi::clutter_point_init(self.to_glib_none_mut().0, x, y)) }
82 }
83
84 /// A point centered at (0, 0).
85 ///
86 /// The returned value can be used as a guard.
87 ///
88 /// # Returns
89 ///
90 /// a point centered in (0, 0); the returned `Point`
91 /// is owned by Clutter and it should not be modified or freed.
92 pub fn zero() -> Option<Point> {
93 unsafe { from_glib_none(ffi::clutter_point_zero()) }
94 }
95}
96
97#[doc(hidden)]
98impl Uninitialized for Point {
99 #[inline]
100 unsafe fn uninitialized() -> Self {
101 Self::alloc()
102 }
103}