// SPDX-FileCopyrightText: 2024 Topola contributors // // SPDX-License-Identifier: MIT use std::{collections::BTreeMap, marker::PhantomData}; use crate::graph::{GenericIndex, GetPetgraphIndex}; use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer, GetWidth, Retag}; pub trait ApplyGeometryEdit< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, SI: GetPetgraphIndex + Into + Eq + Ord + Copy, BI: GetPetgraphIndex + Into + Eq + Ord + Copy, > { fn apply(&mut self, edit: &GeometryEdit); } #[derive(Debug, Clone)] pub struct GeometryEdit { pub(super) dots: BTreeMap, Option)>, pub(super) segs: BTreeMap, Option<((DI, DI), SW)>)>, pub(super) bends: BTreeMap, Option<((DI, DI, DI), BW)>)>, pub(super) compounds: BTreeMap, (Option<(Vec, CW)>, Option<(Vec, CW)>)>, primitive_weight_marker: PhantomData, } impl< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, DW: AccessDotWeight + Into + GetLayer, SW: AccessSegWeight + Into + GetLayer, BW: AccessBendWeight + Into + GetLayer, CW: Copy, PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Ord + Copy, DI: GetPetgraphIndex + Into + Eq + Ord + Copy, SI: GetPetgraphIndex + Into + Eq + Ord + Copy, BI: GetPetgraphIndex + Into + Eq + Ord + Copy, > GeometryEdit { pub fn new() -> Self { Self { dots: BTreeMap::new(), segs: BTreeMap::new(), bends: BTreeMap::new(), compounds: BTreeMap::new(), primitive_weight_marker: PhantomData, } } pub fn reverse(&self) -> Self { Self { dots: self .dots .clone() .into_iter() .map(|(k, v)| (k, (v.1, v.0))) .collect(), segs: self .segs .clone() .into_iter() .map(|(k, v)| (k, (v.1, v.0))) .collect(), bends: self .bends .clone() .into_iter() .map(|(k, v)| (k, (v.1, v.0))) .collect(), compounds: self .compounds .clone() .into_iter() .map(|(k, v)| (k, (v.1, v.0))) .collect(), primitive_weight_marker: PhantomData, } } }