mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
Merge pull request #6266 from penpot/superalex-fix-path-unions
🐛 Fix unions for new render
This commit is contained in:
@@ -76,18 +76,6 @@ pub struct Path {
|
|||||||
open: bool,
|
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 {
|
impl Default for Path {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Path::try_from(Vec::new()).unwrap()
|
Path::try_from(Vec::new()).unwrap()
|
||||||
@@ -105,29 +93,36 @@ impl TryFrom<Vec<RawPathData>> for Path {
|
|||||||
.collect::<Result<Vec<Segment>, String>>()?;
|
.collect::<Result<Vec<Segment>, String>>()?;
|
||||||
|
|
||||||
let mut skia_path = skia::Path::new();
|
let mut skia_path = skia::Path::new();
|
||||||
|
let mut start = None;
|
||||||
|
|
||||||
for segment in segments.iter() {
|
for segment in segments.iter() {
|
||||||
match *segment {
|
let destination = match *segment {
|
||||||
Segment::MoveTo(xy) => {
|
Segment::MoveTo(xy) => {
|
||||||
|
start = Some(xy);
|
||||||
skia_path.move_to(xy);
|
skia_path.move_to(xy);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
Segment::LineTo(xy) => {
|
Segment::LineTo(xy) => {
|
||||||
skia_path.line_to(xy);
|
skia_path.line_to(xy);
|
||||||
|
Some(xy)
|
||||||
}
|
}
|
||||||
Segment::CurveTo((c1, c2, xy)) => {
|
Segment::CurveTo((c1, c2, xy)) => {
|
||||||
skia_path.cubic_to(c1, c2, xy);
|
skia_path.cubic_to(c1, c2, xy);
|
||||||
|
Some(xy)
|
||||||
}
|
}
|
||||||
Segment::Close => {
|
Segment::Close => {
|
||||||
skia_path.close();
|
skia_path.close();
|
||||||
open = false;
|
open = false;
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
if let (Some(start), Some(destination)) = (start, destination) {
|
||||||
|
if destination == start {
|
||||||
if !skia_path.is_last_contour_closed() && starts_and_ends_at_same_point(&skia_path) {
|
|
||||||
skia_path.close();
|
skia_path.close();
|
||||||
open = false;
|
open = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(Path {
|
Ok(Path {
|
||||||
segments,
|
segments,
|
||||||
skia_path,
|
skia_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user