mirror of https://codeberg.org/topola/topola.git
router: store origin and target in navmesh
This commit is contained in:
parent
c1db44c25f
commit
9ac4c780b5
|
|
@ -55,20 +55,17 @@ impl Autoroute {
|
|||
autorouter: &mut Autorouter<R>,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
) -> Option<()> {
|
||||
let (navmesh, from, to) = {
|
||||
let navmesh = {
|
||||
let (from, to) = self.from_to(autorouter);
|
||||
let layout = autorouter.layout.lock().unwrap();
|
||||
let navmesh = Navmesh::new(&layout, from, to).ok()?;
|
||||
(navmesh, from, to)
|
||||
Navmesh::new(&layout, from, to).ok()?
|
||||
};
|
||||
|
||||
let router = Router::new_with_navmesh(
|
||||
let router = Router::new_from_navmesh(
|
||||
&mut autorouter.layout,
|
||||
from,
|
||||
to,
|
||||
std::mem::replace(&mut self.navmesh, navmesh),
|
||||
);
|
||||
router.unwrap().route_band(to, 100.0, observer);
|
||||
router.unwrap().route_band(100.0, observer);
|
||||
|
||||
if let Some(cur_edge) = self.edge_indices.next() {
|
||||
self.cur_edge = cur_edge;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,8 @@ impl HasPosition for TriangulationWeight {
|
|||
pub struct Navmesh {
|
||||
triangulation: Triangulation<TriangulationVertexIndex, TriangulationWeight>,
|
||||
vertex_to_triangulation_vertex: Vec<Option<TriangulationVertexIndex>>,
|
||||
from: FixedDotIndex,
|
||||
to: FixedDotIndex,
|
||||
}
|
||||
|
||||
impl Navmesh {
|
||||
|
|
@ -92,6 +94,8 @@ impl Navmesh {
|
|||
let mut this = Self {
|
||||
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
|
||||
vertex_to_triangulation_vertex: Vec::new(),
|
||||
from,
|
||||
to,
|
||||
};
|
||||
this.vertex_to_triangulation_vertex
|
||||
.resize(layout.drawing().geometry().graph().node_bound(), None);
|
||||
|
|
@ -152,6 +156,14 @@ impl Navmesh {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from(&self) -> FixedDotIndex {
|
||||
self.from
|
||||
}
|
||||
|
||||
pub fn to(&self) -> FixedDotIndex {
|
||||
self.to
|
||||
}
|
||||
}
|
||||
|
||||
impl visit::GraphBase for Navmesh {
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@ pub trait RouterObserverTrait<R: RulesTrait> {
|
|||
|
||||
pub struct Router<'a, R: RulesTrait> {
|
||||
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
||||
from: FixedDotIndex,
|
||||
to: FixedDotIndex,
|
||||
navmesh: Navmesh,
|
||||
}
|
||||
|
||||
|
|
@ -155,42 +153,34 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
|||
let layout = layout.lock().unwrap();
|
||||
Navmesh::new(&layout, from, to)?
|
||||
};
|
||||
Self::new_with_navmesh(layout, from, to, navmesh)
|
||||
Self::new_from_navmesh(layout, navmesh)
|
||||
}
|
||||
|
||||
pub fn new_with_navmesh(
|
||||
pub fn new_from_navmesh(
|
||||
layout: &'a mut Arc<Mutex<Layout<R>>>,
|
||||
from: FixedDotIndex,
|
||||
to: FixedDotIndex,
|
||||
navmesh: Navmesh,
|
||||
) -> Result<Self, InsertionError> {
|
||||
Ok(Self {
|
||||
layout,
|
||||
from,
|
||||
to,
|
||||
navmesh,
|
||||
})
|
||||
Ok(Self { layout, navmesh })
|
||||
}
|
||||
|
||||
pub fn route_band(
|
||||
&mut self,
|
||||
to: FixedDotIndex,
|
||||
width: f64,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
) -> Result<BandIndex, RoutingError> {
|
||||
let mut tracer = self.tracer();
|
||||
|
||||
let trace = tracer.start(self.from, width);
|
||||
let trace = tracer.start(self.navmesh.from(), width);
|
||||
let band = trace.band;
|
||||
|
||||
let (_cost, _path) = astar(
|
||||
&self.navmesh,
|
||||
self.from.into(),
|
||||
&mut RouterAstarStrategy::new(tracer, trace, to.into(), observer),
|
||||
self.navmesh.from().into(),
|
||||
&mut RouterAstarStrategy::new(tracer, trace, self.navmesh.to(), observer),
|
||||
)
|
||||
.ok_or(RoutingError {
|
||||
from: self.from,
|
||||
to,
|
||||
from: self.navmesh.from(),
|
||||
to: self.navmesh.to(),
|
||||
source: RoutingErrorKind::AStar,
|
||||
})?;
|
||||
|
||||
|
|
@ -204,17 +194,14 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
|||
width: f64,
|
||||
observer: &mut impl RouterObserverTrait<R>,
|
||||
) -> Result<BandIndex, RoutingError> {
|
||||
let (from_dot, to_dot) = {
|
||||
{
|
||||
let mut layout = self.layout.lock().unwrap();
|
||||
|
||||
let from_dot = layout.band_from(band);
|
||||
let to_dot = layout.band_to(band).unwrap();
|
||||
layout.remove_band(band);
|
||||
layout.move_dot(to_dot.into(), to).unwrap(); // TODO: Remove `.unwrap()`.
|
||||
(from_dot, to_dot)
|
||||
};
|
||||
layout.move_dot(self.navmesh.to().into(), to).unwrap(); // TODO: Remove `.unwrap()`.
|
||||
}
|
||||
|
||||
self.route_band(to_dot, width, observer)
|
||||
self.route_band(width, observer)
|
||||
}
|
||||
|
||||
fn tracer(&mut self) -> Tracer<R> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue