conspire/geometry/ntree/pair/
mod.rs1use crate::geometry::ntree::{Orthotree, node::split::Split};
2use std::ops::Add;
3
4#[derive(Clone, Copy)]
5pub enum Pairing {
6 Generalized,
7 Regular,
8 None,
9}
10
11impl<const D: usize, const L: usize, const M: usize, const N: usize, T, U, V>
12 Orthotree<D, L, M, N, T, U, V>
13where
14 T: Add<Output = T> + Copy + Split + Into<usize>,
15 U: Copy + From<usize> + Into<usize>,
16 V: Copy,
17{
18 pub fn pair(&mut self, pairing: Pairing) -> Result<bool, &'static str> {
19 match pairing {
20 Pairing::Generalized => unimplemented!(),
21 Pairing::Regular => {
22 let mut index = 0;
23 let mut paired = true;
24 while index < self.len() {
25 if let Some(nodes) = self[index.into()].orthants() {
26 let mut any_leaf = false;
27 let mut any_tree = false;
28 let mut leaves = Vec::with_capacity(N);
29 for &node in nodes.iter() {
30 if self[node].is_leaf() {
31 any_leaf = true;
32 leaves.push(node);
33 } else if self[node].is_tree() {
34 any_tree = true;
35 }
36 }
37 if any_tree && any_leaf {
38 for node in leaves {
39 paired = false;
40 self.subdivide(node)?;
41 }
42 }
43 }
44 index += 1;
45 }
46 Ok(paired)
47 }
48 Pairing::None => Ok(true),
49 }
50 }
51}