1use crate::bridge::ffi;
4use crate::path::Path;
5use crate::point::Point;
6use cxx::UniquePtr;
7
8pub struct PathMeasure {
14 inner: UniquePtr<ffi::PathMeasureHolder>,
15}
16
17impl PathMeasure {
18 pub fn new() -> Self {
20 Self {
21 inner: ffi::measure_new(),
22 }
23 }
24
25 pub fn from_path(path: &Path, force_closed: bool, res_scale: f32) -> Self {
31 Self {
32 inner: ffi::measure_from_path(path.as_raw(), force_closed, res_scale),
33 }
34 }
35
36 pub fn set_path(&mut self, path: &Path, force_closed: bool) {
38 ffi::measure_set_path(self.inner.pin_mut(), path.as_raw(), force_closed);
39 }
40
41 pub fn length(&mut self) -> f32 {
44 ffi::measure_length(self.inner.pin_mut())
45 }
46
47 pub fn pos_tan(&mut self, distance: f32) -> Option<(Point, Point)> {
53 let mut position = ffi::Point { fX: 0.0, fY: 0.0 };
54 let mut tangent = ffi::Point { fX: 0.0, fY: 0.0 };
55 let ok = ffi::measure_get_pos_tan(
56 self.inner.pin_mut(),
57 distance,
58 &mut position,
59 &mut tangent,
60 );
61 if ok {
62 Some((position.into(), tangent.into()))
63 } else {
64 None
65 }
66 }
67
68 pub fn get_segment(
73 &mut self,
74 start_d: f32,
75 stop_d: f32,
76 dst: &mut Path,
77 start_with_move_to: bool,
78 ) -> bool {
79 ffi::measure_get_segment(
80 self.inner.pin_mut(),
81 start_d,
82 stop_d,
83 dst.as_raw_pin_mut(),
84 start_with_move_to,
85 )
86 }
87
88 pub fn is_closed(&mut self) -> bool {
90 ffi::measure_is_closed(self.inner.pin_mut())
91 }
92
93 pub fn next_contour(&mut self) -> bool {
96 ffi::measure_next_contour(self.inner.pin_mut())
97 }
98}
99
100impl Default for PathMeasure {
101 fn default() -> Self {
102 Self::new()
103 }
104}