Skip to main content

conspire/geometry/ntree/balance/
mod.rs

1pub(super) mod octree;
2pub(super) mod quadtree;
3
4use crate::geometry::ntree::pair::Pairing;
5
6/// Constraint on the level difference between neighboring nodes.
7#[derive(Clone, Copy, Debug)]
8pub enum Balancing {
9    /// Level difference of at most `n` between nodes sharing a face, an edge
10    /// or a vertex.
11    Strong(usize),
12    /// Level difference of at most `n` between nodes sharing a face only.
13    Weak(usize),
14    /// No constraint on the level difference.
15    None,
16}
17
18pub trait Balance {
19    fn equilibrate(&mut self, balancing: Balancing, pairing: Pairing) -> Result<(), &'static str> {
20        let mut balanced = false;
21        let mut paired = false;
22        while !balanced || !paired {
23            balanced = self.balance(balancing);
24            paired = self.pair_up(pairing)?;
25        }
26        Ok(())
27    }
28    fn balance(&mut self, balancing: Balancing) -> bool;
29    fn pair_up(&mut self, pairing: Pairing) -> Result<bool, &'static str>;
30}