From 850941715e843c30b2d56d8a11b0a96f3def5f73 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 7 Feb 2024 00:00:57 +0000 Subject: [PATCH] router,layout,draw: remove hardcoded widths --- src/draw.rs | 8 ++++--- src/layout/band.rs | 8 ++++++- src/layout/layout.rs | 52 ++++++++++++++++++++++++++++++++++---------- src/main.rs | 4 ++-- src/router.rs | 25 +++++++++++++++++---- 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/draw.rs b/src/draw.rs index a3d13a6..c9ccad5 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -6,12 +6,14 @@ use crate::{ layout::{ bend::{BendIndex, LooseBendWeight}, dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, + geometry::GetWidth, graph::{GetBandIndex, MakePrimitive}, guide::{Guide, Head, HeadTrait, SegbendHead}, primitive::GetOtherJoint, + rules::RulesTrait, seg::{LoneLooseSegWeight, SeqLooseSegWeight}, + Infringement, Layout, LayoutException, }, - layout::{rules::RulesTrait, Infringement, Layout, LayoutException}, math::{Circle, NoTangents}, wraparoundable::WraparoundableIndex, }; @@ -65,7 +67,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { into.into(), LoneLooseSegWeight { band: head.band(), - width: 3.0, + width: self.layout.band(head.band()).width(), }, ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; @@ -77,7 +79,7 @@ impl<'a, R: RulesTrait> Draw<'a, R> { dot, SeqLooseSegWeight { band: head.band(), - width: 3.0, + width: self.layout.band(head.band()).width(), }, ) .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; diff --git a/src/layout/band.rs b/src/layout/band.rs index fcabed9..fa97ebf 100644 --- a/src/layout/band.rs +++ b/src/layout/band.rs @@ -11,7 +11,7 @@ use crate::{ }, }; -use super::rules::RulesTrait; +use super::{geometry::GetWidth, rules::RulesTrait}; pub struct Band<'a, R: RulesTrait> { pub index: BandIndex, @@ -92,3 +92,9 @@ impl<'a, R: RulesTrait> GetNet for Band<'a, R> { self.weight().net } } + +impl<'a, R: RulesTrait> GetWidth for Band<'a, R> { + fn width(&self) -> f64 { + self.weight().width + } +} diff --git a/src/layout/layout.rs b/src/layout/layout.rs index c823804..3743a2c 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -20,7 +20,7 @@ use crate::graph::{GenericIndex, GetNodeIndex}; use crate::layout::bend::BendIndex; use crate::layout::dot::DotWeight; use crate::layout::geometry::{ - BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetPos, SegWeightTrait, + BendWeightTrait, DotWeightTrait, Geometry, GeometryLabel, GetPos, GetWidth, SegWeightTrait, }; use crate::layout::guide::Guide; use crate::layout::rules::{Conditions, GetConditions}; @@ -413,39 +413,67 @@ impl Layout { while let Some(rail) = maybe_rail { let rail_primitive = self.primitive(rail); - let ends = rail_primitive.joints(); + let joints = rail_primitive.joints(); let guide = Guide::new(self); - let from_head = guide.rear_head(ends.1); - let to_head = guide.rear_head(ends.0); + let from_head = guide.rear_head(joints.1); + let to_head = guide.rear_head(joints.0); if let Some(inner) = rail_primitive.inner() { let from = guide - .head_around_bend_segment(&from_head.into(), inner.into(), true, 6.0)? + .head_around_bend_segment( + &from_head.into(), + inner.into(), + true, + self.primitive(rail).width(), + )? .end_point(); let to = guide - .head_around_bend_segment(&to_head.into(), inner.into(), false, 6.0)? + .head_around_bend_segment( + &to_head.into(), + inner.into(), + false, + self.primitive(rail).width(), + )? .end_point(); self.move_dot_infringably( - ends.0.into(), + joints.0.into(), from, &self.inner_bow_and_outer_bows(rail), )?; - self.move_dot_infringably(ends.1.into(), to, &self.inner_bow_and_outer_bows(rail))?; + self.move_dot_infringably( + joints.1.into(), + to, + &self.inner_bow_and_outer_bows(rail), + )?; } else { let core = rail_primitive.core(); let from = guide - .head_around_dot_segment(&from_head.into(), core.into(), true, 6.0)? + .head_around_dot_segment( + &from_head.into(), + core.into(), + true, + self.primitive(rail).width(), + )? .end_point(); let to = guide - .head_around_dot_segment(&to_head.into(), core.into(), false, 6.0)? + .head_around_dot_segment( + &to_head.into(), + core.into(), + false, + self.primitive(rail).width(), + )? .end_point(); self.move_dot_infringably( - ends.0.into(), + joints.0.into(), from, &self.inner_bow_and_outer_bows(rail), )?; - self.move_dot_infringably(ends.1.into(), to, &self.inner_bow_and_outer_bows(rail))?; + self.move_dot_infringably( + joints.1.into(), + to, + &self.inner_bow_and_outer_bows(rail), + )?; } maybe_rail = self.primitive(rail).outer(); diff --git a/src/main.rs b/src/main.rs index 4da12e0..3928c3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -523,8 +523,8 @@ fn main() -> Result<(), anyhow::Error> { dot_start, dot_end, 3.0, - //&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( diff --git a/src/router.rs b/src/router.rs index 20d0919..5b02cc6 100644 --- a/src/router.rs +++ b/src/router.rs @@ -6,6 +6,7 @@ use thiserror::Error; use crate::astar::{astar, AstarStrategy, PathTracker}; use crate::draw::DrawException; +use crate::layout::geometry::GetWidth; use crate::layout::guide::HeadTrait; use crate::layout::rules::RulesTrait; use crate::layout::Layout; @@ -84,13 +85,24 @@ impl<'a, RO: RouterObserverTrait, R: RulesTrait> AstarStrategy<&Mesh, f64> { fn is_goal(&mut self, vertex: VertexIndex, tracker: &PathTracker<&Mesh>) -> bool { let new_path = tracker.reconstruct_path_to(vertex); + let band = self.trace.head.band(); self.tracer - .rework_path(&mut self.trace, &new_path, 5.0) + .rework_path( + &mut self.trace, + &new_path, + self.tracer.layout.band(band).width(), + ) .unwrap(); self.observer.on_rework(&self.tracer, &self.trace); - self.tracer.finish(&mut self.trace, self.to, 5.0).is_ok() + self.tracer + .finish( + &mut self.trace, + self.to, + self.tracer.layout.band(band).width(), + ) + .is_ok() } fn edge_cost(&mut self, edge: MeshEdgeReference) -> Option { @@ -99,9 +111,14 @@ impl<'a, RO: RouterObserverTrait, R: RulesTrait> AstarStrategy<&Mesh, f64> return None; } - let before_probe_length = self.tracer.layout.band(self.trace.head.band()).length(); + let band = self.trace.head.band(); + let before_probe_length = self.tracer.layout.band(band).length(); - let result = self.tracer.step(&mut self.trace, edge.target(), 5.0); + let result = self.tracer.step( + &mut self.trace, + edge.target(), + self.tracer.layout.band(band).width(), + ); self.observer .on_probe(&self.tracer, &self.trace, edge, result);