use enum_dispatch::enum_dispatch; use crate::{ geometry::{GetWidth, SegWeightTrait}, graph::{GenericIndex, GetNodeIndex}, layout::{ connectivity::{BandIndex, ContinentIndex}, graph::{ GeometryIndex, GeometryWeight, GetBandIndex, GetContinentIndex, GetContinentIndexMut, MakePrimitive, Retag, }, primitive::{GenericPrimitive, Primitive}, rules::RulesTrait, Layout, }, }; use petgraph::stable_graph::NodeIndex; #[enum_dispatch(GetNodeIndex, MakePrimitive)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum SegIndex { Fixed(FixedSegIndex), LoneLoose(LoneLooseSegIndex), SeqLoose(SeqLooseSegIndex), } impl From for GeometryIndex { fn from(seg: SegIndex) -> Self { match seg { SegIndex::Fixed(seg) => GeometryIndex::FixedSeg(seg), SegIndex::LoneLoose(seg) => GeometryIndex::LoneLooseSeg(seg), SegIndex::SeqLoose(seg) => GeometryIndex::SeqLooseSeg(seg), } } } impl TryFrom for SegIndex { type Error = (); // TODO. fn try_from(index: GeometryIndex) -> Result { match index { GeometryIndex::FixedSeg(index) => Ok(SegIndex::Fixed(index)), GeometryIndex::LoneLooseSeg(index) => Ok(SegIndex::LoneLoose(index)), GeometryIndex::SeqLooseSeg(index) => Ok(SegIndex::SeqLoose(index)), _ => Err(()), } } } #[enum_dispatch(GetWidth)] #[derive(Debug, Clone, Copy, PartialEq)] pub enum SegWeight { Fixed(FixedSegWeight), LoneLoose(LoneLooseSegWeight), SeqLoose(SeqLooseSegWeight), } impl From for GeometryWeight { fn from(seg: SegWeight) -> Self { match seg { SegWeight::Fixed(weight) => GeometryWeight::FixedSeg(weight), SegWeight::LoneLoose(weight) => GeometryWeight::LoneLooseSeg(weight), SegWeight::SeqLoose(weight) => GeometryWeight::SeqLooseSeg(weight), } } } impl TryFrom for SegWeight { type Error = (); // TODO. fn try_from(weight: GeometryWeight) -> Result { match weight { GeometryWeight::FixedSeg(weight) => Ok(SegWeight::Fixed(weight)), GeometryWeight::LoneLooseSeg(weight) => Ok(SegWeight::LoneLoose(weight)), GeometryWeight::SeqLooseSeg(weight) => Ok(SegWeight::SeqLoose(weight)), _ => Err(()), } } } impl SegWeightTrait for SegWeight {} #[derive(Debug, Clone, Copy, PartialEq)] pub struct FixedSegWeight { pub continent: ContinentIndex, pub width: f64, } impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); impl SegWeightTrait for FixedSegWeight {} impl GetWidth for FixedSegWeight { fn width(&self) -> f64 { self.width } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct LoneLooseSegWeight { pub band: BandIndex, pub width: f64, } impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); impl SegWeightTrait for LoneLooseSegWeight {} impl GetWidth for LoneLooseSegWeight { fn width(&self) -> f64 { self.width } } #[derive(Debug, Clone, Copy, PartialEq)] pub struct SeqLooseSegWeight { pub band: BandIndex, pub width: f64, } impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); impl SegWeightTrait for SeqLooseSegWeight {} impl GetWidth for SeqLooseSegWeight { fn width(&self) -> f64 { self.width } }