🐛 Fix unions for new render

This commit is contained in:
Alejandro Alonso 2025-04-10 11:05:17 +02:00
parent 43535ae573
commit 8ebaecc472

View file

@ -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<Vec<RawPathData>> for Path {
.collect::<Result<Vec<Segment>, 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 !skia_path.is_last_contour_closed() && starts_and_ends_at_same_point(&skia_path) {
};
if let (Some(start), Some(destination)) = (start, destination) {
if destination == start {
skia_path.close();
open = false;
}
}
}
Ok(Path {
segments,
skia_path,