gsk4/path_point.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, Path, PathDirection, PathPoint};
6
7impl PathPoint {
8 /// Calculates the curvature of the path at the point.
9 ///
10 /// Optionally, returns the center of the osculating circle as well.
11 /// The curvature is the inverse of the radius of the osculating circle.
12 ///
13 /// Lines have a curvature of zero (indicating an osculating circle of
14 /// infinite radius). In this case, the @center is not modified.
15 ///
16 /// Circles with a radius of zero have `INFINITY` as curvature
17 ///
18 /// Note that certain points on a path may not have a single curvature,
19 /// such as sharp turns. At such points, there are two curvatures — the
20 /// (limit of) the curvature of the path going into the point, and the
21 /// (limit of) the curvature of the path coming out of it. The @direction
22 /// argument lets you choose which one to get.
23 ///
24 /// <picture>
25 /// <source srcset="curvature-dark.png" media="(prefers-color-scheme: dark)">
26 /// <img alt="Osculating circle" src="curvature-light.png">
27 /// </picture>
28 /// ## `path`
29 /// the path that @self is on
30 /// ## `direction`
31 /// the direction for which to return the curvature
32 ///
33 /// # Returns
34 ///
35 /// the curvature of the path at the given point
36 ///
37 /// ## `center`
38 /// return location for
39 /// the center of the osculating circle
40 #[doc(alias = "gsk_path_point_get_curvature")]
41 #[doc(alias = "get_curvature")]
42 pub fn curvature(
43 &self,
44 path: &Path,
45 direction: PathDirection,
46 ) -> (f32, Option<graphene::Point>) {
47 unsafe {
48 let mut center = graphene::Point::uninitialized();
49 let ret = ffi::gsk_path_point_get_curvature(
50 self.to_glib_none().0,
51 path.to_glib_none().0,
52 direction.into_glib(),
53 center.to_glib_none_mut().0,
54 );
55
56 if ret == 0.0 {
57 (ret, None)
58 } else {
59 (ret, Some(center))
60 }
61 }
62 }
63}