diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2022-09-20 05:23:55 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2022-09-20 05:23:55 +0800 |
commit | 54dc48bfa3009c74881bac9282c0d21b4d5514f2 (patch) | |
tree | 95c0959e4d67f46c2df0f41764b91d5dcaeabb5a | |
parent | 01f8a15083d79b5d5ddb4fc7225cb5afb2dbf968 (diff) |
feat: add a function to test bounding cells for contacts
-rw-r--r-- | packages/svgbob/src/buffer/cell_buffer/contacts.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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<Cell> { + 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 { |