layout: store component instead of net in weight of each fixed primitive

This commit is contained in:
Mikolaj Wielgus 2024-01-14 14:08:17 +00:00
parent 0c6190e235
commit 8f8f47a41d
6 changed files with 94 additions and 48 deletions

View File

@ -1,7 +1,12 @@
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::StableDiGraph; 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>; pub type ConnectivityGraph = StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>;
@ -23,6 +28,8 @@ impl GetNet for ComponentWeight {
} }
} }
pub type ComponentIndex = GenericIndex<ComponentWeight>;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct BandWeight { pub struct BandWeight {
pub net: i64, pub net: i64,

View File

@ -3,14 +3,16 @@ use geo::{EuclideanLength, Point};
use thiserror::Error; use thiserror::Error;
use crate::{ use crate::{
connectivity::{ComponentIndex, GetNet},
geometry::{ geometry::{
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetNet, LooseBendWeight, BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetComponentIndex,
LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive, WraparoundableIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegWeight, MakePrimitive,
WraparoundableIndex,
}, },
guide::{Guide, Head, HeadTrait, SegbendHead}, guide::{Guide, Head, HeadTrait, SegbendHead},
layout::{Infringement, Layout, LayoutException}, layout::{Infringement, Layout, LayoutException},
math::{Circle, NoTangents}, math::{Circle, NoTangents},
primitive::GetOtherEnd, primitive::{GetOtherEnd, GetWeight},
rules::{Conditions, Rules}, rules::{Conditions, Rules},
}; };
@ -60,8 +62,18 @@ impl<'a> Draw<'a> {
match head.face() { match head.face() {
DotIndex::Fixed(dot) => { 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 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()))?; .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?;
} }
DotIndex::Loose(dot) => { DotIndex::Loose(dot) => {

View File

@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::{NodeIndex, StableDiGraph}; use petgraph::stable_graph::{NodeIndex, StableDiGraph};
use crate::{ use crate::{
connectivity::{BandIndex, BandWeight, ComponentWeight, ConnectivityWeight}, connectivity::{BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityWeight},
graph::GenericIndex, graph::GenericIndex,
layout::Layout, layout::Layout,
math::Circle, math::Circle,
@ -15,12 +15,12 @@ pub trait Retag {
} }
#[enum_dispatch] #[enum_dispatch]
pub trait GetNet { pub trait GetComponentIndex {
fn net(&self) -> i64; fn component(&self) -> ComponentIndex;
} }
pub trait GetNetMut { pub trait GetComponentIndexMut {
fn net_mut(&mut self) -> &mut i64; fn component_mut(&mut self) -> &mut ComponentIndex;
} }
pub trait GetBandIndex { pub trait GetBandIndex {
@ -58,15 +58,15 @@ macro_rules! impl_fixed_weight {
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => { ($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
impl_weight!($weight_struct, $weight_variant, $index_struct); impl_weight!($weight_struct, $weight_variant, $index_struct);
impl GetNet for $weight_struct { impl GetComponentIndex for $weight_struct {
fn net(&self) -> i64 { fn component(&self) -> ComponentIndex {
self.net self.component
} }
} }
impl GetNetMut for $weight_struct { impl GetComponentIndexMut for $weight_struct {
fn net_mut(&mut self) -> &mut i64 { fn component_mut(&mut self) -> &mut ComponentIndex {
&mut self.net &mut self.component
} }
} }
}; };
@ -186,7 +186,7 @@ pub trait DotWeight: GetWidth + Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedDotWeight { pub struct FixedDotWeight {
pub net: i64, pub component: ComponentIndex,
pub circle: Circle, pub circle: Circle,
} }
@ -218,7 +218,7 @@ pub trait SegWeight: Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedSegWeight { pub struct FixedSegWeight {
pub net: i64, pub component: ComponentIndex,
pub width: f64, pub width: f64,
} }
@ -243,7 +243,7 @@ pub trait BendWeight: Into<GeometryWeight> + Copy {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedBendWeight { pub struct FixedBendWeight {
pub net: i64, pub component: ComponentIndex,
pub width: f64, pub width: f64,
pub cw: bool, pub cw: bool,
} }

View File

@ -8,12 +8,15 @@ use rstar::primitives::GeomWithData;
use rstar::{RTree, RTreeObject}; use rstar::{RTree, RTreeObject};
use thiserror::Error; use thiserror::Error;
use crate::connectivity::{BandIndex, BandWeight, ConnectivityGraph, ConnectivityWeight}; use crate::connectivity::{
BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityGraph, ConnectivityWeight,
GetNet,
};
use crate::geometry::{ use crate::geometry::{
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex, BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetNet, Index, LooseBendIndex, FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetComponentIndex, Index,
LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight,
Retag, SegWeight, WraparoundableIndex, MakePrimitive, Retag, SegWeight, WraparoundableIndex,
}; };
use crate::graph::{GenericIndex, GetNodeIndex}; use crate::graph::{GenericIndex, GetNodeIndex};
use crate::guide::Guide; use crate::guide::Guide;
@ -103,6 +106,17 @@ impl Layout {
self.geometry.remove_node(index.node_index()); 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.node_count() == old(self.geometry.node_count()))]
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))] #[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
pub fn add_band(&mut self, from: FixedDotIndex, width: f64) -> BandIndex { pub fn add_band(&mut self, from: FixedDotIndex, width: f64) -> BandIndex {

View File

@ -225,10 +225,18 @@ fn main() -> Result<(), anyhow::Error> {
let _i = 0; let _i = 0;
let mut router = Router::new(); 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 let dot_start = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 1, component: component1_1,
circle: Circle { circle: Circle {
pos: (100.5, 400.5).into(), pos: (100.5, 400.5).into(),
r: 8.0, r: 8.0,
@ -239,7 +247,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot_start2 = router let dot_start2 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 3, component: component3_1,
circle: Circle { circle: Circle {
pos: (100.5, 500.5).into(), pos: (100.5, 500.5).into(),
r: 8.0, r: 8.0,
@ -250,7 +258,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot_start3 = router let dot_start3 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 4, component: component4_1,
circle: Circle { circle: Circle {
pos: (160.5, 430.5).into(), pos: (160.5, 430.5).into(),
r: 8.0, r: 8.0,
@ -261,7 +269,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot_end = router let dot_end = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 1, component: component1_2,
circle: Circle { circle: Circle {
pos: (470.5, 350.5).into(), pos: (470.5, 350.5).into(),
r: 8.0, r: 8.0,
@ -272,7 +280,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot_end2 = router let dot_end2 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 3, component: component3_2,
circle: Circle { circle: Circle {
pos: (500.5, 150.5).into(), pos: (500.5, 150.5).into(),
r: 8.0, r: 8.0,
@ -283,7 +291,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot_end3 = router let dot_end3 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 4, component: component4_2,
circle: Circle { circle: Circle {
pos: (350.5, 200.5).into(), pos: (350.5, 200.5).into(),
r: 8.0, r: 8.0,
@ -294,7 +302,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot1_1 = router let dot1_1 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (200.5, 200.5).into(), pos: (200.5, 200.5).into(),
r: 8.0, r: 8.0,
@ -305,7 +313,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot2_1 = router let dot2_1 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (200.5, 500.5).into(), pos: (200.5, 500.5).into(),
r: 8.0, r: 8.0,
@ -317,7 +325,7 @@ fn main() -> Result<(), anyhow::Error> {
dot1_1, dot1_1,
dot2_1, dot2_1,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -325,7 +333,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot2_2 = router let dot2_2 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (600.5, 500.5).into(), pos: (600.5, 500.5).into(),
r: 8.0, r: 8.0,
@ -337,7 +345,7 @@ fn main() -> Result<(), anyhow::Error> {
dot2_1, dot2_1,
dot2_2, dot2_2,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -345,7 +353,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot3 = router let dot3 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (400.5, 200.5).into(), pos: (400.5, 200.5).into(),
r: 8.0, r: 8.0,
@ -356,7 +364,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot4 = router let dot4 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (400.5, 400.5).into(), pos: (400.5, 400.5).into(),
r: 8.0, r: 8.0,
@ -368,7 +376,7 @@ fn main() -> Result<(), anyhow::Error> {
dot3, dot3,
dot4, dot4,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -376,7 +384,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot5 = router let dot5 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (530.5, 400.5).into(), pos: (530.5, 400.5).into(),
r: 8.0, r: 8.0,
@ -388,7 +396,7 @@ fn main() -> Result<(), anyhow::Error> {
dot4, dot4,
dot5, dot5,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -396,7 +404,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot1_2 = router let dot1_2 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (600.5, 200.5).into(), pos: (600.5, 200.5).into(),
r: 8.0, r: 8.0,
@ -408,7 +416,7 @@ fn main() -> Result<(), anyhow::Error> {
dot3, dot3,
dot1_2, dot1_2,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -417,7 +425,7 @@ fn main() -> Result<(), anyhow::Error> {
dot1_2, dot1_2,
dot2_2, dot2_2,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -425,7 +433,7 @@ fn main() -> Result<(), anyhow::Error> {
let dot6 = router let dot6 = router
.layout .layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
net: 2, component: component2,
circle: Circle { circle: Circle {
pos: (530.5, 300.5).into(), pos: (530.5, 300.5).into(),
r: 8.0, r: 8.0,
@ -437,7 +445,7 @@ fn main() -> Result<(), anyhow::Error> {
dot5, dot5,
dot6, dot6,
FixedSegWeight { FixedSegWeight {
net: 2, component: component2,
width: 16.0, width: 16.0,
}, },
); );
@ -520,8 +528,8 @@ fn main() -> Result<(), anyhow::Error> {
let _ = router.enroute( let _ = router.enroute(
dot_start2, dot_start2,
dot_end2, dot_end2,
//&mut EmptyRouterObserver, &mut EmptyRouterObserver,
&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context), //&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
)?; )?;
render_times( render_times(

View File

@ -4,9 +4,10 @@ use enum_dispatch::enum_dispatch;
use petgraph::stable_graph::NodeIndex; use petgraph::stable_graph::NodeIndex;
use petgraph::Direction::{Incoming, Outgoing}; use petgraph::Direction::{Incoming, Outgoing};
use crate::connectivity::GetNet;
use crate::geometry::{ use crate::geometry::{
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GeometryLabel, 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, LooseBendWeight, LooseDotIndex, LooseDotWeight, LooseSegIndex, LooseSegWeight, MakePrimitive,
Retag, Retag,
}; };
@ -178,7 +179,11 @@ macro_rules! impl_fixed_primitive {
impl<'a> GetNet for $primitive_struct<'a> { impl<'a> GetNet for $primitive_struct<'a> {
fn net(&self) -> i64 { fn net(&self) -> i64 {
self.weight().net() self.layout()
.connectivity()
.node_weight(self.weight().component().node_index())
.unwrap()
.net()
} }
} }
}; };