gsk4/auto/
path_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, Path, PathDirection, PathMeasure};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// An opaque type representing a point on a path.
10    ///
11    /// It can be queried for properties of the path at that point,
12    /// such as its tangent or its curvature.
13    ///
14    /// To obtain a [`PathPoint`][crate::PathPoint], use [`Path::closest_point()`][crate::Path::closest_point()],
15    /// [`Path::start_point()`][crate::Path::start_point()], [`Path::end_point()`][crate::Path::end_point()]
16    /// or [`PathMeasure::point()`][crate::PathMeasure::point()].
17    ///
18    /// Note that [`PathPoint`][crate::PathPoint] structs are meant to be stack-allocated,
19    /// and don't hold a reference to the path object they are obtained from.
20    /// It is the callers responsibility to keep a reference to the path
21    /// as long as the [`PathPoint`][crate::PathPoint] is used.
22    pub struct PathPoint(BoxedInline<ffi::GskPathPoint>);
23
24    match fn {
25        copy => |ptr| ffi::gsk_path_point_copy(mut_override(ptr)),
26        free => |ptr| ffi::gsk_path_point_free(ptr),
27        type_ => || ffi::gsk_path_point_get_type(),
28    }
29}
30
31impl PathPoint {
32    #[doc(alias = "gsk_path_point_compare")]
33    fn compare(&self, point2: &PathPoint) -> i32 {
34        unsafe { ffi::gsk_path_point_compare(self.to_glib_none().0, point2.to_glib_none().0) }
35    }
36
37    #[doc(alias = "gsk_path_point_equal")]
38    fn equal(&self, point2: &PathPoint) -> bool {
39        unsafe {
40            from_glib(ffi::gsk_path_point_equal(
41                self.to_glib_none().0,
42                point2.to_glib_none().0,
43            ))
44        }
45    }
46
47    /// Returns the distance from the beginning of the path
48    /// to the point.
49    /// ## `measure`
50    /// a path measure for the path
51    ///
52    /// # Returns
53    ///
54    /// the distance of @self
55    #[doc(alias = "gsk_path_point_get_distance")]
56    #[doc(alias = "get_distance")]
57    pub fn distance(&self, measure: &PathMeasure) -> f32 {
58        unsafe { ffi::gsk_path_point_get_distance(self.to_glib_none().0, measure.to_glib_none().0) }
59    }
60
61    /// Gets the position of the point.
62    /// ## `path`
63    /// the path that @self is on
64    ///
65    /// # Returns
66    ///
67    ///
68    /// ## `position`
69    /// Return location for
70    ///   the coordinates of the point
71    #[doc(alias = "gsk_path_point_get_position")]
72    #[doc(alias = "get_position")]
73    pub fn position(&self, path: &Path) -> graphene::Point {
74        unsafe {
75            let mut position = graphene::Point::uninitialized();
76            ffi::gsk_path_point_get_position(
77                self.to_glib_none().0,
78                path.to_glib_none().0,
79                position.to_glib_none_mut().0,
80            );
81            position
82        }
83    }
84
85    /// Gets the direction of the tangent at a given point.
86    ///
87    /// This is a convenience variant of [`tangent()`][Self::tangent()]
88    /// that returns the angle between the tangent and the X axis. The angle
89    /// can e.g. be used in
90    /// [gtk_snapshot_rotate()](../gtk4/method.Snapshot.rotate.html).
91    /// ## `path`
92    /// the path that @self is on
93    /// ## `direction`
94    /// the direction for which to return the rotation
95    ///
96    /// # Returns
97    ///
98    /// the angle between the tangent and the X axis, in degrees
99    #[doc(alias = "gsk_path_point_get_rotation")]
100    #[doc(alias = "get_rotation")]
101    pub fn rotation(&self, path: &Path, direction: PathDirection) -> f32 {
102        unsafe {
103            ffi::gsk_path_point_get_rotation(
104                self.to_glib_none().0,
105                path.to_glib_none().0,
106                direction.into_glib(),
107            )
108        }
109    }
110
111    /// Gets the tangent of the path at the point.
112    ///
113    /// Note that certain points on a path may not have a single
114    /// tangent, such as sharp turns. At such points, there are
115    /// two tangents — the direction of the path going into the
116    /// point, and the direction coming out of it. The @direction
117    /// argument lets you choose which one to get.
118    ///
119    /// If the path is just a single point (e.g. a circle with
120    /// radius zero), then the tangent is set to `0, 0`.
121    ///
122    /// If you want to orient something in the direction of the
123    /// path, [`rotation()`][Self::rotation()] may be more
124    /// convenient to use.
125    /// ## `path`
126    /// the path that @self is on
127    /// ## `direction`
128    /// the direction for which to return the tangent
129    ///
130    /// # Returns
131    ///
132    ///
133    /// ## `tangent`
134    /// Return location for
135    ///   the tangent at the point
136    #[doc(alias = "gsk_path_point_get_tangent")]
137    #[doc(alias = "get_tangent")]
138    pub fn tangent(&self, path: &Path, direction: PathDirection) -> graphene::Vec2 {
139        unsafe {
140            let mut tangent = graphene::Vec2::uninitialized();
141            ffi::gsk_path_point_get_tangent(
142                self.to_glib_none().0,
143                path.to_glib_none().0,
144                direction.into_glib(),
145                tangent.to_glib_none_mut().0,
146            );
147            tangent
148        }
149    }
150}
151
152impl PartialOrd for PathPoint {
153    #[inline]
154    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
155        Some(self.cmp(other))
156    }
157}
158
159impl Ord for PathPoint {
160    #[inline]
161    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
162        self.compare(other).cmp(&0)
163    }
164}
165
166impl PartialEq for PathPoint {
167    #[inline]
168    fn eq(&self, other: &Self) -> bool {
169        self.equal(other)
170    }
171}
172
173impl Eq for PathPoint {}