router: exclude same-net nodes from navmesh (except for start and stop)

This commit is contained in:
Mikolaj Wielgus 2024-05-10 01:25:00 +02:00
parent 91f9466d74
commit 83f3245e55
3 changed files with 51 additions and 28 deletions

View File

@ -12,7 +12,11 @@ use spade::InsertionError;
use crate::{
autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex},
drawing::{dot::FixedDotIndex, graph::GetLayer, rules::RulesTrait},
drawing::{
dot::FixedDotIndex,
graph::{GetLayer, GetMaybeNet},
rules::RulesTrait,
},
layout::{connectivity::BandIndex, Layout},
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
triangulation::GetVertexIndex,
@ -35,7 +39,7 @@ impl Autoroute {
let mut layout = autorouter.layout.lock().unwrap();
let (from_dot, to_dot) = Self::terminating_dots(autorouter, &mut layout, ratline);
let navmesh = Self::next_navmesh(&layout, from_dot);
let navmesh = Self::next_navmesh(&layout, from_dot, to_dot);
Some(Self {
edge_indices: peekable_edge_indices,
navmesh,
@ -54,13 +58,14 @@ impl Autoroute {
let (navmesh, from_dot, to_dot) = {
let mut layout = autorouter.layout.lock().unwrap();
let (from_dot, to_dot) = Self::terminating_dots(autorouter, &mut layout, &ratline);
let navmesh = Self::next_navmesh(&layout, from_dot);
let navmesh = Self::next_navmesh(&layout, from_dot, to_dot);
(navmesh, from_dot, to_dot)
};
let router = Router::new_with_navmesh(
&mut autorouter.layout,
from_dot,
to_dot,
std::mem::replace(&mut self.navmesh, navmesh),
);
router.unwrap().route_band(to_dot, 100.0, observer);
@ -103,9 +108,12 @@ impl Autoroute {
(from_dot, to_dot)
}
fn next_navmesh(layout: &Layout<impl RulesTrait>, from: FixedDotIndex) -> Navmesh {
let layer = layout.drawing().primitive(from).layer();
Navmesh::new(layout, layer).unwrap()
fn next_navmesh(
layout: &Layout<impl RulesTrait>,
from: FixedDotIndex,
to: FixedDotIndex,
) -> Navmesh {
Navmesh::new(layout, from, to).unwrap()
}
pub fn navmesh(&self) -> &Navmesh {

View File

@ -7,6 +7,7 @@ use petgraph::visit::{self, NodeIndexable};
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
use spade::{HasPosition, InsertionError, Point2};
use crate::drawing::graph::{GetLayer, GetMaybeNet};
use crate::geometry::shape::ShapeTrait;
use crate::{
drawing::{
@ -83,7 +84,11 @@ pub struct Navmesh {
}
impl Navmesh {
pub fn new(layout: &Layout<impl RulesTrait>, layer: u64) -> Result<Self, InsertionError> {
pub fn new(
layout: &Layout<impl RulesTrait>,
from: FixedDotIndex,
to: FixedDotIndex,
) -> Result<Self, InsertionError> {
let mut this = Self {
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
vertex_to_triangulation_vertex: Vec::new(),
@ -91,25 +96,32 @@ impl Navmesh {
this.vertex_to_triangulation_vertex
.resize(layout.drawing().geometry().graph().node_bound(), None);
for node in layout.drawing().layer_primitive_nodes(layer) {
let center = node.primitive(layout.drawing()).shape().center();
let layer = layout.drawing().primitive(from).layer();
let net = layout.drawing().primitive(from).maybe_net().unwrap();
match node {
PrimitiveIndex::FixedDot(dot) => {
this.triangulation.add_vertex(TriangulationWeight {
vertex: dot.into(),
rails: vec![],
pos: center,
})?;
for node in layout.drawing().layer_primitive_nodes(layer) {
let primitive = node.primitive(layout.drawing());
if let Some(primitive_net) = primitive.maybe_net() {
if node == from.into() || node == to.into() || primitive_net != net {
match node {
PrimitiveIndex::FixedDot(dot) => {
this.triangulation.add_vertex(TriangulationWeight {
vertex: dot.into(),
rails: vec![],
pos: primitive.shape().center(),
})?;
}
PrimitiveIndex::FixedBend(bend) => {
this.triangulation.add_vertex(TriangulationWeight {
vertex: bend.into(),
rails: vec![],
pos: primitive.shape().center(),
})?;
}
_ => (),
}
}
PrimitiveIndex::FixedBend(bend) => {
this.triangulation.add_vertex(TriangulationWeight {
vertex: bend.into(),
rails: vec![],
pos: center,
})?;
}
_ => (),
}
}

View File

@ -6,7 +6,7 @@ use petgraph::visit::EdgeRef;
use spade::InsertionError;
use thiserror::Error;
use crate::drawing::graph::GetLayer;
use crate::drawing::graph::{GetLayer, GetMaybeNet};
use crate::geometry::primitive::PrimitiveShapeTrait;
use crate::layout::connectivity::BandIndex;
use crate::layout::Layout;
@ -61,6 +61,7 @@ pub trait RouterObserverTrait<R: RulesTrait> {
pub struct Router<'a, R: RulesTrait> {
layout: &'a mut Arc<Mutex<Layout<R>>>,
from: FixedDotIndex,
to: FixedDotIndex,
navmesh: Navmesh,
}
@ -148,23 +149,25 @@ impl<'a, R: RulesTrait> Router<'a, R> {
pub fn new(
layout: &'a mut Arc<Mutex<Layout<R>>>,
from: FixedDotIndex,
to: FixedDotIndex,
) -> Result<Self, InsertionError> {
let navmesh = {
let layout = layout.lock().unwrap();
let layer = layout.drawing().primitive(from).layer();
Navmesh::new(&layout, layer)?
Navmesh::new(&layout, from, to)?
};
Self::new_with_navmesh(layout, from, navmesh)
Self::new_with_navmesh(layout, from, to, navmesh)
}
pub fn new_with_navmesh(
layout: &'a mut Arc<Mutex<Layout<R>>>,
from: FixedDotIndex,
to: FixedDotIndex,
navmesh: Navmesh,
) -> Result<Self, InsertionError> {
Ok(Self {
layout,
from,
to,
navmesh,
})
}