gsk4/auto/
path_point.rs

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
// 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::{ffi, Path, PathDirection, PathMeasure};
use glib::translate::*;

glib::wrapper! {
    /// [`PathPoint`][crate::PathPoint] is an opaque type representing a point on a path.
    ///
    /// It can be queried for properties of the path at that point, such as
    /// its tangent or its curvature.
    ///
    /// To obtain a [`PathPoint`][crate::PathPoint], use [`Path::closest_point()`][crate::Path::closest_point()],
    /// [`Path::start_point()`][crate::Path::start_point()], [`Path::end_point()`][crate::Path::end_point()]
    /// or [`PathMeasure::point()`][crate::PathMeasure::point()].
    ///
    /// Note that [`PathPoint`][crate::PathPoint] structs are meant to be stack-allocated,
    /// and don't hold a reference to the path object they are obtained from.
    /// It is the callers responsibility to keep a reference to the path
    /// as long as the [`PathPoint`][crate::PathPoint] is used.
    pub struct PathPoint(BoxedInline<ffi::GskPathPoint>);

    match fn {
        copy => |ptr| ffi::gsk_path_point_copy(mut_override(ptr)),
        free => |ptr| ffi::gsk_path_point_free(ptr),
        type_ => || ffi::gsk_path_point_get_type(),
    }
}

impl PathPoint {
    #[doc(alias = "gsk_path_point_compare")]
    fn compare(&self, point2: &PathPoint) -> i32 {
        unsafe { ffi::gsk_path_point_compare(self.to_glib_none().0, point2.to_glib_none().0) }
    }

    #[doc(alias = "gsk_path_point_equal")]
    fn equal(&self, point2: &PathPoint) -> bool {
        unsafe {
            from_glib(ffi::gsk_path_point_equal(
                self.to_glib_none().0,
                point2.to_glib_none().0,
            ))
        }
    }

    /// Returns the distance from the beginning of the path
    /// to @self.
    /// ## `measure`
    /// a [`PathMeasure`][crate::PathMeasure] for the path
    ///
    /// # Returns
    ///
    /// the distance of @self
    #[doc(alias = "gsk_path_point_get_distance")]
    #[doc(alias = "get_distance")]
    pub fn distance(&self, measure: &PathMeasure) -> f32 {
        unsafe { ffi::gsk_path_point_get_distance(self.to_glib_none().0, measure.to_glib_none().0) }
    }

    /// Gets the position of the point.
    /// ## `path`
    /// the path that @self is on
    ///
    /// # Returns
    ///
    ///
    /// ## `position`
    /// Return location for
    ///   the coordinates of the point
    #[doc(alias = "gsk_path_point_get_position")]
    #[doc(alias = "get_position")]
    pub fn position(&self, path: &Path) -> graphene::Point {
        unsafe {
            let mut position = graphene::Point::uninitialized();
            ffi::gsk_path_point_get_position(
                self.to_glib_none().0,
                path.to_glib_none().0,
                position.to_glib_none_mut().0,
            );
            position
        }
    }

    /// Gets the direction of the tangent at a given point.
    ///
    /// This is a convenience variant of [`tangent()`][Self::tangent()]
    /// that returns the angle between the tangent and the X axis. The angle
    /// can e.g. be used in
    /// [gtk_snapshot_rotate()](../gtk4/method.Snapshot.rotate.html).
    /// ## `path`
    /// the path that @self is on
    /// ## `direction`
    /// the direction for which to return the rotation
    ///
    /// # Returns
    ///
    /// the angle between the tangent and the X axis, in degrees
    #[doc(alias = "gsk_path_point_get_rotation")]
    #[doc(alias = "get_rotation")]
    pub fn rotation(&self, path: &Path, direction: PathDirection) -> f32 {
        unsafe {
            ffi::gsk_path_point_get_rotation(
                self.to_glib_none().0,
                path.to_glib_none().0,
                direction.into_glib(),
            )
        }
    }

    /// Gets the tangent of the path at the point.
    ///
    /// Note that certain points on a path may not have a single
    /// tangent, such as sharp turns. At such points, there are
    /// two tangents -- the direction of the path going into the
    /// point, and the direction coming out of it. The @direction
    /// argument lets you choose which one to get.
    ///
    /// If the path is just a single point (e.g. a circle with
    /// radius zero), then @tangent is set to `0, 0`.
    ///
    /// If you want to orient something in the direction of the
    /// path, [`rotation()`][Self::rotation()] may be more
    /// convenient to use.
    /// ## `path`
    /// the path that @self is on
    /// ## `direction`
    /// the direction for which to return the tangent
    ///
    /// # Returns
    ///
    ///
    /// ## `tangent`
    /// Return location for
    ///   the tangent at the point
    #[doc(alias = "gsk_path_point_get_tangent")]
    #[doc(alias = "get_tangent")]
    pub fn tangent(&self, path: &Path, direction: PathDirection) -> graphene::Vec2 {
        unsafe {
            let mut tangent = graphene::Vec2::uninitialized();
            ffi::gsk_path_point_get_tangent(
                self.to_glib_none().0,
                path.to_glib_none().0,
                direction.into_glib(),
                tangent.to_glib_none_mut().0,
            );
            tangent
        }
    }
}

impl PartialOrd for PathPoint {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for PathPoint {
    #[inline]
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.compare(other).cmp(&0)
    }
}

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

impl Eq for PathPoint {}