Skip to content

Commit

Permalink
graphics: add stroked line segment when closing stroked path
Browse files Browse the repository at this point in the history
When closing a stroked path, add a full stroked line segment from the current
point to the current path component's start point, rather than just a line
join.
  • Loading branch information
micahrj committed Dec 3, 2024
1 parent aac3ff9 commit eb40c59
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion reflector-graphics/src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,15 @@ pub fn stroke(path: &Path, width: f32, transform: Affine, sink: &mut impl FnMut(
let mut stroker = Stroker::new(width, transform, sink);

let mut points = path.points.iter();
let mut first = Point::new(0.0, 0.0);
let mut prev = Point::new(0.0, 0.0);
for verb in &path.verbs {
match *verb {
Verb::Move => {
stroker.finish();
prev = *points.next().unwrap();

first = *points.next().unwrap();
prev = first;
}
Verb::Line => {
let p1 = *points.next().unwrap();
Expand All @@ -438,6 +441,14 @@ pub fn stroke(path: &Path, width: f32, transform: Affine, sink: &mut impl FnMut(
prev = p3;
}
Verb::Close => {
if prev != first {
stroker.stroke_curve(&Line {
p0: prev,
p1: first,
});
}
prev = first;

stroker.close();
}
}
Expand Down

0 comments on commit eb40c59

Please sign in to comment.