Skip to content

Commit

Permalink
started to work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davids91 committed Apr 26, 2023
1 parent 5a0eba4 commit db9cda9
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,52 +147,54 @@ where

/// Inserts a new leaf `Node` at the given position, if possible.
pub(crate) fn insert(&mut self, position: Vector3<u32>, min_dimension: u32, data: T) -> Result<(), Error> {
if !self.contains(position) {
return Err(Error::InvalidPosition {
x: position.x,
y: position.y,
z: position.z,
});
}

if self.dimension() == min_dimension {
self.ty = NodeType::Leaf(data);
} else {
let ChildInfo {
dimension,
dimension_3d,
octant,
} = self.child_info(position).unwrap();
if self.contains(position) {
if self.dimension() == min_dimension {
self.ty = NodeType::Leaf(data);
} else {
let ChildInfo {
dimension,
dimension_3d,
octant,
} = self.child_info(position).unwrap();

let bounds = self.child_bounds(dimension_3d, octant);
let bounds = self.child_bounds(dimension_3d, octant);

let mut node = if self.children[octant as usize].as_ref().is_some() {
self.children[octant as usize].take().unwrap()
} else {
Node::<T>::new(bounds)
};
let mut node = if self.children[octant as usize].as_ref().is_some() {
self.children[octant as usize].take().unwrap()
} else {
Node::<T>::new(bounds)
};

if self.is_leaf() && dimension == min_dimension {
for i in 0..OCTREE_CHILDREN {
if i != octant as usize {
let new_octant = Octant::try_from(i).unwrap();
let new_node = Node::<T>::new_with_ty(
self.child_bounds(dimension_3d, new_octant),
std::mem::replace(&mut self.ty, NodeType::Leaf(T::default())),
);
self.children[new_octant as usize] = Box::new(Some(new_node));
if self.is_leaf() && dimension == min_dimension {
for i in 0..OCTREE_CHILDREN {
if i != octant as usize {
let new_octant = Octant::try_from(i).unwrap();
let new_node = Node::<T>::new_with_ty(
self.child_bounds(dimension_3d, new_octant),
NodeType::Leaf(T::default()),
);
self.children[new_octant as usize] = Box::new(Some(new_node));
}
}
// move current data to appropriate child ???
let data = std::mem::replace(&mut self.ty, NodeType::Internal);
}
}

node.insert(position, min_dimension, data).unwrap();
node.insert(position, min_dimension, data).unwrap();

self.children[octant as usize] = Box::new(Some(node));
self.ty = NodeType::Internal;
}
self.children[octant as usize] = Box::new(Some(node));
self.ty = NodeType::Internal;
}

self.simplify();
Ok(())
self.simplify();
Ok(())
} else {
Err(Error::InvalidPosition {
x: position.x,
y: position.y,
z: position.z,
})
}
}

/// Removes the `Node` at the given position, if possible.
Expand Down

0 comments on commit db9cda9

Please sign in to comment.