feat(geometry): add easy way to detect if primitive is part of compound

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-01-09 20:20:57 +01:00
parent a16eba8891
commit 8280560b02
1 changed files with 8 additions and 1 deletions

View File

@ -8,7 +8,7 @@ use geo::Point;
use petgraph::{ use petgraph::{
stable_graph::{NodeIndex, StableDiGraph}, stable_graph::{NodeIndex, StableDiGraph},
visit::EdgeRef, visit::EdgeRef,
Direction::{self, Incoming}, Direction::{self, Incoming, Outgoing},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -570,6 +570,13 @@ impl<
}) })
.map(|ni| self.primitive_weight(ni).retag(ni)) .map(|ni| self.primitive_weight(ni).retag(ni))
} }
pub fn is_part_of_any_compound(&self, primitive: PI) -> Option<GenericIndex<CW>> {
self.graph
.edges_directed(primitive.petgraph_index(), Outgoing)
.find(|ei| ei.weight() == &GeometryLabel::Compound)
.map(|ei| GenericIndex::new(ei.source()))
}
} }
impl<PW, DW, SW, BW, CW: Copy, PI, DI, SI, BI> ManageCompounds<CW, GenericIndex<CW>> impl<PW, DW, SW, BW, CW: Copy, PI, DI, SI, BI> ManageCompounds<CW, GenericIndex<CW>>