1use crate::{ffi, Vec2};
6use glib::translate::*;
7
8glib::wrapper! {
9 pub struct Point(BoxedInline<ffi::graphene_point_t>);
10
11 match fn {
12 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_point_get_type(), ptr as *mut _) as *mut ffi::graphene_point_t,
13 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_point_get_type(), ptr as *mut _),
14 type_ => || ffi::graphene_point_get_type(),
15 }
16}
17
18impl Point {
19 #[doc(alias = "graphene_point_distance")]
20 pub fn distance(&self, b: &Point) -> (f32, f32, f32) {
21 unsafe {
22 let mut d_x = std::mem::MaybeUninit::uninit();
23 let mut d_y = std::mem::MaybeUninit::uninit();
24 let ret = ffi::graphene_point_distance(
25 self.to_glib_none().0,
26 b.to_glib_none().0,
27 d_x.as_mut_ptr(),
28 d_y.as_mut_ptr(),
29 );
30 (ret, d_x.assume_init(), d_y.assume_init())
31 }
32 }
33
34 #[cfg(feature = "v1_12")]
35 #[cfg_attr(docsrs, doc(cfg(feature = "v1_12")))]
36 #[doc(alias = "graphene_point_distance_squared")]
37 pub fn distance_squared(&self, b: &Point) -> f32 {
38 unsafe { ffi::graphene_point_distance_squared(self.to_glib_none().0, b.to_glib_none().0) }
39 }
40
41 #[doc(alias = "graphene_point_equal")]
42 fn equal(&self, b: &Point) -> bool {
43 unsafe { ffi::graphene_point_equal(self.to_glib_none().0, b.to_glib_none().0) }
44 }
45
46 #[doc(alias = "graphene_point_interpolate")]
47 #[must_use]
48 pub fn interpolate(&self, b: &Point, factor: f64) -> Point {
49 unsafe {
50 let mut res = Point::uninitialized();
51 ffi::graphene_point_interpolate(
52 self.to_glib_none().0,
53 b.to_glib_none().0,
54 factor,
55 res.to_glib_none_mut().0,
56 );
57 res
58 }
59 }
60
61 #[doc(alias = "graphene_point_near")]
62 pub fn near(&self, b: &Point, epsilon: f32) -> bool {
63 unsafe { ffi::graphene_point_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
64 }
65
66 #[doc(alias = "graphene_point_to_vec2")]
67 pub fn to_vec2(&self) -> Vec2 {
68 unsafe {
69 let mut v = Vec2::uninitialized();
70 ffi::graphene_point_to_vec2(self.to_glib_none().0, v.to_glib_none_mut().0);
71 v
72 }
73 }
74
75 #[doc(alias = "graphene_point_zero")]
76 pub fn zero() -> Point {
77 assert_initialized_main_thread!();
78 unsafe { from_glib_none(ffi::graphene_point_zero()) }
79 }
80}
81
82impl PartialEq for Point {
83 #[inline]
84 fn eq(&self, other: &Self) -> bool {
85 self.equal(other)
86 }
87}
88
89impl Eq for Point {}