From a6f86f488c73175177357cf47a0ec6ff3092cde4 Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Fri, 25 Apr 2025 13:23:47 +0200 Subject: [PATCH] feat(planar-incr-embed): add convenience method to remove paths from navmesh --- crates/planar-incr-embed/src/navmesh/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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)