diff --git a/crates/planar-incr-embed/src/navmesh/mod.rs b/crates/planar-incr-embed/src/navmesh/mod.rs index f4ef021..afbd6f2 100644 --- a/crates/planar-incr-embed/src/navmesh/mod.rs +++ b/crates/planar-incr-embed/src/navmesh/mod.rs @@ -7,6 +7,7 @@ use alloc::collections::BTreeMap; use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use core::mem::take; use crate::{mayrev::MaybeReversed, planarr, Edge, NavmeshBase, NavmeshIndex, Node, RelaxedPath}; @@ -258,6 +259,22 @@ impl<'a, B: NavmeshBase + 'a> NavmeshRefMut<'a, B> { resolve_edge_data(self.edges, from_node, to_node) } + /// Removes a path (weak or normal) with the given label from the navmesh + pub fn remove_path(&mut self, label: &RelaxedPath) + where + B::GapComment: PartialEq, + { + let mut updated_indices = Vec::new(); + for i in &mut *self.edge_paths { + updated_indices.clear(); + updated_indices.extend(i[..].iter().filter(|&j| j != label).cloned()); + + if updated_indices.len() != i.len() { + *i = take(&mut updated_indices).into_boxed_slice().into(); + } + } + } + /// ## Panics /// This function panics if the given `item` is out of bounds /// (e.g. only happens when it was produced by a `Navmesh` with different edges)