mirror of https://codeberg.org/topola/topola.git
feat(planar-incr-embed): add convenience method to remove paths from navmesh
This commit is contained in:
parent
368caa268f
commit
a6f86f488c
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::collections::BTreeMap;
|
||||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||||
|
use core::mem::take;
|
||||||
|
|
||||||
use crate::{mayrev::MaybeReversed, planarr, Edge, NavmeshBase, NavmeshIndex, Node, RelaxedPath};
|
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)
|
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<B::EtchedPath, B::GapComment>)
|
||||||
|
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
|
/// ## Panics
|
||||||
/// This function panics if the given `item` is out of bounds
|
/// 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)
|
/// (e.g. only happens when it was produced by a `Navmesh` with different edges)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue