forked from 1b-agent/fieldcraft-upstream
mesh: octree chooses its levels and root size before building
The thinnest wall (measured to a facing wall) and narrowest patch give the cell size the grid needs; the requested size refined that deep comes first, a root shrunk so one level fewer is exact second; beyond the levels or cells allowed meshing fails at once naming the wall, levels and cells. max_depth is a cap (default 4); rebuilds stay within the planned levels; lattice positions no longer depend on the lattice depth; the report gives root size, levels, wall, patch and cells per level before and after closure. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
1 parent
effb5a7a14
commit
5a4c501524
6 files changed
+420
-80
No files matched your search
@@ -88,6 +88,35 @@ impl Tree {
|
||||
self.leaves
|
||||
}
|
||||
|
||||
/// Allow at most `max_leaves` leaves from now on (an error when there are more already).
|
||||
pub fn set_max_leaves(&mut self, max_leaves: usize) -> Result<()> {
|
||||
if self.leaves > max_leaves {
|
||||
return Err(Error::Limit(format!("the grid has {} cells; the limit is {max_leaves}", self.leaves)));
|
||||
}
|
||||
self.max_leaves = max_leaves;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Make `depth` the deepest level allowed (an error when a leaf is deeper already).
|
||||
pub fn set_depth(&mut self, depth: u8) -> Result<()> {
|
||||
if depth > MAX_LEVEL || self.nodes.keys().any(|k| k.0 > depth) {
|
||||
return Err(Error::Invalid(format!("grid depth {depth} is shallower than its leaves")));
|
||||
}
|
||||
self.depth = depth;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Leaves per level, root level first.
|
||||
pub fn level_counts(&self) -> Vec<usize> {
|
||||
let mut out = vec![0; usize::from(self.depth) + 1];
|
||||
for (k, _) in self.nodes.iter().filter(|(_, leaf)| **leaf) {
|
||||
if let Some(n) = out.get_mut(usize::from(k.0)) {
|
||||
*n += 1;
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether `key` is a leaf.
|
||||
pub fn is_leaf(&self, key: &Key) -> bool {
|
||||
self.nodes.get(key).copied().unwrap_or(false)
|
||||
|
||||
Reference in new issue
Block a user