gsk4/auto/path_measure.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, PathPoint};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Performs measurements on paths such as determining the length of the path.
10 ///
11 /// Many measuring operations require sampling the path length
12 /// at intermediate points. Therefore, a [`PathMeasure`][crate::PathMeasure] has
13 /// a tolerance that determines what precision is required
14 /// for such approximations.
15 ///
16 /// A [`PathMeasure`][crate::PathMeasure] struct is a reference counted struct
17 /// and should be treated as opaque.
18 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
19 pub struct PathMeasure(Shared<ffi::GskPathMeasure>);
20
21 match fn {
22 ref => |ptr| ffi::gsk_path_measure_ref(ptr),
23 unref => |ptr| ffi::gsk_path_measure_unref(ptr),
24 type_ => || ffi::gsk_path_measure_get_type(),
25 }
26}
27
28impl PathMeasure {
29 /// Creates a measure object for the given @path with the
30 /// default tolerance.
31 /// ## `path`
32 /// the path to measure
33 ///
34 /// # Returns
35 ///
36 /// a new [`PathMeasure`][crate::PathMeasure] representing @path
37 #[doc(alias = "gsk_path_measure_new")]
38 pub fn new(path: &Path) -> PathMeasure {
39 assert_initialized_main_thread!();
40 unsafe { from_glib_full(ffi::gsk_path_measure_new(path.to_glib_none().0)) }
41 }
42
43 /// Creates a measure object for the given @path and @tolerance.
44 /// ## `path`
45 /// the path to measure
46 /// ## `tolerance`
47 /// the tolerance for measuring operations
48 ///
49 /// # Returns
50 ///
51 /// a new [`PathMeasure`][crate::PathMeasure] representing @path
52 #[doc(alias = "gsk_path_measure_new_with_tolerance")]
53 #[doc(alias = "new_with_tolerance")]
54 pub fn with_tolerance(path: &Path, tolerance: f32) -> PathMeasure {
55 assert_initialized_main_thread!();
56 unsafe {
57 from_glib_full(ffi::gsk_path_measure_new_with_tolerance(
58 path.to_glib_none().0,
59 tolerance,
60 ))
61 }
62 }
63
64 /// Gets the length of the path being measured.
65 ///
66 /// The length is cached, so this function does not do any work.
67 ///
68 /// # Returns
69 ///
70 /// the length of the path measured by @self
71 #[doc(alias = "gsk_path_measure_get_length")]
72 #[doc(alias = "get_length")]
73 pub fn length(&self) -> f32 {
74 unsafe { ffi::gsk_path_measure_get_length(self.to_glib_none().0) }
75 }
76
77 /// Returns the path that the measure was created for.
78 ///
79 /// # Returns
80 ///
81 /// the path of @self
82 #[doc(alias = "gsk_path_measure_get_path")]
83 #[doc(alias = "get_path")]
84 pub fn path(&self) -> Path {
85 unsafe { from_glib_none(ffi::gsk_path_measure_get_path(self.to_glib_none().0)) }
86 }
87
88 /// Gets the point at the given distance into the path.
89 ///
90 /// An empty path has no points, so false is returned in that case.
91 /// ## `distance`
92 /// the distance
93 ///
94 /// # Returns
95 ///
96 /// true if @result was set
97 ///
98 /// ## `result`
99 /// return location for the point
100 #[doc(alias = "gsk_path_measure_get_point")]
101 #[doc(alias = "get_point")]
102 pub fn point(&self, distance: f32) -> Option<PathPoint> {
103 unsafe {
104 let mut result = PathPoint::uninitialized();
105 let ret = from_glib(ffi::gsk_path_measure_get_point(
106 self.to_glib_none().0,
107 distance,
108 result.to_glib_none_mut().0,
109 ));
110 if ret {
111 Some(result)
112 } else {
113 None
114 }
115 }
116 }
117
118 /// Returns the tolerance that the measure was created with.
119 ///
120 /// # Returns
121 ///
122 /// the tolerance of @self
123 #[doc(alias = "gsk_path_measure_get_tolerance")]
124 #[doc(alias = "get_tolerance")]
125 pub fn tolerance(&self) -> f32 {
126 unsafe { ffi::gsk_path_measure_get_tolerance(self.to_glib_none().0) }
127 }
128}