1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::geom::Tree;
impl<'a, T> Tree<'a, T> {
#[inline]
#[must_use]
pub fn num_cells(&self) -> usize {
match *self {
Self::Root { ref children, .. } | Self::Branch { ref children, .. } => {
1 + children.iter().map(|ch| ch.num_cells()).sum::<usize>()
}
Self::Leaf { .. } | Self::Empty { .. } => 1,
}
}
#[inline]
#[must_use]
pub fn num_leaf_cells(&self) -> usize {
match *self {
Self::Root { ref children, .. } | Self::Branch { ref children, .. } => {
children.iter().map(|ch| ch.num_leaf_cells()).sum::<usize>()
}
Self::Leaf { .. } => 1,
Self::Empty { .. } => 0,
}
}
#[inline]
#[must_use]
pub fn num_tri_refs(&self) -> usize {
match *self {
Self::Root { ref children, .. } | Self::Branch { ref children, .. } => {
children.iter().map(|c| c.num_tri_refs()).sum()
}
Self::Leaf { ref tris, .. } => tris.len(),
Self::Empty { .. } => 0,
}
}
#[inline]
#[must_use]
pub fn depth(&self) -> usize {
match *self {
Self::Root { ref children, .. } => children.iter().map(|c| c.depth()).max().unwrap(),
Self::Branch { ref children, .. } => {
1 + children.iter().map(|c| c.depth()).max().unwrap()
}
Self::Leaf { .. } | Self::Empty { .. } => 1,
}
}
}