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    #[doc(alias = "graphene_point_equal")]
49    fn equal(&self, b: &Point) -> bool {
50        unsafe { ffi::graphene_point_equal(self.to_glib_none().0, b.to_glib_none().0) }
51    }
52
53    /// Linearly interpolates the coordinates of `self` and `b` using the
54    /// given `factor`.
55    /// ## `b`
56    /// a [`Point`][crate::Point]
57    /// ## `factor`
58    /// the linear interpolation factor
59    ///
60    /// # Returns
61    ///
62    ///
63    /// ## `res`
64    /// return location for the interpolated
65    ///  point
66    #[doc(alias = "graphene_point_interpolate")]
67    #[must_use]
68    pub fn interpolate(&self, b: &Point, factor: f64) -> Point {
69        unsafe {
70            let mut res = Point::uninitialized();
71            ffi::graphene_point_interpolate(
72                self.to_glib_none().0,
73                b.to_glib_none().0,
74                factor,
75                res.to_glib_none_mut().0,
76            );
77            res
78        }
79    }
80
81    /// Checks whether the two points `self` and `b` are within
82    /// the threshold of `epsilon`.
83    /// ## `b`
84    /// a [`Point`][crate::Point]
85    /// ## `epsilon`
86    /// threshold between the two points
87    ///
88    /// # Returns
89    ///
90    /// `true` if the distance is within `epsilon`
91    #[doc(alias = "graphene_point_near")]
92    pub fn near(&self, b: &Point, epsilon: f32) -> bool {
93        unsafe { ffi::graphene_point_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
94    }
95
96    /// Stores the coordinates of the given [`Point`][crate::Point] into a
97    /// [`Vec2`][crate::Vec2].
98    ///
99    /// # Returns
100    ///
101    ///
102    /// ## `v`
103    /// return location for the vertex
104    #[doc(alias = "graphene_point_to_vec2")]
105    pub fn to_vec2(&self) -> Vec2 {
106        unsafe {
107            let mut v = Vec2::uninitialized();
108            ffi::graphene_point_to_vec2(self.to_glib_none().0, v.to_glib_none_mut().0);
109            v
110        }
111    }
112
113    /// Returns a point fixed at (0, 0).
114    ///
115    /// # Returns
116    ///
117    /// a fixed point
118    #[doc(alias = "graphene_point_zero")]
119    pub fn zero() -> Point {
120        assert_initialized_main_thread!();
121        unsafe { from_glib_none(ffi::graphene_point_zero()) }
122    }
123}
124
125impl PartialEq for Point {
126    #[inline]
127    fn eq(&self, other: &Self) -> bool {
128        self.equal(other)
129    }
130}
131
132impl Eq for Point {}