diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 401e06a..1fcf119 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -21,7 +21,7 @@ use crate::{ graph::{GetLayer, GetMaybeNet}, rules::RulesTrait, }, - layout::{connectivity::BandIndex, Layout, NodeIndex}, + layout::{Layout, NodeIndex}, router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError}, triangulation::GetVertexIndex, }; diff --git a/src/bin/topola-sdl2-demo/main.rs b/src/bin/topola-sdl2-demo/main.rs index 742ff14..ef2476c 100644 --- a/src/bin/topola-sdl2-demo/main.rs +++ b/src/bin/topola-sdl2-demo/main.rs @@ -330,7 +330,7 @@ fn render_times( font_context: &CanvasFontContext, view: &mut View, mut router_or_layout: RouterOrLayout, - maybe_band: Option, + _unused: Option<()>, mut maybe_navmesh: Option, path: &[VertexIndex], ghosts: &[PrimitiveShape], @@ -381,7 +381,7 @@ fn render_times( RouterOrLayout::Router(ref mut router) => { let state = event_pump.mouse_state(); - if let Some(band) = maybe_band { + /*if let Some(band) = maybe_band { router .reroute_band( band, @@ -398,7 +398,7 @@ fn render_times( ) .ok(); maybe_navmesh = None; - } + }*/ router.layout().clone() } diff --git a/src/drawing/primitive.rs b/src/drawing/primitive.rs index c2e4259..8437533 100644 --- a/src/drawing/primitive.rs +++ b/src/drawing/primitive.rs @@ -5,8 +5,6 @@ use crate::geometry::{ primitive::{PrimitiveShape, PrimitiveShapeTrait}, GetOffset, GetWidth, }; -use crate::graph::{GenericIndex, GetNodeIndex}; -use crate::layout::connectivity::{BandIndex, ContinentIndex}; use crate::{ drawing::{ bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight}, @@ -21,6 +19,7 @@ use crate::{ Drawing, }, geometry::GenericNode, + graph::{GenericIndex, GetNodeIndex}, }; #[enum_dispatch] @@ -249,36 +248,6 @@ where pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>; impl_fixed_primitive!(FixedDot, FixedDotWeight); -impl<'a, CW: Copy, R: RulesTrait> FixedDot<'a, CW, R> { - pub fn first_loose(&self, _band: BandIndex) -> Option { - self.drawing - .geometry() - .joineds(self.index.into()) - .into_iter() - .find_map(|ni| { - let weight = self - .drawing - .geometry() - .graph() - .node_weight(ni.node_index()) - .unwrap(); - if matches!( - weight, - GenericNode::Primitive(PrimitiveWeight::LoneLooseSeg(..)) - ) { - Some(LoneLooseSegIndex::new(ni.node_index()).into()) - } else if matches!( - weight, - GenericNode::Primitive(PrimitiveWeight::SeqLooseSeg(..)) - ) { - Some(SeqLooseSegIndex::new(ni.node_index()).into()) - } else { - None - } - }) - } -} - impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedDot<'a, CW, R> { fn shape(&self) -> PrimitiveShape { self.drawing.geometry().dot_shape(self.index.into()) diff --git a/src/layout/connectivity.rs b/src/layout/connectivity.rs deleted file mode 100644 index 674528a..0000000 --- a/src/layout/connectivity.rs +++ /dev/null @@ -1,41 +0,0 @@ -use enum_dispatch::enum_dispatch; -use petgraph::stable_graph::StableDiGraph; - -use crate::{ - drawing::{dot::FixedDotIndex, graph::GetMaybeNet, primitive::Primitive, rules::RulesTrait}, - graph::GenericIndex, -}; - -pub type ConnectivityGraph = StableDiGraph; - -#[derive(Debug, Clone, Copy)] -pub enum ConnectivityWeight { - Continent(ContinentWeight), - Band(BandWeight), -} - -#[derive(Debug, Clone, Copy)] -pub struct ContinentWeight { - pub maybe_net: Option, -} - -impl GetMaybeNet for ContinentWeight { - fn maybe_net(&self) -> Option { - self.maybe_net - } -} - -pub type ContinentIndex = GenericIndex; - -#[derive(Debug, Clone, Copy)] -pub struct BandWeight { - pub from: FixedDotIndex, - pub to: Option, -} - -pub type BandIndex = GenericIndex; - -#[derive(Debug, Clone, Copy)] -pub enum ConnectivityLabel { - Band, -} diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 9dd29b0..74db707 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -21,12 +21,7 @@ use crate::{ DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait, }, graph::{GenericIndex, GetNodeIndex}, - layout::{ - connectivity::{ - BandIndex, BandWeight, ConnectivityLabel, ConnectivityWeight, ContinentIndex, - }, - zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight}, - }, + layout::zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight}, math::Circle, }; @@ -35,45 +30,17 @@ pub type NodeIndex = GenericNode>; #[derive(Debug)] pub struct Layout { drawing: Drawing, - connectivity: StableDiGraph, } impl Layout { pub fn new(drawing: Drawing) -> Self { - Self { - drawing, - connectivity: StableDiGraph::default(), - } - } - - pub fn remove_band(&mut self, band: BandIndex) { - todo!() + Self { drawing } } pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) { self.drawing.remove_segbend(segbend, face) } - pub fn start_band(&mut self, from: FixedDotIndex) -> BandIndex { - let band = self - .connectivity - .add_node(ConnectivityWeight::Band(BandWeight { from, to: None })); - self.connectivity.update_edge( - self.continent(from.into()).node_index(), - band, - ConnectivityLabel::Band, - ); - BandIndex::new(band) - } - - pub fn finish_band(&mut self, band: BandIndex, to: FixedDotIndex) { - self.connectivity.update_edge( - band.node_index(), - self.continent(to.into()).node_index(), - ConnectivityLabel::Band, - ); - } - pub fn insert_segbend( &mut self, from: DotIndex, @@ -152,24 +119,11 @@ impl Layout { self.drawing.move_dot(dot, to) } - pub fn band_from(&self, band: BandIndex) -> FixedDotIndex { - todo!() - } - - pub fn band_to(&self, band: BandIndex) -> Option { - todo!() - } - - pub fn band_length(&self, band: BandIndex) -> f64 { + pub fn band_length(&self, face: DotIndex) -> f64 { // TODO. 0.0 } - pub fn continent(&self, dot: FixedDotIndex) -> ContinentIndex { - // TODO. - ContinentIndex::new(0.into()) - } - pub fn zone_nodes(&self) -> impl Iterator> + '_ { self.drawing.rtree().iter().filter_map(|wrapper| { if let NodeIndex::Compound(zone) = wrapper.data { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index a415a3a..1e5fef1 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,4 +1,3 @@ -pub mod connectivity; mod layout; pub mod zone; diff --git a/src/router/router.rs b/src/router/router.rs index 04429bd..2cc733a 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -7,8 +7,8 @@ use spade::InsertionError; use thiserror::Error; use crate::drawing::graph::{GetLayer, GetMaybeNet}; +use crate::drawing::guide::HeadTrait; use crate::geometry::primitive::PrimitiveShapeTrait; -use crate::layout::connectivity::BandIndex; use crate::layout::Layout; use crate::{ drawing::{ @@ -123,7 +123,7 @@ impl<'a, RO: RouterObserverTrait, R: RulesTrait> AstarStrategy<&Navmesh, f64> .layout .lock() .unwrap() - .band_length(self.trace.band); + .band_length(self.trace.head.face()); let width = self.trace.width; let result = self.tracer.step(&mut self.trace, edge.target(), width); @@ -135,7 +135,7 @@ impl<'a, RO: RouterObserverTrait, R: RulesTrait> AstarStrategy<&Navmesh, f64> .layout .lock() .unwrap() - .band_length(self.trace.band); + .band_length(self.trace.head.face()); if result.is_ok() { self.tracer.undo_step(&mut self.trace); @@ -183,11 +183,10 @@ impl<'a, R: RulesTrait> Router<'a, R> { &mut self, width: f64, observer: &mut impl RouterObserverTrait, - ) -> Result { + ) -> Result<(), RoutingError> { let mut tracer = self.tracer(); let trace = tracer.start(self.navmesh.from(), width); - let band = trace.band; let (_cost, _path) = astar( &self.navmesh, @@ -200,10 +199,10 @@ impl<'a, R: RulesTrait> Router<'a, R> { source: RoutingErrorKind::AStar, })?; - Ok(band) + Ok(()) } - pub fn reroute_band( + /*pub fn reroute_band( &mut self, band: BandIndex, to: Point, @@ -218,7 +217,7 @@ impl<'a, R: RulesTrait> Router<'a, R> { } self.route_band(width, observer) - } + }*/ fn tracer(&mut self) -> Tracer { Tracer::new(self.layout.clone()) diff --git a/src/router/tracer.rs b/src/router/tracer.rs index 5acd2dd..43b3536 100644 --- a/src/router/tracer.rs +++ b/src/router/tracer.rs @@ -9,7 +9,7 @@ use crate::{ guide::{BareHead, Head, SegbendHead}, rules::RulesTrait, }, - layout::{connectivity::BandIndex, Layout}, + layout::Layout, router::{ draw::{Draw, DrawException}, navmesh::{Navmesh, VertexIndex}, @@ -20,7 +20,6 @@ use crate::{ pub struct Trace { pub path: Vec, pub head: Head, - pub band: BandIndex, pub width: f64, } @@ -35,11 +34,9 @@ impl Tracer { } pub fn start(&mut self, from: FixedDotIndex, width: f64) -> Trace { - let band = self.layout.lock().unwrap().start_band(from); Trace { path: vec![from.into()], head: BareHead { dot: from }.into(), - band, width, } } @@ -51,7 +48,7 @@ impl Tracer { width: f64, ) -> Result<(), DrawException> { Draw::new(&mut self.layout.lock().unwrap()).finish_in_dot(trace.head, into, width)?; - Ok(self.layout.lock().unwrap().finish_band(trace.band, into)) + Ok(()) } #[debug_ensures(ret.is_ok() -> trace.path.len() == path.len())]