mirror of https://codeberg.org/topola/topola.git
layout,geometry: move bend reattachment to `Geometry`
This commit is contained in:
parent
67f985c980
commit
7f044f018f
|
|
@ -420,25 +420,8 @@ impl Layout {
|
||||||
|| self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count() + 1))]
|
|| self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count() + 1))]
|
||||||
fn reattach_bend(&mut self, bend: LooseBendIndex, maybe_new_inner: Option<LooseBendIndex>) {
|
fn reattach_bend(&mut self, bend: LooseBendIndex, maybe_new_inner: Option<LooseBendIndex>) {
|
||||||
self.remove_from_rtree(bend.into());
|
self.remove_from_rtree(bend.into());
|
||||||
|
self.geometry
|
||||||
if let Some(old_inner_edge) = self
|
.reattach_bend(bend.into(), maybe_new_inner.map(Into::into));
|
||||||
.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.insert_into_rtree(bend.into());
|
self.insert_into_rtree(bend.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -681,10 +664,10 @@ impl Layout {
|
||||||
.add_core_bend_infringably(from.into(), to.into(), core, weight, infringables)
|
.add_core_bend_infringably(from.into(), to.into(), core, weight, infringables)
|
||||||
.map_err(Into::into),
|
.map_err(Into::into),
|
||||||
WraparoundableIndex::FixedBend(around) => self
|
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),
|
.map_err(Into::into),
|
||||||
WraparoundableIndex::LooseBend(around) => self
|
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),
|
.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_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_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()))]
|
#[debug_ensures(ret.is_err() -> self.geometry.graph().edge_count() == old(self.geometry.graph().edge_count()))]
|
||||||
fn add_outer_bend_infringably<W: BendWeightTrait<GeometryWeight>>(
|
fn add_outer_bend_infringably(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: LooseDotIndex,
|
from: LooseDotIndex,
|
||||||
to: LooseDotIndex,
|
to: LooseDotIndex,
|
||||||
inner: impl GetNodeIndex,
|
inner: BendIndex,
|
||||||
weight: W,
|
weight: LooseBendWeight,
|
||||||
infringables: &[GeometryIndex],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<LooseBendWeight>, Infringement> {
|
||||||
where
|
|
||||||
GenericIndex<W>: Into<GeometryIndex>,
|
|
||||||
{
|
|
||||||
let core = *self
|
let core = *self
|
||||||
.geometry
|
.geometry
|
||||||
.graph()
|
.graph()
|
||||||
|
|
@ -752,6 +732,7 @@ impl Layout {
|
||||||
let bend = self
|
let bend = self
|
||||||
.geometry
|
.geometry
|
||||||
.add_bend(from.into(), to.into(), core.into(), weight);
|
.add_bend(from.into(), to.into(), core.into(), weight);
|
||||||
|
self.geometry.reattach_bend(bend.into(), Some(inner));
|
||||||
|
|
||||||
self.geometry.graph.update_edge(
|
self.geometry.graph.update_edge(
|
||||||
inner.node_index(),
|
inner.node_index(),
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use enum_dispatch::enum_dispatch;
|
||||||
use geo::Point;
|
use geo::Point;
|
||||||
use petgraph::{
|
use petgraph::{
|
||||||
stable_graph::{NodeIndex, StableDiGraph},
|
stable_graph::{NodeIndex, StableDiGraph},
|
||||||
|
visit::EdgeRef,
|
||||||
Direction::{Incoming, Outgoing},
|
Direction::{Incoming, Outgoing},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -241,6 +242,25 @@ impl<
|
||||||
bend
|
bend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reattach_bend(&mut self, bend: BI, maybe_new_inner: Option<BI>) {
|
||||||
|
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 {
|
pub fn dot_shape(&self, dot: DI) -> Shape {
|
||||||
let weight = self.dot_weight(dot);
|
let weight = self.dot_weight(dot);
|
||||||
Shape::Dot(DotShape {
|
Shape::Dot(DotShape {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue