diff --git a/src/layout.rs b/src/layout.rs index b36c6b2..ccebf3f 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -420,25 +420,8 @@ impl Layout { || self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count() + 1))] fn reattach_bend(&mut self, bend: LooseBendIndex, maybe_new_inner: Option) { self.remove_from_rtree(bend.into()); - - if let Some(old_inner_edge) = self - .geometry() - .graph() - .edges_directed(bend.node_index(), Incoming) - .filter(|edge| *edge.weight() == GeometryLabel::Outer) - .next() - { - self.geometry.graph.remove_edge(old_inner_edge.id()); - } - - if let Some(new_inner) = maybe_new_inner { - self.geometry.graph.update_edge( - new_inner.node_index(), - bend.node_index(), - GeometryLabel::Outer, - ); - } - + self.geometry + .reattach_bend(bend.into(), maybe_new_inner.map(Into::into)); self.insert_into_rtree(bend.into()); } @@ -681,10 +664,10 @@ impl Layout { .add_core_bend_infringably(from.into(), to.into(), core, weight, infringables) .map_err(Into::into), WraparoundableIndex::FixedBend(around) => self - .add_outer_bend_infringably(from, to, around, weight, infringables) + .add_outer_bend_infringably(from, to, around.into(), weight, infringables) .map_err(Into::into), WraparoundableIndex::LooseBend(around) => self - .add_outer_bend_infringably(from, to, around, weight, infringables) + .add_outer_bend_infringably(from, to, around.into(), weight, infringables) .map_err(Into::into), } } @@ -715,17 +698,14 @@ impl Layout { #[debug_ensures(ret.is_err() -> self.geometry.graph().node_count() == old(self.geometry.graph().node_count()))] #[debug_ensures(ret.is_ok() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count() + 4))] #[debug_ensures(ret.is_err() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))] - fn add_outer_bend_infringably>( + fn add_outer_bend_infringably( &mut self, from: LooseDotIndex, to: LooseDotIndex, - inner: impl GetNodeIndex, - weight: W, + inner: BendIndex, + weight: LooseBendWeight, infringables: &[GeometryIndex], - ) -> Result, Infringement> - where - GenericIndex: Into, - { + ) -> Result, Infringement> { let core = *self .geometry .graph() @@ -752,6 +732,7 @@ impl Layout { let bend = self .geometry .add_bend(from.into(), to.into(), core.into(), weight); + self.geometry.reattach_bend(bend.into(), Some(inner)); self.geometry.graph.update_edge( inner.node_index(), diff --git a/src/layout/geometry.rs b/src/layout/geometry.rs index 77ce14c..2ab77ea 100644 --- a/src/layout/geometry.rs +++ b/src/layout/geometry.rs @@ -4,6 +4,7 @@ use enum_dispatch::enum_dispatch; use geo::Point; use petgraph::{ stable_graph::{NodeIndex, StableDiGraph}, + visit::EdgeRef, Direction::{Incoming, Outgoing}, }; @@ -241,6 +242,25 @@ impl< bend } + pub fn reattach_bend(&mut self, bend: BI, maybe_new_inner: Option) { + if let Some(old_inner_edge) = self + .graph + .edges_directed(bend.node_index(), Incoming) + .filter(|edge| *edge.weight() == GeometryLabel::Outer) + .next() + { + self.graph.remove_edge(old_inner_edge.id()); + } + + if let Some(new_inner) = maybe_new_inner { + self.graph.update_edge( + new_inner.node_index(), + bend.node_index(), + GeometryLabel::Outer, + ); + } + } + pub fn dot_shape(&self, dot: DI) -> Shape { let weight = self.dot_weight(dot); Shape::Dot(DotShape {