Add `Path2D::add_path()`

This commit is contained in:
Patrick Walton 2020-03-27 12:33:06 -07:00
parent 15718d297c
commit c258616bad
2 changed files with 29 additions and 0 deletions

View File

@ -569,6 +569,18 @@ impl Path2D {
}
}
// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d-addpath
pub fn add_path(&mut self, mut path: Path2D, transform: &Transform2F) {
self.flush_current_contour();
path.flush_current_contour();
path.outline.transform(transform);
let last_contour = path.outline.pop_contour();
for contour in path.outline.into_contours() {
self.outline.push_contour(contour);
}
self.current_contour = last_contour.unwrap_or_else(Contour::new);
}
pub fn into_outline(mut self) -> Outline {
self.flush_current_contour();
self.outline

View File

@ -120,6 +120,11 @@ impl Outline {
&self.contours
}
#[inline]
pub fn into_contours(self) -> Vec<Contour> {
self.contours
}
/// Removes all contours from this outline.
#[inline]
pub fn clear(&mut self) {
@ -141,6 +146,18 @@ impl Outline {
self.contours.push(contour);
}
pub fn pop_contour(&mut self) -> Option<Contour> {
let last_contour = self.contours.pop();
let mut new_bounds = None;
for contour in &mut self.contours {
contour.update_bounds(&mut new_bounds);
}
self.bounds = new_bounds.unwrap_or_else(|| RectF::default());
last_contour
}
pub fn transform(&mut self, transform: &Transform2F) {
if transform.is_identity() {
return;