1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Vec2;
use glib::translate::*;

glib::wrapper! {
    /// A point with two coordinates.
    pub struct Point(BoxedInline<ffi::graphene_point_t>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::graphene_point_get_type(), ptr as *mut _) as *mut ffi::graphene_point_t,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::graphene_point_get_type(), ptr as *mut _),
        type_ => || ffi::graphene_point_get_type(),
    }
}

impl Point {
    /// Computes the distance between `self` and `b`.
    /// ## `b`
    /// a [`Point`][crate::Point]
    ///
    /// # Returns
    ///
    /// the distance between the two points
    ///
    /// ## `d_x`
    /// distance component on the X axis
    ///
    /// ## `d_y`
    /// distance component on the Y axis
    #[doc(alias = "graphene_point_distance")]
    pub fn distance(&self, b: &Point) -> (f32, f32, f32) {
        unsafe {
            let mut d_x = std::mem::MaybeUninit::uninit();
            let mut d_y = std::mem::MaybeUninit::uninit();
            let ret = ffi::graphene_point_distance(
                self.to_glib_none().0,
                b.to_glib_none().0,
                d_x.as_mut_ptr(),
                d_y.as_mut_ptr(),
            );
            (ret, d_x.assume_init(), d_y.assume_init())
        }
    }

    #[doc(alias = "graphene_point_equal")]
    fn equal(&self, b: &Point) -> bool {
        unsafe { ffi::graphene_point_equal(self.to_glib_none().0, b.to_glib_none().0) }
    }

    /// Linearly interpolates the coordinates of `self` and `b` using the
    /// given `factor`.
    /// ## `b`
    /// a [`Point`][crate::Point]
    /// ## `factor`
    /// the linear interpolation factor
    ///
    /// # Returns
    ///
    ///
    /// ## `res`
    /// return location for the interpolated
    ///  point
    #[doc(alias = "graphene_point_interpolate")]
    #[must_use]
    pub fn interpolate(&self, b: &Point, factor: f64) -> Point {
        unsafe {
            let mut res = Point::uninitialized();
            ffi::graphene_point_interpolate(
                self.to_glib_none().0,
                b.to_glib_none().0,
                factor,
                res.to_glib_none_mut().0,
            );
            res
        }
    }

    /// Checks whether the two points `self` and `b` are within
    /// the threshold of `epsilon`.
    /// ## `b`
    /// a [`Point`][crate::Point]
    /// ## `epsilon`
    /// threshold between the two points
    ///
    /// # Returns
    ///
    /// `true` if the distance is within `epsilon`
    #[doc(alias = "graphene_point_near")]
    pub fn near(&self, b: &Point, epsilon: f32) -> bool {
        unsafe { ffi::graphene_point_near(self.to_glib_none().0, b.to_glib_none().0, epsilon) }
    }

    /// Stores the coordinates of the given [`Point`][crate::Point] into a
    /// [`Vec2`][crate::Vec2].
    ///
    /// # Returns
    ///
    ///
    /// ## `v`
    /// return location for the vertex
    #[doc(alias = "graphene_point_to_vec2")]
    pub fn to_vec2(&self) -> Vec2 {
        unsafe {
            let mut v = Vec2::uninitialized();
            ffi::graphene_point_to_vec2(self.to_glib_none().0, v.to_glib_none_mut().0);
            v
        }
    }

    /// Returns a point fixed at (0, 0).
    ///
    /// # Returns
    ///
    /// a fixed point
    #[doc(alias = "graphene_point_zero")]
    pub fn zero() -> Point {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::graphene_point_zero()) }
    }
}

impl PartialEq for Point {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Point {}