mirror of https://codeberg.org/topola/topola.git
layout: store component instead of net in weight of each fixed primitive
This commit is contained in:
parent
0c6190e235
commit
8f8f47a41d
|
|
@ -1,7 +1,12 @@
|
|||
use enum_dispatch::enum_dispatch;
|
||||
use petgraph::stable_graph::StableDiGraph;
|
||||
|
||||
use crate::{geometry::GetNet, graph::GenericIndex};
|
||||
use crate::graph::GenericIndex;
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait GetNet {
|
||||
fn net(&self) -> i64;
|
||||
}
|
||||
|
||||
pub type ConnectivityGraph = StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>;
|
||||
|
||||
|
|
@ -23,6 +28,8 @@ impl GetNet for ComponentWeight {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ComponentIndex = GenericIndex<ComponentWeight>;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct BandWeight {
|
||||
pub net: i64,
|
||||
|
|
|
|||
20
src/draw.rs
20
src/draw.rs
|
|
@ -3,14 +3,16 @@ use geo::{EuclideanLength, Point};
|
|||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
connectivity::{ComponentIndex, GetNet},
|
||||
geometry::{
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetNet, LooseBendWeight,
|
||||
LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, WraparoundableIndex,
|
||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetComponentIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
|
||||
WraparoundableIndex,
|
||||
},
|
||||
guide::{Guide, Head, HeadTrait, SegbendHead},
|
||||
layout::{Infringement, Layout, LayoutException},
|
||||
math::{Circle, NoTangents},
|
||||
primitive::GetOtherEnd,
|
||||
primitive::{GetOtherEnd, GetWeight},
|
||||
rules::{Conditions, Rules},
|
||||
};
|
||||
|
||||
|
|
@ -60,8 +62,18 @@ impl<'a> Draw<'a> {
|
|||
|
||||
match head.face() {
|
||||
DotIndex::Fixed(dot) => {
|
||||
// TODO: This code is temporary (component is wrong). Fix this by splitting loose
|
||||
// segs into direct and indirect ones, the former ending with fixed dots on both
|
||||
// sides and the latter not.
|
||||
self.layout
|
||||
.add_fixed_seg(into.into(), dot, FixedSegWeight { net, width })
|
||||
.add_fixed_seg(
|
||||
into.into(),
|
||||
dot,
|
||||
FixedSegWeight {
|
||||
component: self.layout.primitive(into).weight().component(),
|
||||
width,
|
||||
},
|
||||
)
|
||||
.map_err(|err| DrawException::CannotFinishIn(into, err.into()))?;
|
||||
}
|
||||
DotIndex::Loose(dot) => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch;
|
|||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
||||
|
||||
use crate::{
|
||||
connectivity::{BandIndex, BandWeight, ComponentWeight, ConnectivityWeight},
|
||||
connectivity::{BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityWeight},
|
||||
graph::GenericIndex,
|
||||
layout::Layout,
|
||||
math::Circle,
|
||||
|
|
@ -15,12 +15,12 @@ pub trait Retag {
|
|||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
pub trait GetNet {
|
||||
fn net(&self) -> i64;
|
||||
pub trait GetComponentIndex {
|
||||
fn component(&self) -> ComponentIndex;
|
||||
}
|
||||
|
||||
pub trait GetNetMut {
|
||||
fn net_mut(&mut self) -> &mut i64;
|
||||
pub trait GetComponentIndexMut {
|
||||
fn component_mut(&mut self) -> &mut ComponentIndex;
|
||||
}
|
||||
|
||||
pub trait GetBandIndex {
|
||||
|
|
@ -58,15 +58,15 @@ macro_rules! impl_fixed_weight {
|
|||
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
|
||||
impl_weight!($weight_struct, $weight_variant, $index_struct);
|
||||
|
||||
impl GetNet for $weight_struct {
|
||||
fn net(&self) -> i64 {
|
||||
self.net
|
||||
impl GetComponentIndex for $weight_struct {
|
||||
fn component(&self) -> ComponentIndex {
|
||||
self.component
|
||||
}
|
||||
}
|
||||
|
||||
impl GetNetMut for $weight_struct {
|
||||
fn net_mut(&mut self) -> &mut i64 {
|
||||
&mut self.net
|
||||
impl GetComponentIndexMut for $weight_struct {
|
||||
fn component_mut(&mut self) -> &mut ComponentIndex {
|
||||
&mut self.component
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -186,7 +186,7 @@ pub trait DotWeight: GetWidth + Into<GeometryWeight> + Copy {}
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FixedDotWeight {
|
||||
pub net: i64,
|
||||
pub component: ComponentIndex,
|
||||
pub circle: Circle,
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ pub trait SegWeight: Into<GeometryWeight> + Copy {}
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FixedSegWeight {
|
||||
pub net: i64,
|
||||
pub component: ComponentIndex,
|
||||
pub width: f64,
|
||||
}
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ pub trait BendWeight: Into<GeometryWeight> + Copy {}
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FixedBendWeight {
|
||||
pub net: i64,
|
||||
pub component: ComponentIndex,
|
||||
pub width: f64,
|
||||
pub cw: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,15 @@ use rstar::primitives::GeomWithData;
|
|||
use rstar::{RTree, RTreeObject};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::connectivity::{BandIndex, BandWeight, ConnectivityGraph, ConnectivityWeight};
|
||||
use crate::connectivity::{
|
||||
BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityGraph, ConnectivityWeight,
|
||||
GetNet,
|
||||
};
|
||||
use crate::geometry::{
|
||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
||||
FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetNet, Index, LooseBendIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
|
||||
Retag, SegWeight, WraparoundableIndex,
|
||||
FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetComponentIndex, Index,
|
||||
LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight,
|
||||
MakePrimitive, Retag, SegWeight, WraparoundableIndex,
|
||||
};
|
||||
use crate::graph::{GenericIndex, GetNodeIndex};
|
||||
use crate::guide::Guide;
|
||||
|
|
@ -103,6 +106,17 @@ impl Layout {
|
|||
self.geometry.remove_node(index.node_index());
|
||||
}
|
||||
|
||||
// TODO: This method shouldn't be public.
|
||||
#[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_component(&mut self, net: i64) -> ComponentIndex {
|
||||
ComponentIndex::new(
|
||||
self.connectivity
|
||||
.add_node(ConnectivityWeight::Component(ComponentWeight { net })),
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: This method shouldn't be public.
|
||||
#[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 {
|
||||
|
|
|
|||
54
src/main.rs
54
src/main.rs
|
|
@ -225,10 +225,18 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let _i = 0;
|
||||
let mut router = Router::new();
|
||||
|
||||
let component1_1 = router.layout.add_component(1);
|
||||
let component1_2 = router.layout.add_component(1);
|
||||
let component2 = router.layout.add_component(2);
|
||||
let component3_1 = router.layout.add_component(3);
|
||||
let component3_2 = router.layout.add_component(3);
|
||||
let component4_1 = router.layout.add_component(4);
|
||||
let component4_2 = router.layout.add_component(4);
|
||||
|
||||
let dot_start = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 1,
|
||||
component: component1_1,
|
||||
circle: Circle {
|
||||
pos: (100.5, 400.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -239,7 +247,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot_start2 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 3,
|
||||
component: component3_1,
|
||||
circle: Circle {
|
||||
pos: (100.5, 500.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -250,7 +258,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot_start3 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 4,
|
||||
component: component4_1,
|
||||
circle: Circle {
|
||||
pos: (160.5, 430.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -261,7 +269,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot_end = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 1,
|
||||
component: component1_2,
|
||||
circle: Circle {
|
||||
pos: (470.5, 350.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -272,7 +280,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot_end2 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 3,
|
||||
component: component3_2,
|
||||
circle: Circle {
|
||||
pos: (500.5, 150.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -283,7 +291,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot_end3 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 4,
|
||||
component: component4_2,
|
||||
circle: Circle {
|
||||
pos: (350.5, 200.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -294,7 +302,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot1_1 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (200.5, 200.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -305,7 +313,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot2_1 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (200.5, 500.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -317,7 +325,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot1_1,
|
||||
dot2_1,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -325,7 +333,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot2_2 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (600.5, 500.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -337,7 +345,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot2_1,
|
||||
dot2_2,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -345,7 +353,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot3 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (400.5, 200.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -356,7 +364,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot4 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (400.5, 400.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -368,7 +376,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot3,
|
||||
dot4,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -376,7 +384,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot5 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (530.5, 400.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -388,7 +396,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot4,
|
||||
dot5,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -396,7 +404,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot1_2 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (600.5, 200.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -408,7 +416,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot3,
|
||||
dot1_2,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -417,7 +425,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot1_2,
|
||||
dot2_2,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -425,7 +433,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let dot6 = router
|
||||
.layout
|
||||
.add_fixed_dot(FixedDotWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
circle: Circle {
|
||||
pos: (530.5, 300.5).into(),
|
||||
r: 8.0,
|
||||
|
|
@ -437,7 +445,7 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
dot5,
|
||||
dot6,
|
||||
FixedSegWeight {
|
||||
net: 2,
|
||||
component: component2,
|
||||
width: 16.0,
|
||||
},
|
||||
);
|
||||
|
|
@ -520,8 +528,8 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let _ = router.enroute(
|
||||
dot_start2,
|
||||
dot_end2,
|
||||
//&mut EmptyRouterObserver,
|
||||
&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
|
||||
&mut EmptyRouterObserver,
|
||||
//&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
|
||||
)?;
|
||||
|
||||
render_times(
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ use enum_dispatch::enum_dispatch;
|
|||
use petgraph::stable_graph::NodeIndex;
|
||||
use petgraph::Direction::{Incoming, Outgoing};
|
||||
|
||||
use crate::connectivity::GetNet;
|
||||
use crate::geometry::{
|
||||
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GeometryLabel,
|
||||
GeometryWeight, GetBandIndex, GetNet, GetOffset, GetWidth, Index, LooseBendIndex,
|
||||
GeometryWeight, GetBandIndex, GetComponentIndex, GetOffset, GetWidth, Index, LooseBendIndex,
|
||||
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
|
||||
Retag,
|
||||
};
|
||||
|
|
@ -178,7 +179,11 @@ macro_rules! impl_fixed_primitive {
|
|||
|
||||
impl<'a> GetNet for $primitive_struct<'a> {
|
||||
fn net(&self) -> i64 {
|
||||
self.weight().net()
|
||||
self.layout()
|
||||
.connectivity()
|
||||
.node_weight(self.weight().component().node_index())
|
||||
.unwrap()
|
||||
.net()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue