path_kit/
corner_path_effect.rs1use crate::bridge::ffi;
4use crate::path::Path;
5use crate::stroke_rec::StrokeRec;
6use cxx::UniquePtr;
7
8pub struct CornerPathEffect {
11 inner: UniquePtr<ffi::PathEffectHolder>,
12}
13
14impl CornerPathEffect {
15 pub fn new(radius: f32) -> Option<Self> {
20 if radius <= 0.0 {
21 return None;
22 }
23 let inner = ffi::corner_effect_make(radius);
24 if inner.is_null() {
25 return None;
26 }
27 Some(Self { inner })
28 }
29
30 pub fn filter_path(&self, path: &Path, stroke_width: f32) -> Option<Path> {
34 let mut dst = Path::new();
35 let mut rec = StrokeRec::new_stroke(stroke_width, false);
36 let bounds = path.tight_bounds();
37 let cull: ffi::Rect = bounds.into();
38 let ok = ffi::path_effect_filter(
39 self.inner.as_ref().expect("PathEffect"),
40 dst.as_raw_pin_mut(),
41 path.as_raw(),
42 rec.pin_holder_mut(),
43 &cull,
44 );
45 if ok {
46 Some(dst)
47 } else {
48 None
49 }
50 }
51}