Close subpaths explicitly.

Partially addresses #57.
This commit is contained in:
Patrick Walton 2017-12-20 13:41:01 -08:00
parent 6a81ec4893
commit f04f39afd6
2 changed files with 9 additions and 6 deletions

View File

@ -188,10 +188,7 @@ export class SVGLoader {
this.paths.push({ segments: segments, kind: 'Fill' });
this.pathBounds.push(pathBounds);
} else if (instance instanceof SVGStroke) {
this.paths.push({
kind: { Stroke: instance.width },
segments: segments,
});
this.paths.push({ segments: segments, kind: { Stroke: instance.width } });
this.pathBounds.push(pathBounds);
}
}

View File

@ -59,7 +59,7 @@ impl PathBuffer {
PathCommand::ClosePath => self.close_subpath(&mut first_subpath_endpoint_index),
PathCommand::MoveTo(position) => {
self.close_subpath(&mut first_subpath_endpoint_index);
self.end_subpath(&mut first_subpath_endpoint_index);
self.endpoints.push(Endpoint {
position: position,
control_point_index: u32::MAX,
@ -87,10 +87,16 @@ impl PathBuffer {
}
}
self.close_subpath(&mut first_subpath_endpoint_index)
self.end_subpath(&mut first_subpath_endpoint_index)
}
fn close_subpath(&mut self, first_subpath_endpoint_index: &mut u32) {
let first_endpoint = self.endpoints[*first_subpath_endpoint_index as usize];
self.endpoints.push(first_endpoint);
self.end_subpath(first_subpath_endpoint_index)
}
fn end_subpath(&mut self, first_subpath_endpoint_index: &mut u32) {
let last_subpath_endpoint_index = self.endpoints.len() as u32;
if *first_subpath_endpoint_index != last_subpath_endpoint_index {
self.subpaths.push(Subpath {