graphene/auto/
point.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::{ffi, Vec2};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A point with two coordinates.
10    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    /// Computes the distance between `self` and `b`.
21    /// ## `b`
22    /// a [`Point`][crate::Point]
23    ///
24    /// # Returns
25    ///
26    /// the distance between the two points
27    ///
28    /// ## `d_x`
29    /// distance component on the X axis
30    ///
31    /// ## `d_y`
32    /// distance component on the Y axis
33    #[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    /// Computes the squared distance between `self` and `b`.
49    /// ## `b`
50    /// a [`Point`][crate::Point]
51    ///
52    /// # Returns
53    ///
54    /// the distance between the two points, squared
55    #[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    /// Linearly interpolates the coordinates of `self` and `b` using the
68    /// given `factor`.
69    /// ## `b`
70    /// a [`Point`][crate::Point]
71    /// ## `factor`
72    /// the linear interpolation factor
73    ///
74    /// # Returns
75    ///
76    ///
77    /// ## `res`
78    /// return location for the interpolated
79    ///  point
80    #[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    /// Checks whether the two points `self` and `b` are within
96    /// the threshold of `epsilon`.
97    /// ## `b`
98    /// a [`Point`][crate::Point]
99    /// ## `epsilon`
100    /// threshold between the two points
101    ///
102    /// # Returns
103    ///
104    /// `true` if the distance is within `epsilon`
105    #[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    /// Stores the coordinates of the given [`Point`][crate::Point] into a
111    /// [`Vec2`][crate::Vec2].
112    ///
113    /// # Returns
114    ///
115    ///
116    /// ## `v`
117    /// return location for the vertex
118    #[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    /// Returns a point fixed at (0, 0).
128    ///
129    /// # Returns
130    ///
131    /// a fixed point
132    #[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 {}