feat(geometry/geometry): Add convenience GetPetgraphIndex impls

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-05-15 15:37:02 +02:00
parent f9b1cc2cbf
commit 2394fa6256
2 changed files with 17 additions and 1 deletions

View File

@ -73,6 +73,15 @@ pub enum GenericNode<P, C> {
Compound(C),
}
impl<P: GetPetgraphIndex, C: GetPetgraphIndex> GetPetgraphIndex for GenericNode<P, C> {
fn petgraph_index(&self) -> NodeIndex<usize> {
match self {
Self::Primitive(x) => x.petgraph_index(),
Self::Compound(x) => x.petgraph_index(),
}
}
}
pub trait AccessDotWeight: GetSetPos + GetWidth + Copy {}
impl<T: GetSetPos + GetWidth + Copy> AccessDotWeight for T {}

View File

@ -18,6 +18,13 @@ pub trait GetPetgraphIndex {
fn petgraph_index(&self) -> NodeIndex<usize>;
}
impl GetPetgraphIndex for NodeIndex<usize> {
#[inline(always)]
fn petgraph_index(&self) -> NodeIndex<usize> {
*self
}
}
// unfortunately, as we don't want any restrictions on `W`,
// we have to implement many traits ourselves, instead of using derive macros.
#[derive(Deserialize, Serialize)]
@ -40,7 +47,7 @@ impl<W> GenericIndex<W> {
}
impl<W> core::clone::Clone for GenericIndex<W> {
#[inline]
#[inline(always)]
fn clone(&self) -> Self {
*self
}