mirror of https://codeberg.org/topola/topola.git
router: exclude same-net nodes from navmesh (except for start and stop)
This commit is contained in:
parent
91f9466d74
commit
83f3245e55
|
|
@ -12,7 +12,11 @@ use spade::InsertionError;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex},
|
autorouter::ratsnest::{Ratsnest, RatsnestVertexIndex},
|
||||||
drawing::{dot::FixedDotIndex, graph::GetLayer, rules::RulesTrait},
|
drawing::{
|
||||||
|
dot::FixedDotIndex,
|
||||||
|
graph::{GetLayer, GetMaybeNet},
|
||||||
|
rules::RulesTrait,
|
||||||
|
},
|
||||||
layout::{connectivity::BandIndex, Layout},
|
layout::{connectivity::BandIndex, Layout},
|
||||||
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
|
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
|
||||||
triangulation::GetVertexIndex,
|
triangulation::GetVertexIndex,
|
||||||
|
|
@ -35,7 +39,7 @@ impl Autoroute {
|
||||||
|
|
||||||
let mut layout = autorouter.layout.lock().unwrap();
|
let mut layout = autorouter.layout.lock().unwrap();
|
||||||
let (from_dot, to_dot) = Self::terminating_dots(autorouter, &mut layout, ratline);
|
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 {
|
Some(Self {
|
||||||
edge_indices: peekable_edge_indices,
|
edge_indices: peekable_edge_indices,
|
||||||
navmesh,
|
navmesh,
|
||||||
|
|
@ -54,13 +58,14 @@ impl Autoroute {
|
||||||
let (navmesh, from_dot, to_dot) = {
|
let (navmesh, from_dot, to_dot) = {
|
||||||
let mut layout = autorouter.layout.lock().unwrap();
|
let mut layout = autorouter.layout.lock().unwrap();
|
||||||
let (from_dot, to_dot) = Self::terminating_dots(autorouter, &mut layout, &ratline);
|
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)
|
(navmesh, from_dot, to_dot)
|
||||||
};
|
};
|
||||||
|
|
||||||
let router = Router::new_with_navmesh(
|
let router = Router::new_with_navmesh(
|
||||||
&mut autorouter.layout,
|
&mut autorouter.layout,
|
||||||
from_dot,
|
from_dot,
|
||||||
|
to_dot,
|
||||||
std::mem::replace(&mut self.navmesh, navmesh),
|
std::mem::replace(&mut self.navmesh, navmesh),
|
||||||
);
|
);
|
||||||
router.unwrap().route_band(to_dot, 100.0, observer);
|
router.unwrap().route_band(to_dot, 100.0, observer);
|
||||||
|
|
@ -103,9 +108,12 @@ impl Autoroute {
|
||||||
(from_dot, to_dot)
|
(from_dot, to_dot)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_navmesh(layout: &Layout<impl RulesTrait>, from: FixedDotIndex) -> Navmesh {
|
fn next_navmesh(
|
||||||
let layer = layout.drawing().primitive(from).layer();
|
layout: &Layout<impl RulesTrait>,
|
||||||
Navmesh::new(layout, layer).unwrap()
|
from: FixedDotIndex,
|
||||||
|
to: FixedDotIndex,
|
||||||
|
) -> Navmesh {
|
||||||
|
Navmesh::new(layout, from, to).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn navmesh(&self) -> &Navmesh {
|
pub fn navmesh(&self) -> &Navmesh {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use petgraph::visit::{self, NodeIndexable};
|
||||||
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
||||||
use spade::{HasPosition, InsertionError, Point2};
|
use spade::{HasPosition, InsertionError, Point2};
|
||||||
|
|
||||||
|
use crate::drawing::graph::{GetLayer, GetMaybeNet};
|
||||||
use crate::geometry::shape::ShapeTrait;
|
use crate::geometry::shape::ShapeTrait;
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
|
|
@ -83,7 +84,11 @@ pub struct Navmesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
let mut this = Self {
|
||||||
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
|
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
|
||||||
vertex_to_triangulation_vertex: Vec::new(),
|
vertex_to_triangulation_vertex: Vec::new(),
|
||||||
|
|
@ -91,27 +96,34 @@ impl Navmesh {
|
||||||
this.vertex_to_triangulation_vertex
|
this.vertex_to_triangulation_vertex
|
||||||
.resize(layout.drawing().geometry().graph().node_bound(), None);
|
.resize(layout.drawing().geometry().graph().node_bound(), None);
|
||||||
|
|
||||||
for node in layout.drawing().layer_primitive_nodes(layer) {
|
let layer = layout.drawing().primitive(from).layer();
|
||||||
let center = node.primitive(layout.drawing()).shape().center();
|
let net = layout.drawing().primitive(from).maybe_net().unwrap();
|
||||||
|
|
||||||
|
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 {
|
match node {
|
||||||
PrimitiveIndex::FixedDot(dot) => {
|
PrimitiveIndex::FixedDot(dot) => {
|
||||||
this.triangulation.add_vertex(TriangulationWeight {
|
this.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: dot.into(),
|
vertex: dot.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: primitive.shape().center(),
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
PrimitiveIndex::FixedBend(bend) => {
|
PrimitiveIndex::FixedBend(bend) => {
|
||||||
this.triangulation.add_vertex(TriangulationWeight {
|
this.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: bend.into(),
|
vertex: bend.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: primitive.shape().center(),
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for node in layout.drawing().layer_primitive_nodes(layer) {
|
for node in layout.drawing().layer_primitive_nodes(layer) {
|
||||||
// Add rails as vertices. This is how the navmesh differs from the triangulation.
|
// Add rails as vertices. This is how the navmesh differs from the triangulation.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use petgraph::visit::EdgeRef;
|
||||||
use spade::InsertionError;
|
use spade::InsertionError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::drawing::graph::GetLayer;
|
use crate::drawing::graph::{GetLayer, GetMaybeNet};
|
||||||
use crate::geometry::primitive::PrimitiveShapeTrait;
|
use crate::geometry::primitive::PrimitiveShapeTrait;
|
||||||
use crate::layout::connectivity::BandIndex;
|
use crate::layout::connectivity::BandIndex;
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
|
|
@ -61,6 +61,7 @@ pub trait RouterObserverTrait<R: RulesTrait> {
|
||||||
pub struct Router<'a, R: RulesTrait> {
|
pub struct Router<'a, R: RulesTrait> {
|
||||||
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
||||||
from: FixedDotIndex,
|
from: FixedDotIndex,
|
||||||
|
to: FixedDotIndex,
|
||||||
navmesh: Navmesh,
|
navmesh: Navmesh,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,23 +149,25 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
||||||
from: FixedDotIndex,
|
from: FixedDotIndex,
|
||||||
|
to: FixedDotIndex,
|
||||||
) -> Result<Self, InsertionError> {
|
) -> Result<Self, InsertionError> {
|
||||||
let navmesh = {
|
let navmesh = {
|
||||||
let layout = layout.lock().unwrap();
|
let layout = layout.lock().unwrap();
|
||||||
let layer = layout.drawing().primitive(from).layer();
|
Navmesh::new(&layout, from, to)?
|
||||||
Navmesh::new(&layout, layer)?
|
|
||||||
};
|
};
|
||||||
Self::new_with_navmesh(layout, from, navmesh)
|
Self::new_with_navmesh(layout, from, to, navmesh)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_navmesh(
|
pub fn new_with_navmesh(
|
||||||
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
||||||
from: FixedDotIndex,
|
from: FixedDotIndex,
|
||||||
|
to: FixedDotIndex,
|
||||||
navmesh: Navmesh,
|
navmesh: Navmesh,
|
||||||
) -> Result<Self, InsertionError> {
|
) -> Result<Self, InsertionError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
layout,
|
layout,
|
||||||
from,
|
from,
|
||||||
|
to,
|
||||||
navmesh,
|
navmesh,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue