mirror of https://codeberg.org/topola/topola.git
cleanup,layout: make connectivity and geometry private and clean up
This commit is contained in:
parent
1af5b96768
commit
0c6190e235
|
|
@ -4,9 +4,8 @@ use thiserror::Error;
|
|||
|
||||
use crate::{
|
||||
geometry::{
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetNet, LooseBendIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
|
||||
WraparoundableIndex,
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetNet, LooseBendWeight,
|
||||
LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, WraparoundableIndex,
|
||||
},
|
||||
guide::{Guide, Head, HeadTrait, SegbendHead},
|
||||
layout::{Infringement, Layout, LayoutException},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::{
|
||||
connectivity::{BandIndex, BandWeight, ComponentWeight, ConnectivityWeight},
|
||||
graph::{GenericIndex, GetNodeIndex},
|
||||
graph::GenericIndex,
|
||||
layout::Layout,
|
||||
math::Circle,
|
||||
primitive::{GenericPrimitive, Primitive},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use enum_dispatch::enum_dispatch;
|
|||
use petgraph::stable_graph::NodeIndex;
|
||||
|
||||
// Due to apparent limitations of enum_dispatch we're forced to import some types backwards.
|
||||
use crate::connectivity::{BandWeight, ComponentWeight, ConnectivityWeight};
|
||||
|
||||
use crate::geometry::{BendIndex, DotIndex, Index, SegIndex, WraparoundableIndex};
|
||||
|
||||
#[enum_dispatch]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use contracts::debug_invariant;
|
||||
use contracts::{debug_ensures, debug_invariant};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use geo::Point;
|
||||
use petgraph::stable_graph::StableDiGraph;
|
||||
|
|
@ -8,7 +8,7 @@ use rstar::primitives::GeomWithData;
|
|||
use rstar::{RTree, RTreeObject};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::connectivity::{BandIndex, ConnectivityLabel, ConnectivityWeight};
|
||||
use crate::connectivity::{BandIndex, BandWeight, ConnectivityGraph, ConnectivityWeight};
|
||||
use crate::geometry::{
|
||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
||||
FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetNet, Index, LooseBendIndex,
|
||||
|
|
@ -19,8 +19,8 @@ use crate::graph::{GenericIndex, GetNodeIndex};
|
|||
use crate::guide::Guide;
|
||||
use crate::math::NoTangents;
|
||||
use crate::primitive::{
|
||||
GenericPrimitive, GetConnectable, GetCore, GetEnds, GetFirstRail, GetInnerOuter, GetInterior,
|
||||
GetOtherEnd, GetWeight, GetWraparound, MakeShape,
|
||||
GenericPrimitive, GetConnectable, GetCore, GetEnds, GetFirstRail, GetInnerOuter, GetOtherEnd,
|
||||
GetWeight, GetWraparound, MakeShape,
|
||||
};
|
||||
use crate::segbend::Segbend;
|
||||
use crate::shape::{Shape, ShapeTrait};
|
||||
|
|
@ -56,8 +56,8 @@ pub struct AlreadyConnected(pub i64, pub Index);
|
|||
#[derive(Debug)]
|
||||
pub struct Layout {
|
||||
rtree: RTree<RTreeWrapper>,
|
||||
pub connectivity: StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>,
|
||||
pub geometry: GeometryGraph,
|
||||
connectivity: ConnectivityGraph,
|
||||
geometry: GeometryGraph,
|
||||
}
|
||||
|
||||
#[debug_invariant(self.geometry.node_count() == self.rtree.size())]
|
||||
|
|
@ -103,6 +103,18 @@ impl Layout {
|
|||
self.geometry.remove_node(index.node_index());
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
pub fn add_band(&mut self, from: FixedDotIndex, width: f64) -> BandIndex {
|
||||
BandIndex::new(
|
||||
self.connectivity
|
||||
.add_node(ConnectivityWeight::Band(BandWeight {
|
||||
width,
|
||||
net: self.primitive(from).net(),
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
#[debug_ensures(ret.is_ok() -> self.geometry.node_count() == old(self.geometry.node_count() + 1))]
|
||||
#[debug_ensures(ret.is_err() -> self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
|
|
@ -770,12 +782,6 @@ impl Layout {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W> {
|
||||
GenericPrimitive::new(index, self)
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
fn detect_infringement_except(&self, index: Index, except: &[Index]) -> Option<Infringement> {
|
||||
|
|
@ -829,6 +835,24 @@ impl Layout {
|
|||
}
|
||||
|
||||
impl Layout {
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
pub fn connectivity(&self) -> &ConnectivityGraph {
|
||||
&self.connectivity
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
pub fn geometry(&self) -> &GeometryGraph {
|
||||
&self.geometry
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W> {
|
||||
GenericPrimitive::new(index, self)
|
||||
}
|
||||
|
||||
fn test_envelopes(&self) -> bool {
|
||||
!self.rtree.iter().any(|wrapper| {
|
||||
let index = wrapper.data;
|
||||
|
|
|
|||
12
src/main.rs
12
src/main.rs
|
|
@ -32,7 +32,7 @@ use layout::{Infringement, Layout, LayoutException};
|
|||
use mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
||||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||
use primitive::MakeShape;
|
||||
use router::{RouterObserver, RoutingError};
|
||||
use router::RouterObserver;
|
||||
|
||||
use sdl2::event::Event;
|
||||
use sdl2::keyboard::Keycode;
|
||||
|
|
@ -68,14 +68,14 @@ enum RouterOrLayout<'a> {
|
|||
struct EmptyRouterObserver;
|
||||
|
||||
impl RouterObserver for EmptyRouterObserver {
|
||||
fn on_rework(&mut self, tracer: &Tracer, trace: &Trace) {}
|
||||
fn before_probe(&mut self, tracer: &Tracer, trace: &Trace, edge: MeshEdgeReference) {}
|
||||
fn on_rework(&mut self, _tracer: &Tracer, _trace: &Trace) {}
|
||||
fn before_probe(&mut self, _tracer: &Tracer, _trace: &Trace, _edge: MeshEdgeReference) {}
|
||||
fn on_probe(
|
||||
&mut self,
|
||||
tracer: &Tracer,
|
||||
trace: &Trace,
|
||||
_tracer: &Tracer,
|
||||
_trace: &Trace,
|
||||
_edge: MeshEdgeReference,
|
||||
result: Result<(), DrawException>,
|
||||
_result: Result<(), DrawException>,
|
||||
) {
|
||||
}
|
||||
fn on_estimate(&mut self, _tracer: &Tracer, _vertex: VertexIndex) {}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ impl Mesh {
|
|||
vertex_to_triangulation_vertex: Vec::new(),
|
||||
};
|
||||
this.vertex_to_triangulation_vertex
|
||||
.resize(layout.geometry.node_bound(), None);
|
||||
.resize(layout.geometry().node_bound(), None);
|
||||
this
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,15 +66,15 @@ pub trait GetWraparound: GetLayout + GetNodeIndex {
|
|||
pub trait GetFirstRail: GetLayout + GetNodeIndex {
|
||||
fn first_rail(&self) -> Option<LooseBendIndex> {
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_directed(self.node_index(), Incoming)
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge(*ni, self.node_index())
|
||||
.unwrap()
|
||||
)
|
||||
|
|
@ -90,15 +90,15 @@ pub trait GetFirstRail: GetLayout + GetNodeIndex {
|
|||
pub trait GetCore: GetLayout + GetNodeIndex {
|
||||
fn core(&self) -> FixedDotIndex {
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors(self.node_index())
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge(self.node_index(), *ni)
|
||||
.unwrap()
|
||||
)
|
||||
|
|
@ -115,15 +115,15 @@ pub trait GetCore: GetLayout + GetNodeIndex {
|
|||
pub trait GetInnerOuter: GetLayout + GetNodeIndex {
|
||||
fn inner(&self) -> Option<LooseBendIndex> {
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_directed(self.node_index(), Incoming)
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge(*ni, self.node_index())
|
||||
.unwrap()
|
||||
)
|
||||
|
|
@ -137,15 +137,15 @@ pub trait GetInnerOuter: GetLayout + GetNodeIndex {
|
|||
|
||||
fn outer(&self) -> Option<LooseBendIndex> {
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_directed(self.node_index(), Outgoing)
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout()
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge(self.node_index(), *ni)
|
||||
.unwrap()
|
||||
)
|
||||
|
|
@ -191,7 +191,7 @@ macro_rules! impl_loose_primitive {
|
|||
impl<'a> GetNet for $primitive_struct<'a> {
|
||||
fn net(&self) -> i64 {
|
||||
self.layout()
|
||||
.connectivity
|
||||
.connectivity()
|
||||
.node_weight(self.weight().band().node_index())
|
||||
.unwrap()
|
||||
.net()
|
||||
|
|
@ -224,22 +224,22 @@ impl<'a, W> GenericPrimitive<'a, W> {
|
|||
fn tagged_weight(&self) -> GeometryWeight {
|
||||
*self
|
||||
.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.node_weight(self.index.node_index())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn adjacents(&self) -> Vec<NodeIndex<usize>> {
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_undirected(self.index.node_index())
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge_undirected(self.index.node_index(), *ni)
|
||||
.unwrap()
|
||||
.0,
|
||||
|
|
@ -308,15 +308,15 @@ impl_loose_primitive!(LooseDot, LooseDotWeight);
|
|||
impl<'a> LooseDot<'a> {
|
||||
pub fn seg(&self) -> Option<LooseSegIndex> {
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_undirected(self.index.node_index())
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge_undirected(self.index.node_index(), *ni)
|
||||
.unwrap()
|
||||
.0,
|
||||
|
|
@ -327,7 +327,7 @@ impl<'a> LooseDot<'a> {
|
|||
})
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout.geometry.node_weight(*ni).unwrap(),
|
||||
self.layout.geometry().node_weight(*ni).unwrap(),
|
||||
GeometryWeight::LooseSeg(..)
|
||||
)
|
||||
})
|
||||
|
|
@ -337,15 +337,15 @@ impl<'a> LooseDot<'a> {
|
|||
|
||||
pub fn bend(&self) -> LooseBendIndex {
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.neighbors_undirected(self.index.node_index())
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.edge_weight(
|
||||
self.layout
|
||||
.geometry
|
||||
.geometry()
|
||||
.find_edge_undirected(self.index.node_index(), *ni)
|
||||
.unwrap()
|
||||
.0,
|
||||
|
|
@ -356,7 +356,7 @@ impl<'a> LooseDot<'a> {
|
|||
})
|
||||
.filter(|ni| {
|
||||
matches!(
|
||||
self.layout.geometry.node_weight(*ni).unwrap(),
|
||||
self.layout.geometry().node_weight(*ni).unwrap(),
|
||||
GeometryWeight::LooseBend(..)
|
||||
)
|
||||
})
|
||||
|
|
@ -423,9 +423,10 @@ impl<'a> GetWidth for LooseSeg<'a> {
|
|||
impl<'a> GetEnds<DotIndex, LooseDotIndex> for LooseSeg<'a> {
|
||||
fn ends(&self) -> (DotIndex, LooseDotIndex) {
|
||||
let v = self.adjacents();
|
||||
if let GeometryWeight::FixedDot(..) = self.layout.geometry.node_weight(v[0]).unwrap() {
|
||||
if let GeometryWeight::FixedDot(..) = self.layout.geometry().node_weight(v[0]).unwrap() {
|
||||
(FixedDotIndex::new(v[0]).into(), LooseDotIndex::new(v[1]))
|
||||
} else if let GeometryWeight::FixedDot(..) = self.layout.geometry.node_weight(v[1]).unwrap()
|
||||
} else if let GeometryWeight::FixedDot(..) =
|
||||
self.layout.geometry().node_weight(v[1]).unwrap()
|
||||
{
|
||||
(FixedDotIndex::new(v[1]).into(), LooseDotIndex::new(v[0]))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
use contracts::debug_ensures;
|
||||
|
||||
use crate::{
|
||||
connectivity::{BandIndex, BandWeight, ConnectivityWeight},
|
||||
draw::{Draw, DrawException},
|
||||
geometry::{FixedDotIndex, GetNet, LooseBendIndex},
|
||||
geometry::{FixedDotIndex, LooseBendIndex},
|
||||
guide::{BareHead, Head, SegbendHead},
|
||||
layout::{Layout, LayoutException},
|
||||
layout::Layout,
|
||||
mesh::{Mesh, VertexIndex},
|
||||
rules::Rules,
|
||||
};
|
||||
|
|
@ -32,12 +31,7 @@ impl<'a> Tracer<'a> {
|
|||
}
|
||||
|
||||
pub fn start(&mut self, from: FixedDotIndex, width: f64) -> Trace {
|
||||
let band = BandIndex::new(self.layout.connectivity.add_node(ConnectivityWeight::Band(
|
||||
BandWeight {
|
||||
width,
|
||||
net: self.layout.primitive(from).net(),
|
||||
},
|
||||
)));
|
||||
let band = self.layout.add_band(from, width);
|
||||
Trace {
|
||||
path: vec![from.into()],
|
||||
head: BareHead { dot: from, band }.into(),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl<I: Copy + PartialEq + GetNodeIndex, W: GetVertexIndex<I> + HasPosition<Scal
|
|||
index_marker: PhantomData,
|
||||
};
|
||||
this.vertex_to_handle
|
||||
.resize(layout.geometry.node_bound(), None);
|
||||
.resize(layout.geometry().node_bound(), None);
|
||||
this
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue