diff options
Diffstat (limited to 'src/quad.rs')
-rw-r--r-- | src/quad.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/quad.rs b/src/quad.rs index 583e5a9..bab0491 100644 --- a/src/quad.rs +++ b/src/quad.rs @@ -1,6 +1,8 @@ +use crate::ctx::Ctx; + /// Represents the data present in a quad-tree node. /// May be the base-level repr, or a node with 4 children. -pub enum Quad<A: Default, B> { +pub enum Quad<A: Default, B: Copy> { /// Base cell in grid. /// May actually be a chunk of cells for performance. Base(A), @@ -14,21 +16,18 @@ pub enum Quad<A: Default, B> { /// Has a depth denoting the number of nodes below it. /// Nodes should only be siblings of nodes with the same depth. /// Data stored inside a quadtree node, including children, are in `data`. -pub struct Node<A: Default, B> { - depth: usize, - compr: B, - data: Quad<A, B>, +pub struct Node<A: Default, B: Copy> { + pub depth: usize, + pub compr: B, + pub data: Quad<A, B>, } -/// Represents a context with shared state. -pub struct Ctx(); - -impl<A: Default, B> Node<A, B> { +impl<A: Default, B: Copy> Node<A, B> { /// Creates a new tree from a single base node pub fn new_base(base: A, ctx: &mut Ctx) -> Self { Node { depth: 0, - compr: ctx.compress(&base), + compr: ctx.compress_base(&base), data: Quad::Base(base), } } @@ -38,11 +37,18 @@ impl<A: Default, B> Node<A, B> { Self::new_base(Default::default(), ctx) } + pub fn new_cached(compr: B, depth: usize) -> Self { + Node { + depth, + compr, + data: Quad::Cached, + } + } + /// Creates a new node double the size by centering the current node /// on a node double the size. pub fn pad_empty(self, ctx: &mut Ctx) -> Self { todo!() } - } |