Stroke closed paths properly

This commit is contained in:
Patrick Walton 2019-05-16 08:34:52 -07:00
parent 6eab3fa2d8
commit 1b9cfa98a9
1 changed files with 20 additions and 10 deletions

View File

@ -34,17 +34,28 @@ impl OutlineStrokeToFill {
#[inline] #[inline]
pub fn offset(&mut self) { pub fn offset(&mut self) {
let mut new_bounds = None; let mut new_contours = vec![];
for contour in &mut self.outline.contours { for input in mem::replace(&mut self.outline.contours, vec![]) {
let input = mem::replace(contour, Contour::new()); let mut stroker = ContourStrokeToFill::new(input,
let mut contour_stroke_to_fill = Contour::new(),
ContourStrokeToFill::new(input, Contour::new(), self.stroke_width * 0.5); self.stroke_width * 0.5);
contour_stroke_to_fill.offset_forward(); stroker.offset_forward();
contour_stroke_to_fill.offset_backward(); stroker.output.closed = stroker.input.closed;
*contour = contour_stroke_to_fill.output; if stroker.input.closed {
contour.update_bounds(&mut new_bounds); new_contours.push(stroker.output);
stroker = ContourStrokeToFill::new(stroker.input,
Contour::new(),
self.stroke_width * 0.5);
}
stroker.offset_backward();
stroker.output.closed = stroker.input.closed;
new_contours.push(stroker.output);
} }
let mut new_bounds = None;
new_contours.iter().for_each(|contour| contour.update_bounds(&mut new_bounds));
self.outline.contours = new_contours;
self.outline.bounds = new_bounds.unwrap_or_else(|| RectF32::default()); self.outline.bounds = new_bounds.unwrap_or_else(|| RectF32::default());
} }
} }
@ -72,7 +83,6 @@ impl ContourStrokeToFill {
} }
fn offset_backward(&mut self) { fn offset_backward(&mut self) {
// FIXME(pcwalton)
let mut segments: Vec<_> = self let mut segments: Vec<_> = self
.input .input
.iter() .iter()