mirror of https://codeberg.org/topola/topola.git
refactor(geometry): move edit application to new trait
This commit is contained in:
parent
a838310ecb
commit
847654b5c3
|
|
@ -7,6 +7,21 @@ use crate::{
|
||||||
|
|
||||||
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth};
|
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth};
|
||||||
|
|
||||||
|
pub trait ApplyGeometryEdit<
|
||||||
|
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||||
|
DW: AccessDotWeight<PW> + GetLayer,
|
||||||
|
SW: AccessSegWeight<PW> + GetLayer,
|
||||||
|
BW: AccessBendWeight<PW> + GetLayer,
|
||||||
|
CW: Copy,
|
||||||
|
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Hash + Copy,
|
||||||
|
DI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
SI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
BI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
>
|
||||||
|
{
|
||||||
|
fn apply(&mut self, edit: GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GeometryEdit<
|
pub struct GeometryEdit<
|
||||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
compound::ManageCompounds,
|
compound::ManageCompounds,
|
||||||
edit::GeometryEdit,
|
edit::{ApplyGeometryEdit, GeometryEdit},
|
||||||
with_rtree::{BboxedIndex, GeometryWithRtree},
|
with_rtree::{BboxedIndex, GeometryWithRtree},
|
||||||
AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel,
|
AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel,
|
||||||
GetWidth,
|
GetWidth,
|
||||||
|
|
@ -333,7 +333,48 @@ impl<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_edit(&mut self, edit: GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>) {
|
pub fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
|
||||||
|
self.geometry_with_rtree.compound_weight(compound)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compounds<'a, W: 'a>(
|
||||||
|
&'a self,
|
||||||
|
node: GenericIndex<W>,
|
||||||
|
) -> impl Iterator<Item = GenericIndex<CW>> + 'a {
|
||||||
|
self.geometry_with_rtree.compounds(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
||||||
|
self.geometry_with_rtree.geometry()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rtree(&self) -> &RTree<BboxedIndex<GenericNode<PI, GenericIndex<CW>>>> {
|
||||||
|
self.geometry_with_rtree.rtree()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn layer_count(&self) -> usize {
|
||||||
|
*self.geometry_with_rtree.layer_count()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn graph(&self) -> &StableDiGraph<GenericNode<PW, CW>, GeometryLabel, usize> {
|
||||||
|
self.geometry_with_rtree.graph()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||||
|
DW: AccessDotWeight<PW> + GetLayer,
|
||||||
|
SW: AccessSegWeight<PW> + GetLayer,
|
||||||
|
BW: AccessBendWeight<PW> + GetLayer,
|
||||||
|
CW: Copy,
|
||||||
|
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Hash + Copy,
|
||||||
|
DI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
SI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
BI: GetPetgraphIndex + Into<PI> + Eq + Hash + Copy,
|
||||||
|
> ApplyGeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
|
for RecordingGeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
|
{
|
||||||
|
fn apply(&mut self, edit: GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>) {
|
||||||
for (compound, ..) in &edit.compounds {
|
for (compound, ..) in &edit.compounds {
|
||||||
self.geometry_with_rtree.remove_compound(*compound);
|
self.geometry_with_rtree.remove_compound(*compound);
|
||||||
}
|
}
|
||||||
|
|
@ -384,31 +425,4 @@ impl<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compound_weight(&self, compound: GenericIndex<CW>) -> CW {
|
|
||||||
self.geometry_with_rtree.compound_weight(compound)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compounds<'a, W: 'a>(
|
|
||||||
&'a self,
|
|
||||||
node: GenericIndex<W>,
|
|
||||||
) -> impl Iterator<Item = GenericIndex<CW>> + 'a {
|
|
||||||
self.geometry_with_rtree.compounds(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
|
||||||
self.geometry_with_rtree.geometry()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rtree(&self) -> &RTree<BboxedIndex<GenericNode<PI, GenericIndex<CW>>>> {
|
|
||||||
self.geometry_with_rtree.rtree()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn layer_count(&self) -> usize {
|
|
||||||
*self.geometry_with_rtree.layer_count()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn graph(&self) -> &StableDiGraph<GenericNode<PW, CW>, GeometryLabel, usize> {
|
|
||||||
self.geometry_with_rtree.graph()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue