From 54dc48bfa3009c74881bac9282c0d21b4d5514f2 Mon Sep 17 00:00:00 2001 From: Jovansonlee Cesar Date: Tue, 20 Sep 2022 05:23:55 +0800 Subject: feat: add a function to test bounding cells for contacts --- packages/svgbob/src/buffer/cell_buffer/contacts.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/svgbob/src/buffer/cell_buffer/contacts.rs b/packages/svgbob/src/buffer/cell_buffer/contacts.rs index 16e5bcc..7f390b2 100644 --- a/packages/svgbob/src/buffer/cell_buffer/contacts.rs +++ b/packages/svgbob/src/buffer/cell_buffer/contacts.rs @@ -29,6 +29,10 @@ impl Contacts { self.0.iter().map(|fs| &fs.fragment).collect() } + pub fn cells(&self) -> Vec { + self.0.iter().flat_map(|fs| fs.cells.clone()).collect() + } + /// Check if any fragment can be group with any of the other fragment /// We use `.rev()` on this list of fragment since it has a high change of matching at the last /// added fragment of the next fragments to be checked. @@ -71,6 +75,16 @@ impl Contacts { .collect(), ) } + + pub fn is_bounded(&self, bound1: Cell, bound2: Cell) -> bool { + self.cells() + .iter() + .all(|cell| cell.is_bounded(bound1, bound2)) + } + + pub fn hit_cell(&self, needle: Cell) -> bool { + self.cells().iter().any(|cell| *cell == needle) + } } impl fmt::Display for Contacts { -- cgit v1.2.3