diff --git a/render-wasm/src/shapes/paths.rs b/render-wasm/src/shapes/paths.rs index 5f0741842c..a09ec3c545 100644 --- a/render-wasm/src/shapes/paths.rs +++ b/render-wasm/src/shapes/paths.rs @@ -76,18 +76,6 @@ pub struct Path { open: bool, } -fn starts_and_ends_at_same_point(path: &skia::Path) -> bool { - if path.count_points() < 2 { - return false; // A path with fewer than 2 points cannot be closed - } - - let start_point = path.get_point(0); // First point of the path - let end_point = path.get_point(path.count_points() - 1); // Last point of the path - - // Compare the start and end points - start_point == end_point -} - impl Default for Path { fn default() -> Self { Path::try_from(Vec::new()).unwrap() @@ -105,29 +93,36 @@ impl TryFrom> for Path { .collect::, String>>()?; let mut skia_path = skia::Path::new(); + let mut start = None; + for segment in segments.iter() { - match *segment { + let destination = match *segment { Segment::MoveTo(xy) => { + start = Some(xy); skia_path.move_to(xy); + None } Segment::LineTo(xy) => { skia_path.line_to(xy); + Some(xy) } Segment::CurveTo((c1, c2, xy)) => { skia_path.cubic_to(c1, c2, xy); + Some(xy) } Segment::Close => { skia_path.close(); open = false; + None + } + }; + if let (Some(start), Some(destination)) = (start, destination) { + if destination == start { + skia_path.close(); + open = false; } } } - - if !skia_path.is_last_contour_closed() && starts_and_ends_at_same_point(&skia_path) { - skia_path.close(); - open = false; - } - Ok(Path { segments, skia_path,