geometry: make compound weights accessible from `CompoundManagerTrait`

This commit is contained in:
Mikolaj Wielgus 2024-04-18 13:58:04 +02:00
parent f2569c5167
commit e5bae501ad
6 changed files with 25 additions and 0 deletions

View File

@ -888,6 +888,10 @@ impl<CW: Copy, R: RulesTrait> CompoundManagerTrait<CW, GenericIndex<CW>> for Dra
.add_to_compound(primitive, compound);
}
fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
self.geometry_with_rtree.compound_weight(compound)
}
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
self.geometry_with_rtree.compounds(node)
}

View File

@ -83,6 +83,8 @@ macro_rules! impl_loose_weight {
};
}
// TODO: This enum shouldn't exist: we shouldn't be carrying the tag around like this. Instead we
// should be getting it from the graph when it's needed.
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
pub enum PrimitiveIndex {

View File

@ -4,5 +4,6 @@ pub trait CompoundManagerTrait<CW: Copy, GI: GetNodeIndex + Copy> {
fn add_compound(&mut self, weight: CW) -> GenericIndex<CW>;
fn remove_compound(&mut self, compound: GenericIndex<CW>);
fn add_to_compound<W>(&mut self, node: GenericIndex<W>, compound: GenericIndex<CW>);
fn compound_weight(&self, node: GenericIndex<CW>) -> CW;
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>>;
}

View File

@ -507,6 +507,16 @@ impl<
);
}
fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
if let GenericNode::Compound(weight) =
*self.graph.node_weight(compound.node_index()).unwrap()
{
weight
} else {
unreachable!()
}
}
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
self.graph
.neighbors(node.node_index())

View File

@ -408,6 +408,10 @@ impl<
self.geometry.add_to_compound(primitive, compound);
}
fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
self.geometry.compound_weight(compound)
}
fn compounds<W>(&self, node: GenericIndex<W>) -> impl Iterator<Item = GenericIndex<CW>> {
self.geometry.compounds(node)
}

View File

@ -236,6 +236,10 @@ impl<R: RulesTrait> CompoundManagerTrait<ZoneWeight, GenericIndex<ZoneWeight>> f
self.drawing.add_to_compound(primitive, compound);
}
fn compound_weight(&self, compound: GenericIndex<ZoneWeight>) -> ZoneWeight {
self.drawing.compound_weight(compound)
}
fn compounds<W>(
&self,
node: GenericIndex<W>,