From 37fa62a4c2f5be34766014c80ad2854c93e2107b Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Thu, 18 Jan 2024 22:02:02 +0000 Subject: [PATCH] layout,connectivity: add band edges when adding terminating segs --- src/connectivity.rs | 5 +++-- src/layout.rs | 39 ++++++++++++++++++++++++++++++++------- src/primitive.rs | 10 ++++++++-- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/connectivity.rs b/src/connectivity.rs index 138032f..75cb886 100644 --- a/src/connectivity.rs +++ b/src/connectivity.rs @@ -45,6 +45,7 @@ impl GetNet for BandWeight { pub type BandIndex = GenericIndex; -#[enum_dispatch] #[derive(Debug, Clone, Copy)] -pub enum ConnectivityLabel {} +pub enum ConnectivityLabel { + Band, +} diff --git a/src/layout.rs b/src/layout.rs index d90de25..618f598 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -10,14 +10,14 @@ use thiserror::Error; use crate::band::Band; use crate::connectivity::{ - BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityGraph, ConnectivityWeight, - GetNet, + BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityGraph, ConnectivityLabel, + ConnectivityWeight, GetNet, }; use crate::geometry::{ BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex, - FixedSegWeight, GeometryGraph, GeometryIndex, GeometryLabel, GeometryWeight, LoneLooseSegIndex, - LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, - MakePrimitive, Retag, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight, + FixedSegWeight, GeometryGraph, GeometryIndex, GeometryLabel, GeometryWeight, GetComponentIndex, + LoneLooseSegIndex, LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex, + LooseDotWeight, MakePrimitive, Retag, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight, }; use crate::graph::{GenericIndex, GetNodeIndex}; use crate::guide::Guide; @@ -131,6 +131,8 @@ impl Layout { for outer in outers { self.update_this_and_outward_bows(outer).unwrap(); // Must never fail. } + + self.connectivity.remove_node(band.node_index()); } #[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count() - 4))] @@ -533,7 +535,20 @@ impl Layout { to: FixedDotIndex, weight: LoneLooseSegWeight, ) -> Result { - self.add_seg_infringably(from, to, weight, &[]) + let seg = self.add_seg_infringably(from, to, weight, &[])?; + + self.connectivity.update_edge( + self.primitive(from).component().node_index(), + weight.band.node_index(), + ConnectivityLabel::Band, + ); + self.connectivity.update_edge( + weight.band.node_index(), + self.primitive(to).component().node_index(), + ConnectivityLabel::Band, + ); + + Ok(seg) } #[debug_ensures(ret.is_ok() -> self.geometry.node_count() == old(self.geometry.node_count() + 1))] @@ -546,7 +561,17 @@ impl Layout { to: LooseDotIndex, weight: SeqLooseSegWeight, ) -> Result { - self.add_seg_infringably(from, to, weight, &[]) + let seg = self.add_seg_infringably(from, to, weight, &[])?; + + if let DotIndex::Fixed(dot) = from { + self.connectivity.update_edge( + self.primitive(dot).component().node_index(), + weight.band.node_index(), + ConnectivityLabel::Band, + ); + } + + Ok(seg) } #[debug_ensures(ret.is_ok() -> self.geometry.node_count() == old(self.geometry.node_count() + 1))] diff --git a/src/primitive.rs b/src/primitive.rs index 54a3812..b48bc58 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -4,7 +4,7 @@ use enum_dispatch::enum_dispatch; use petgraph::stable_graph::NodeIndex; use petgraph::Direction::{Incoming, Outgoing}; -use crate::connectivity::{BandIndex, GetNet}; +use crate::connectivity::{BandIndex, ComponentIndex, GetNet}; use crate::geometry::{ DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GeometryIndex, GeometryLabel, GeometryWeight, GetBandIndex, GetComponentIndex, GetOffset, GetWidth, @@ -174,11 +174,17 @@ macro_rules! impl_fixed_primitive { ($primitive_struct:ident, $weight_struct:ident) => { impl_primitive!($primitive_struct, $weight_struct); + impl<'a> GetComponentIndex for $primitive_struct<'a> { + fn component(&self) -> ComponentIndex { + self.weight().component() + } + } + impl<'a> GetNet for $primitive_struct<'a> { fn net(&self) -> i64 { self.layout() .connectivity() - .node_weight(self.weight().component().node_index()) + .node_weight(self.component().node_index()) .unwrap() .net() }