1use crate::{ffi, Vec2};
6use glib::translate::*;
7
8glib::wrapper! {
9    pub struct Point(BoxedInline<ffi::graphene_point_t>);
11
12    match fn {
13        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_point_get_type(), ptr as *mut _) as *mut ffi::graphene_point_t,
14        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_point_get_type(), ptr as *mut _),
15        type_ => || ffi::graphene_point_get_type(),
16    }
17}
18
19impl Point {
20    #[doc(alias = "graphene_point_distance")]
34    pub fn distance(&self, b: &Point) -> (f32, f32, f32) {
35        unsafe {
36            let mut d_x = std::mem::MaybeUninit::uninit();
37            let mut d_y = std::mem::MaybeUninit::uninit();
38            let ret = ffi::graphene_point_distance(
39                self.to_glib_none().0,
40                b.to_glib_none().0,
41                d_x.as_mut_ptr(),
42                d_y.as_mut_ptr(),
43            );
44            (ret, d_x.assume_init(), d_y.assume_init())
45        }
46    }
47
48    #[cfg(feature = "v1_12")]
56    #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
57    #[doc(alias = "graphene_point_distance_squared")]
58    pub fn distance_squared(&self, b: &Point) -> f32 {
59        unsafe { ffi::graphene_point_distance_squared(self.to_glib_none().0, b.to_glib_none().0) }
60    }
61
62    #[doc(alias = "graphene_point_equal")]
63    fn equal(&self, b: &Point) -> bool {
64        unsafe { ffi::graphene_point_equal(self.to_glib_none().0, b.to_glib_none().0) }
65    }
66
67    #[doc(alias = "graphene_point_interpolate")]
81    #[must_use]
82    pub fn interpolate(&self, b: &Point, factor: f64) -> Point {
83        unsafe {
84            let mut res = Point::uninitialized();
85            ffi::graphene_point_interpolate(
86                self.to_glib_none().0,
87                b.to_glib_none().0,
88                factor,
89                res.to_glib_none_mut().0,
90            );
91            res
92        }
93    }
94
95    #[doc(alias = "graphene_point_near")]
106    pub fn near(&self, b: &Point, epsilon: f32) -> bool {
107        unsafe { ffi::graphene_point_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
108    }
109
110    #[doc(alias = "graphene_point_to_vec2")]
119    pub fn to_vec2(&self) -> Vec2 {
120        unsafe {
121            let mut v = Vec2::uninitialized();
122            ffi::graphene_point_to_vec2(self.to_glib_none().0, v.to_glib_none_mut().0);
123            v
124        }
125    }
126
127    #[doc(alias = "graphene_point_zero")]
133    pub fn zero() -> Point {
134        assert_initialized_main_thread!();
135        unsafe { from_glib_none(ffi::graphene_point_zero()) }
136    }
137}
138
139impl PartialEq for Point {
140    #[inline]
141    fn eq(&self, other: &Self) -> bool {
142        self.equal(other)
143    }
144}
145
146impl Eq for Point {}