From 3486d5556520d2867c270aa27982e48f84177773 Mon Sep 17 00:00:00 2001 From: Sebastian K Date: Tue, 19 May 2020 18:26:17 +0300 Subject: [PATCH] Add a function to merge two outlines --- content/src/outline.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/content/src/outline.rs b/content/src/outline.rs index f5bbd58c..8da6c6bd 100644 --- a/content/src/outline.rs +++ b/content/src/outline.rs @@ -218,6 +218,26 @@ impl Outline { pub fn close_all_contours(&mut self) { self.contours.iter_mut().for_each(|contour| contour.close()); } + + #[inline] + pub fn is_empty(&self) -> bool { + self.contours.iter().all(Contour::is_empty) + } + + /// Appends the contours in another outline to this one. + pub fn push_outline(&mut self, other: Outline) { + if other.is_empty() { + return; + } + + if self.is_empty() { + self.bounds = other.bounds; + } else { + self.bounds = self.bounds.union_rect(other.bounds); + } + + self.contours.extend(other.contours); + } } impl Debug for Outline {