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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// 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::*;
use std::mem;

glib::wrapper! {
    /// A point with two coordinates.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct Point(Boxed<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 _),
        init => |_ptr| (),
        clear => |_ptr| (),
        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 = mem::MaybeUninit::uninit();
            let mut d_y = 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(),
            );
            let d_x = d_x.assume_init();
            let d_y = d_y.assume_init();
            (ret, d_x, d_y)
        }
    }

    /// Checks if the two points `self` and `b` point to the same
    /// coordinates.
    ///
    /// This function accounts for floating point fluctuations; if
    /// you want to control the fuzziness of the match, you can use
    /// [`near()`][Self::near()] instead.
    /// ## `b`
    /// a [`Point`][crate::Point]
    ///
    /// # Returns
    ///
    /// `true` if the points have the same coordinates
    #[doc(alias = "graphene_point_equal")]
    fn equal(&self, b: &Point) -> bool {
        unsafe {
            from_glib(ffi::graphene_point_equal(
                self.to_glib_none().0,
                b.to_glib_none().0,
            ))
        }
    }

    /// Initializes `self` to the given `x` and `y` coordinates.
    ///
    /// It's safe to call this function multiple times.
    /// ## `x`
    /// the X coordinate
    /// ## `y`
    /// the Y coordinate
    ///
    /// # Returns
    ///
    /// the initialized point
    #[doc(alias = "graphene_point_init")]
    pub fn init(&mut self, x: f32, y: f32) {
        unsafe {
            ffi::graphene_point_init(self.to_glib_none_mut().0, x, y);
        }
    }

    /// Initializes `self` with the same coordinates of `src`.
    /// ## `src`
    /// the [`Point`][crate::Point] to use
    ///
    /// # Returns
    ///
    /// the initialized point
    #[doc(alias = "graphene_point_init_from_point")]
    pub fn init_from_point(&mut self, src: &Point) {
        unsafe {
            ffi::graphene_point_init_from_point(self.to_glib_none_mut().0, src.to_glib_none().0);
        }
    }

    /// Initializes `self` with the coordinates inside the given [`Vec2`][crate::Vec2].
    /// ## `src`
    /// a [`Vec2`][crate::Vec2]
    ///
    /// # Returns
    ///
    /// the initialized point
    #[doc(alias = "graphene_point_init_from_vec2")]
    pub fn init_from_vec2(&mut self, src: &Vec2) {
        unsafe {
            ffi::graphene_point_init_from_vec2(self.to_glib_none_mut().0, src.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")]
    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 {
            from_glib(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 {}