mirror of https://codeberg.org/topola/topola.git
refactor(router/navmesh): Rename "navvertex" to "navnode"
Easier to pronounce.
This commit is contained in:
parent
8d0681c07d
commit
24d119ad04
|
|
@ -24,7 +24,7 @@ use topola::{
|
|||
graph::MakeRef,
|
||||
layout::{poly::MakePolygon, via::ViaWeight},
|
||||
math::{Circle, RotationSense},
|
||||
router::navmesh::NavvertexIndex,
|
||||
router::navmesh::NavnodeIndex,
|
||||
};
|
||||
|
||||
use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace};
|
||||
|
|
@ -333,16 +333,16 @@ impl Viewport {
|
|||
}
|
||||
|
||||
for index in navmesh.graph().node_indices() {
|
||||
let navvertex = NavvertexIndex(index);
|
||||
let navnode = NavnodeIndex(index);
|
||||
let mut pos = PrimitiveIndex::from(
|
||||
navmesh.node_weight(navvertex).unwrap().node,
|
||||
navmesh.node_weight(navnode).unwrap().node,
|
||||
)
|
||||
.primitive(board.layout().drawing())
|
||||
.shape()
|
||||
.center();
|
||||
|
||||
pos += match navmesh
|
||||
.node_weight(navvertex)
|
||||
.node_weight(navnode)
|
||||
.unwrap()
|
||||
.maybe_sense
|
||||
{
|
||||
|
|
@ -356,14 +356,14 @@ impl Viewport {
|
|||
//TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)"
|
||||
let score_text = &astar
|
||||
.scores
|
||||
.get(&navvertex)
|
||||
.get(&navnode)
|
||||
.map_or_else(String::new, |s| format!("g={:.2}", s));
|
||||
let estimate_score_text = &astar
|
||||
.estimate_scores
|
||||
.get(&navvertex)
|
||||
.get(&navnode)
|
||||
.map_or_else(String::new, |s| format!("(f={:.2})", s));
|
||||
let debug_text =
|
||||
activity.navvertex_debug_text(navvertex).unwrap_or("");
|
||||
activity.navnode_debug_text(navnode).unwrap_or("");
|
||||
|
||||
painter.paint_text(
|
||||
pos,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use crate::{
|
|||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
navmesh::{Navmesh, NavnodeIndex},
|
||||
},
|
||||
stepper::Step,
|
||||
};
|
||||
|
|
@ -76,11 +76,11 @@ pub trait GetObstacles {
|
|||
/// Trait for getting text strings with debug information attached to navmesh
|
||||
/// edges and vertices.
|
||||
pub trait GetNavmeshDebugTexts {
|
||||
fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> {
|
||||
fn navnode_debug_text(&self, _navnode: NavnodeIndex) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
|
||||
fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> {
|
||||
fn navedge_debug_text(&self, _navedge: (NavnodeIndex, NavnodeIndex)) -> Option<&str> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use crate::{
|
|||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
navmesh::{Navmesh, NavnodeIndex},
|
||||
},
|
||||
stepper::{Abort, Step},
|
||||
};
|
||||
|
|
@ -150,11 +150,11 @@ impl GetObstacles for ActivityStepperWithStatus {
|
|||
}
|
||||
|
||||
impl GetNavmeshDebugTexts for ActivityStepperWithStatus {
|
||||
fn navvertex_debug_text(&self, navvertex: NavvertexIndex) -> Option<&str> {
|
||||
self.activity.navvertex_debug_text(navvertex)
|
||||
fn navnode_debug_text(&self, navnode: NavnodeIndex) -> Option<&str> {
|
||||
self.activity.navnode_debug_text(navnode)
|
||||
}
|
||||
|
||||
fn navedge_debug_text(&self, navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> {
|
||||
fn navedge_debug_text(&self, navedge: (NavnodeIndex, NavnodeIndex)) -> Option<&str> {
|
||||
self.activity.navedge_debug_text(navedge)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use crate::{
|
|||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
navmesh::{Navmesh, NavnodeIndex},
|
||||
},
|
||||
stepper::{Abort, Step},
|
||||
};
|
||||
|
|
@ -78,11 +78,11 @@ impl GetObstacles for InteractionStepper {
|
|||
}
|
||||
|
||||
impl GetNavmeshDebugTexts for InteractionStepper {
|
||||
fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> {
|
||||
fn navnode_debug_text(&self, _navnode: NavnodeIndex) -> Option<&str> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> {
|
||||
fn navedge_debug_text(&self, _navedge: (NavnodeIndex, NavnodeIndex)) -> Option<&str> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use crate::{
|
|||
use super::{
|
||||
draw::Draw,
|
||||
navcorder::{Navcorder, NavcorderException},
|
||||
navmesh::{BinavvertexNodeIndex, Navmesh, NavvertexIndex},
|
||||
navmesh::{BinavnodeNodeIndex, Navmesh, NavnodeIndex},
|
||||
};
|
||||
|
||||
/// The `Navcord` is a data structure that holds the movable non-borrowing data
|
||||
|
|
@ -35,7 +35,7 @@ pub struct Navcord {
|
|||
/// The layout edit which we are currently recording.
|
||||
pub recorder: LayoutEdit,
|
||||
/// The currently attempted path.
|
||||
pub path: Vec<NavvertexIndex>,
|
||||
pub path: Vec<NavnodeIndex>,
|
||||
/// The head of the currently routed band.
|
||||
pub head: Head,
|
||||
/// If the band is finished, stores the termseg that was used to finish it.
|
||||
|
|
@ -49,25 +49,25 @@ impl Navcord {
|
|||
pub fn new(
|
||||
recorder: LayoutEdit,
|
||||
source: FixedDotIndex,
|
||||
source_navvertex: NavvertexIndex,
|
||||
source_navnode: NavnodeIndex,
|
||||
width: f64,
|
||||
) -> Navcord {
|
||||
Self {
|
||||
recorder,
|
||||
path: vec![source_navvertex],
|
||||
path: vec![source_navnode],
|
||||
head: BareHead { face: source }.into(),
|
||||
final_termseg: None,
|
||||
width,
|
||||
}
|
||||
}
|
||||
|
||||
/// From the current head `head` wrap a new head around the navvertex `around`.
|
||||
/// From the current head `head` wrap a new head around the navnode `around`.
|
||||
fn wrap(
|
||||
&mut self,
|
||||
layout: &mut Layout<impl AccessRules>,
|
||||
navmesh: &Navmesh,
|
||||
head: Head,
|
||||
around: NavvertexIndex,
|
||||
around: NavnodeIndex,
|
||||
) -> Result<CaneHead, NavcorderException> {
|
||||
let around_node_weight = navmesh.node_weight(around).unwrap();
|
||||
let sense = around_node_weight
|
||||
|
|
@ -75,17 +75,17 @@ impl Navcord {
|
|||
.ok_or(NavcorderException::CannotWrap)?;
|
||||
|
||||
match around_node_weight.node {
|
||||
BinavvertexNodeIndex::FixedDot(dot) => {
|
||||
BinavnodeNodeIndex::FixedDot(dot) => {
|
||||
layout.cane_around_dot(&mut self.recorder, head, dot, sense, self.width)
|
||||
}
|
||||
BinavvertexNodeIndex::FixedBend(fixed_bend) => layout.cane_around_bend(
|
||||
BinavnodeNodeIndex::FixedBend(fixed_bend) => layout.cane_around_bend(
|
||||
&mut self.recorder,
|
||||
head,
|
||||
fixed_bend.into(),
|
||||
sense,
|
||||
self.width,
|
||||
),
|
||||
BinavvertexNodeIndex::LooseBend(loose_bend) => layout.cane_around_bend(
|
||||
BinavnodeNodeIndex::LooseBend(loose_bend) => layout.cane_around_bend(
|
||||
&mut self.recorder,
|
||||
head,
|
||||
loose_bend.into(),
|
||||
|
|
@ -97,18 +97,18 @@ impl Navcord {
|
|||
}
|
||||
|
||||
/// Advance the navcord and the currently routed band by one step to the
|
||||
/// navvertex `to`.
|
||||
/// navnode `to`.
|
||||
#[debug_ensures(ret.is_ok() -> self.path.len() == old(self.path.len() + 1))]
|
||||
#[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))]
|
||||
pub fn step_to<R: AccessRules>(
|
||||
&mut self,
|
||||
layout: &mut Layout<R>,
|
||||
navmesh: &Navmesh,
|
||||
to: NavvertexIndex,
|
||||
to: NavnodeIndex,
|
||||
) -> Result<(), NavcorderException> {
|
||||
if to == navmesh.destination_navvertex() {
|
||||
if to == navmesh.destination_navnode() {
|
||||
let to_node_weight = navmesh.node_weight(to).unwrap();
|
||||
let BinavvertexNodeIndex::FixedDot(to_dot) = to_node_weight.node else {
|
||||
let BinavnodeNodeIndex::FixedDot(to_dot) = to_node_weight.node else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ impl Navcord {
|
|||
}
|
||||
|
||||
// Now that the new part of the trace has been created, push the
|
||||
// navvertex `to` onto the currently attempted path to start from it
|
||||
// navnode `to` onto the currently attempted path to start from it
|
||||
// on the next `.step_to(...)` call or retreat from it later using
|
||||
// `.step_back(...)`.
|
||||
self.path.push(to);
|
||||
|
|
@ -148,7 +148,7 @@ impl Navcord {
|
|||
}
|
||||
|
||||
// Now that the last head of the currently routed band was deleted, pop
|
||||
// the last navvertex from the currently attempted path so that it is up
|
||||
// the last navnode from the currently attempted path so that it is up
|
||||
// to date.
|
||||
self.path.pop();
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
use super::{
|
||||
draw::{Draw, DrawException},
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
navmesh::{Navmesh, NavnodeIndex},
|
||||
};
|
||||
|
||||
#[derive(Error, Debug, Clone, Copy)]
|
||||
|
|
@ -29,7 +29,7 @@ pub trait Navcorder {
|
|||
&mut self,
|
||||
recorder: LayoutEdit,
|
||||
source: FixedDotIndex,
|
||||
source_navvertex: NavvertexIndex,
|
||||
source_navnode: NavnodeIndex,
|
||||
width: f64,
|
||||
) -> Navcord;
|
||||
|
||||
|
|
@ -44,14 +44,14 @@ pub trait Navcorder {
|
|||
&mut self,
|
||||
navmesh: &Navmesh,
|
||||
navcord: &mut Navcord,
|
||||
path: &[NavvertexIndex],
|
||||
path: &[NavnodeIndex],
|
||||
) -> Result<(), NavcorderException>;
|
||||
|
||||
fn path(
|
||||
&mut self,
|
||||
navmesh: &Navmesh,
|
||||
navcord: &mut Navcord,
|
||||
path: &[NavvertexIndex],
|
||||
path: &[NavnodeIndex],
|
||||
) -> Result<(), NavcorderException>;
|
||||
|
||||
fn undo_path(&mut self, navcord: &mut Navcord, step_count: usize);
|
||||
|
|
@ -62,10 +62,10 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
&mut self,
|
||||
recorder: LayoutEdit,
|
||||
source: FixedDotIndex,
|
||||
source_navvertex: NavvertexIndex,
|
||||
source_navnode: NavnodeIndex,
|
||||
width: f64,
|
||||
) -> Navcord {
|
||||
Navcord::new(recorder, source, source_navvertex, width)
|
||||
Navcord::new(recorder, source, source_navnode, width)
|
||||
}
|
||||
|
||||
fn finish(
|
||||
|
|
@ -83,7 +83,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
&mut self,
|
||||
navmesh: &Navmesh,
|
||||
navcord: &mut Navcord,
|
||||
path: &[NavvertexIndex],
|
||||
path: &[NavnodeIndex],
|
||||
) -> Result<(), NavcorderException> {
|
||||
let prefix_length = navcord
|
||||
.path
|
||||
|
|
@ -102,7 +102,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
|
|||
&mut self,
|
||||
navmesh: &Navmesh,
|
||||
navcord: &mut Navcord,
|
||||
path: &[NavvertexIndex],
|
||||
path: &[NavnodeIndex],
|
||||
) -> Result<(), NavcorderException> {
|
||||
for (i, vertex) in path.iter().enumerate() {
|
||||
if let Err(err) = navcord.step_to(self, navmesh, *vertex) {
|
||||
|
|
|
|||
|
|
@ -39,54 +39,54 @@ use crate::{
|
|||
use super::RouterOptions;
|
||||
|
||||
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct NavvertexIndex(pub NodeIndex<usize>);
|
||||
pub struct NavnodeIndex(pub NodeIndex<usize>);
|
||||
|
||||
impl core::fmt::Debug for NavvertexIndex {
|
||||
impl core::fmt::Debug for NavnodeIndex {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "NavvertexIndex({})", self.0.index())
|
||||
write!(f, "NavnodeIndex({})", self.0.index())
|
||||
}
|
||||
}
|
||||
|
||||
impl GetPetgraphIndex for NavvertexIndex {
|
||||
impl GetPetgraphIndex for NavnodeIndex {
|
||||
fn petgraph_index(&self) -> NodeIndex<usize> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// A binavvertex is a pair of navvertices, one clockwise and the other
|
||||
/// counterclockwise. Unlike their constituents, binavvertices are themselves
|
||||
/// not considered navvertices.
|
||||
/// A binavnode is a pair of navnodes, one clockwise and the other
|
||||
/// counterclockwise. Unlike their constituents, binavnodes are themselves
|
||||
/// not considered navnodes.
|
||||
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BinavvertexNodeIndex {
|
||||
pub enum BinavnodeNodeIndex {
|
||||
FixedDot(FixedDotIndex),
|
||||
FixedBend(FixedBendIndex),
|
||||
LooseBend(LooseBendIndex),
|
||||
}
|
||||
|
||||
impl From<BinavvertexNodeIndex> for PrimitiveIndex {
|
||||
fn from(vertex: BinavvertexNodeIndex) -> Self {
|
||||
impl From<BinavnodeNodeIndex> for PrimitiveIndex {
|
||||
fn from(vertex: BinavnodeNodeIndex) -> Self {
|
||||
match vertex {
|
||||
BinavvertexNodeIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||
BinavvertexNodeIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||
BinavvertexNodeIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||
BinavnodeNodeIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||
BinavnodeNodeIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||
BinavnodeNodeIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BinavvertexNodeIndex> for GearIndex {
|
||||
fn from(vertex: BinavvertexNodeIndex) -> Self {
|
||||
impl From<BinavnodeNodeIndex> for GearIndex {
|
||||
fn from(vertex: BinavnodeNodeIndex) -> Self {
|
||||
match vertex {
|
||||
BinavvertexNodeIndex::FixedDot(dot) => GearIndex::FixedDot(dot),
|
||||
BinavvertexNodeIndex::FixedBend(bend) => GearIndex::FixedBend(bend),
|
||||
BinavvertexNodeIndex::LooseBend(bend) => GearIndex::LooseBend(bend),
|
||||
BinavnodeNodeIndex::FixedDot(dot) => GearIndex::FixedDot(dot),
|
||||
BinavnodeNodeIndex::FixedBend(bend) => GearIndex::FixedBend(bend),
|
||||
BinavnodeNodeIndex::LooseBend(bend) => GearIndex::LooseBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Trianvertices are the vertices of the triangulation before it is converted
|
||||
/// to the navmesh by multiplying each of them into more vertices (called
|
||||
/// navvertices). Every trianvertex corresponds to one or more binavvertices on
|
||||
/// navnodes). Every trianvertex corresponds to one or more binavnodes on
|
||||
/// the navmesh.
|
||||
///
|
||||
/// The name "trianvertex" is a shortening of "triangulation vertex".
|
||||
|
|
@ -97,11 +97,11 @@ enum TrianvertexNodeIndex {
|
|||
FixedBend(FixedBendIndex),
|
||||
}
|
||||
|
||||
impl From<TrianvertexNodeIndex> for BinavvertexNodeIndex {
|
||||
impl From<TrianvertexNodeIndex> for BinavnodeNodeIndex {
|
||||
fn from(vertex: TrianvertexNodeIndex) -> Self {
|
||||
match vertex {
|
||||
TrianvertexNodeIndex::FixedDot(dot) => BinavvertexNodeIndex::FixedDot(dot),
|
||||
TrianvertexNodeIndex::FixedBend(bend) => BinavvertexNodeIndex::FixedBend(bend),
|
||||
TrianvertexNodeIndex::FixedDot(dot) => BinavnodeNodeIndex::FixedDot(dot),
|
||||
TrianvertexNodeIndex::FixedBend(bend) => BinavnodeNodeIndex::FixedBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -125,15 +125,16 @@ impl HasPosition for TrianvertexWeight {
|
|||
}
|
||||
}
|
||||
|
||||
/// The names "navvertex" and "navmesh vertex" are equivalent to "navigation vertex".
|
||||
/// The terms "navnode" and "navmesh vertex", "navmesh node", "navigation
|
||||
/// vertex", "navigation node" are all equivalent.
|
||||
///
|
||||
/// See the following blog post for more information and a visualization of the navmesh
|
||||
/// during autorouting: <https://topola.dev/blog/2024/07/20/junejuly-2024-development-update/#advanced-debug-visualization>
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NavvertexWeight {
|
||||
pub node: BinavvertexNodeIndex,
|
||||
pub struct NavnodeWeight {
|
||||
pub node: BinavnodeNodeIndex,
|
||||
|
||||
/// There are two navvertices for each navigable node:
|
||||
/// There are two navnodes for each navigable node:
|
||||
/// one is clockwise (`Some(true)`), the other counterclockwise (`Some(false)`).
|
||||
/// The origin and destination nodes however have
|
||||
/// only one corresponding navmesh vertex each (`None`).
|
||||
|
|
@ -155,11 +156,11 @@ pub enum NavmeshError {
|
|||
/// The name "navmesh" is a blend of "navigation mesh".
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Navmesh {
|
||||
graph: UnGraph<NavvertexWeight, (), usize>,
|
||||
graph: UnGraph<NavnodeWeight, (), usize>,
|
||||
origin: FixedDotIndex,
|
||||
origin_navvertex: NavvertexIndex,
|
||||
origin_navnode: NavnodeIndex,
|
||||
destination: FixedDotIndex,
|
||||
destination_navvertex: NavvertexIndex,
|
||||
destination_navnode: NavnodeIndex,
|
||||
}
|
||||
|
||||
impl Navmesh {
|
||||
|
|
@ -213,37 +214,37 @@ impl Navmesh {
|
|||
destination: FixedDotIndex,
|
||||
options: RouterOptions,
|
||||
) -> Result<Self, NavmeshError> {
|
||||
let mut graph: UnGraph<NavvertexWeight, (), usize> = UnGraph::default();
|
||||
let mut origin_navvertex = None;
|
||||
let mut destination_navvertex = None;
|
||||
let mut graph: UnGraph<NavnodeWeight, (), usize> = UnGraph::default();
|
||||
let mut origin_navnode = None;
|
||||
let mut destination_navnode = None;
|
||||
|
||||
let mut map = BTreeMap::new();
|
||||
|
||||
for trianvertex in triangulation.node_identifiers() {
|
||||
if trianvertex == origin.into() {
|
||||
let navvertex = graph.add_node(NavvertexWeight {
|
||||
let navnode = graph.add_node(NavnodeWeight {
|
||||
node: trianvertex.into(),
|
||||
maybe_sense: None,
|
||||
});
|
||||
|
||||
origin_navvertex = Some(navvertex);
|
||||
map.insert(trianvertex, vec![(navvertex, navvertex)]);
|
||||
origin_navnode = Some(navnode);
|
||||
map.insert(trianvertex, vec![(navnode, navnode)]);
|
||||
} else if trianvertex == destination.into() {
|
||||
let navvertex = graph.add_node(NavvertexWeight {
|
||||
let navnode = graph.add_node(NavnodeWeight {
|
||||
node: trianvertex.into(),
|
||||
maybe_sense: None,
|
||||
});
|
||||
|
||||
destination_navvertex = Some(navvertex);
|
||||
map.insert(trianvertex, vec![(navvertex, navvertex)]);
|
||||
destination_navnode = Some(navnode);
|
||||
map.insert(trianvertex, vec![(navnode, navnode)]);
|
||||
} else {
|
||||
map.insert(trianvertex, vec![]);
|
||||
|
||||
let mut gear =
|
||||
Into::<GearIndex>::into(Into::<BinavvertexNodeIndex>::into(trianvertex));
|
||||
Into::<GearIndex>::into(Into::<BinavnodeNodeIndex>::into(trianvertex));
|
||||
|
||||
if options.squeeze_through_under_bends {
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -252,7 +253,7 @@ impl Navmesh {
|
|||
|
||||
if options.wrap_around_bands {
|
||||
while let Some(bend) = gear.ref_(layout.drawing()).next_gear() {
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -269,14 +270,14 @@ impl Navmesh {
|
|||
gear = bend.into();
|
||||
}
|
||||
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
bend.into(),
|
||||
);
|
||||
} else {
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -287,12 +288,12 @@ impl Navmesh {
|
|||
}
|
||||
|
||||
for edge in triangulation.edge_references() {
|
||||
for (from_navvertex1, from_navvertex2) in map[&edge.source()].iter() {
|
||||
for (to_navvertex1, to_navvertex2) in map[&edge.target()].iter() {
|
||||
graph.update_edge(*from_navvertex1, *to_navvertex1, ());
|
||||
graph.update_edge(*from_navvertex1, *to_navvertex2, ());
|
||||
graph.update_edge(*from_navvertex2, *to_navvertex1, ());
|
||||
graph.update_edge(*from_navvertex2, *to_navvertex2, ());
|
||||
for (from_navnode1, from_navnode2) in map[&edge.source()].iter() {
|
||||
for (to_navnode1, to_navnode2) in map[&edge.target()].iter() {
|
||||
graph.update_edge(*from_navnode1, *to_navnode1, ());
|
||||
graph.update_edge(*from_navnode1, *to_navnode2, ());
|
||||
graph.update_edge(*from_navnode2, *to_navnode1, ());
|
||||
graph.update_edge(*from_navnode2, *to_navnode2, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -300,35 +301,35 @@ impl Navmesh {
|
|||
Ok(Self {
|
||||
graph,
|
||||
origin,
|
||||
origin_navvertex: NavvertexIndex(origin_navvertex.unwrap()),
|
||||
origin_navnode: NavnodeIndex(origin_navnode.unwrap()),
|
||||
destination,
|
||||
destination_navvertex: NavvertexIndex(destination_navvertex.unwrap()),
|
||||
destination_navnode: NavnodeIndex(destination_navnode.unwrap()),
|
||||
})
|
||||
}
|
||||
|
||||
fn add_node_to_graph_and_map_as_binavvertex(
|
||||
graph: &mut UnGraph<NavvertexWeight, (), usize>,
|
||||
fn add_node_to_graph_and_map_as_binavnode(
|
||||
graph: &mut UnGraph<NavnodeWeight, (), usize>,
|
||||
map: &mut BTreeMap<TrianvertexNodeIndex, Vec<(NodeIndex<usize>, NodeIndex<usize>)>>,
|
||||
trianvertex: TrianvertexNodeIndex,
|
||||
node: BinavvertexNodeIndex,
|
||||
node: BinavnodeNodeIndex,
|
||||
) {
|
||||
let navvertex1 = graph.add_node(NavvertexWeight {
|
||||
let navnode1 = graph.add_node(NavnodeWeight {
|
||||
node,
|
||||
maybe_sense: Some(RotationSense::Counterclockwise),
|
||||
});
|
||||
|
||||
let navvertex2 = graph.add_node(NavvertexWeight {
|
||||
let navnode2 = graph.add_node(NavnodeWeight {
|
||||
node,
|
||||
maybe_sense: Some(RotationSense::Clockwise),
|
||||
});
|
||||
|
||||
map.get_mut(&trianvertex)
|
||||
.unwrap()
|
||||
.push((navvertex1, navvertex2));
|
||||
.push((navnode1, navnode2));
|
||||
}
|
||||
|
||||
/// Returns the navmesh's underlying petgraph graph structure.
|
||||
pub fn graph(&self) -> &UnGraph<NavvertexWeight, (), usize> {
|
||||
pub fn graph(&self) -> &UnGraph<NavnodeWeight, (), usize> {
|
||||
&self.graph
|
||||
}
|
||||
|
||||
|
|
@ -337,9 +338,9 @@ impl Navmesh {
|
|||
self.origin
|
||||
}
|
||||
|
||||
/// Returns the navvertex of the origin node.
|
||||
pub fn origin_navvertex(&self) -> NavvertexIndex {
|
||||
self.origin_navvertex
|
||||
/// Returns the navnode of the origin node.
|
||||
pub fn origin_navnode(&self) -> NavnodeIndex {
|
||||
self.origin_navnode
|
||||
}
|
||||
|
||||
/// Returns the destination node.
|
||||
|
|
@ -347,19 +348,19 @@ impl Navmesh {
|
|||
self.destination
|
||||
}
|
||||
|
||||
/// Returns the navvertex of the destination node.
|
||||
pub fn destination_navvertex(&self) -> NavvertexIndex {
|
||||
self.destination_navvertex
|
||||
/// Returns the navnode of the destination node.
|
||||
pub fn destination_navnode(&self) -> NavnodeIndex {
|
||||
self.destination_navnode
|
||||
}
|
||||
}
|
||||
|
||||
impl GraphBase for Navmesh {
|
||||
type NodeId = NavvertexIndex;
|
||||
type EdgeId = (NavvertexIndex, NavvertexIndex);
|
||||
type NodeId = NavnodeIndex;
|
||||
type EdgeId = (NavnodeIndex, NavnodeIndex);
|
||||
}
|
||||
|
||||
impl Data for Navmesh {
|
||||
type NodeWeight = NavvertexWeight;
|
||||
type NodeWeight = NavnodeWeight;
|
||||
type EdgeWeight = ();
|
||||
}
|
||||
|
||||
|
|
@ -375,13 +376,13 @@ impl DataMap for Navmesh {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NavmeshEdgeReference {
|
||||
from: NavvertexIndex,
|
||||
to: NavvertexIndex,
|
||||
from: NavnodeIndex,
|
||||
to: NavnodeIndex,
|
||||
}
|
||||
|
||||
impl EdgeRef for NavmeshEdgeReference {
|
||||
type NodeId = NavvertexIndex;
|
||||
type EdgeId = (NavvertexIndex, NavvertexIndex);
|
||||
type NodeId = NavnodeIndex;
|
||||
type EdgeId = (NavnodeIndex, NavnodeIndex);
|
||||
type Weight = ();
|
||||
|
||||
fn source(&self) -> Self::NodeId {
|
||||
|
|
@ -402,13 +403,13 @@ impl EdgeRef for NavmeshEdgeReference {
|
|||
}
|
||||
|
||||
impl<'a> IntoNeighbors for &'a Navmesh {
|
||||
type Neighbors = Box<dyn Iterator<Item = NavvertexIndex> + 'a>;
|
||||
type Neighbors = Box<dyn Iterator<Item = NavnodeIndex> + 'a>;
|
||||
|
||||
fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors {
|
||||
Box::new(
|
||||
self.graph
|
||||
.neighbors(vertex.petgraph_index())
|
||||
.map(NavvertexIndex),
|
||||
.map(NavnodeIndex),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -422,8 +423,8 @@ impl<'a> IntoEdgeReferences for &'a Navmesh {
|
|||
self.graph
|
||||
.edge_references()
|
||||
.map(|edge| NavmeshEdgeReference {
|
||||
from: NavvertexIndex(edge.source()),
|
||||
to: NavvertexIndex(edge.target()),
|
||||
from: NavnodeIndex(edge.source()),
|
||||
to: NavnodeIndex(edge.target()),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
@ -437,8 +438,8 @@ impl<'a> IntoEdges for &'a Navmesh {
|
|||
self.graph
|
||||
.edges(vertex.petgraph_index())
|
||||
.map(|edge| NavmeshEdgeReference {
|
||||
from: NavvertexIndex(edge.source()),
|
||||
to: NavvertexIndex(edge.target()),
|
||||
from: NavnodeIndex(edge.source()),
|
||||
to: NavnodeIndex(edge.target()),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,14 +49,14 @@ impl RouteStepper {
|
|||
width: f64,
|
||||
) -> Self {
|
||||
let source = navmesh.origin();
|
||||
let source_navvertex = navmesh.origin_navvertex();
|
||||
let source_navnode = navmesh.origin_navnode();
|
||||
let target = navmesh.destination();
|
||||
|
||||
let layout = router.layout_mut();
|
||||
let mut navcord = layout.start(recorder, source, source_navvertex, width);
|
||||
let mut navcord = layout.start(recorder, source, source_navnode, width);
|
||||
|
||||
let mut strategy = RouterAstarStrategy::new(layout, &mut navcord, target);
|
||||
let astar = AstarStepper::new(navmesh, source_navvertex, &mut strategy);
|
||||
let astar = AstarStepper::new(navmesh, source_navnode, &mut strategy);
|
||||
let ghosts = vec![];
|
||||
let obstacles = vec![];
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper {
|
|||
Ok(ControlFlow::Break((_cost, _path, band))) => Ok(ControlFlow::Break(band)),
|
||||
Err(e) => {
|
||||
// NOTE(fogti): The 1 instead 0 is because the first element in the path
|
||||
// is the source navvertex. See also: `NavcordStepper::new`.
|
||||
// is the source navnode. See also: `NavcordStepper::new`.
|
||||
for _ in 1..self.navcord.path.len() {
|
||||
self.navcord.step_back(layout);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use super::{
|
|||
draw::DrawException,
|
||||
navcord::Navcord,
|
||||
navcorder::{Navcorder, NavcorderException},
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavvertexIndex},
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavnodeIndex},
|
||||
route::RouteStepper,
|
||||
};
|
||||
|
||||
|
|
@ -65,12 +65,12 @@ impl<R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex> for RouterAst
|
|||
fn is_goal(
|
||||
&mut self,
|
||||
navmesh: &Navmesh,
|
||||
vertex: NavvertexIndex,
|
||||
vertex: NavnodeIndex,
|
||||
tracker: &PathTracker<Navmesh>,
|
||||
) -> Option<BandTermsegIndex> {
|
||||
let new_path = tracker.reconstruct_path_to(vertex);
|
||||
|
||||
if vertex == navmesh.destination_navvertex() {
|
||||
if vertex == navmesh.destination_navnode() {
|
||||
self.layout
|
||||
.rework_path(navmesh, self.navcord, &new_path[..new_path.len() - 1])
|
||||
.unwrap();
|
||||
|
|
@ -137,7 +137,7 @@ impl<R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex> for RouterAst
|
|||
self.navcord.step_back(self.layout);
|
||||
}
|
||||
|
||||
fn estimate_cost(&mut self, navmesh: &Navmesh, vertex: NavvertexIndex) -> f64 {
|
||||
fn estimate_cost(&mut self, navmesh: &Navmesh, vertex: NavnodeIndex) -> f64 {
|
||||
let start_point = PrimitiveIndex::from(navmesh.node_weight(vertex).unwrap().node)
|
||||
.primitive(self.layout.drawing())
|
||||
.shape()
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ pub fn replay_and_assert(invoker: &mut Invoker<SpecctraMesadata>, filename: &str
|
|||
);
|
||||
}
|
||||
|
||||
pub fn assert_navvertex_count(
|
||||
pub fn assert_navnode_count(
|
||||
autorouter: &mut Autorouter<SpecctraMesadata>,
|
||||
origin_pin: &str,
|
||||
destination_pin: &str,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ mod common;
|
|||
#[test]
|
||||
fn test_0603_breakout() {
|
||||
let mut autorouter = common::load_design("tests/single_layer/0603_breakout/0603_breakout.dsn");
|
||||
common::assert_navvertex_count(&mut autorouter, "R1-2", "J1-2", 54);
|
||||
common::assert_navnode_count(&mut autorouter, "R1-2", "J1-2", 54);
|
||||
let mut invoker = common::create_invoker_and_assert(autorouter);
|
||||
common::replay_and_assert(
|
||||
&mut invoker,
|
||||
|
|
@ -35,7 +35,7 @@ fn test_tht_diode_bridge_rectifier() {
|
|||
let mut autorouter = common::load_design(
|
||||
"tests/single_layer/tht_diode_bridge_rectifier/tht_diode_bridge_rectifier.dsn",
|
||||
);
|
||||
common::assert_navvertex_count(&mut autorouter, "J2-2", "D4-2", 68);
|
||||
common::assert_navnode_count(&mut autorouter, "J2-2", "D4-2", 68);
|
||||
let mut invoker = common::create_invoker_and_assert(autorouter);
|
||||
common::replay_and_assert(
|
||||
&mut invoker,
|
||||
|
|
@ -71,7 +71,7 @@ fn test_4x_3rd_order_smd_lc_filters() {
|
|||
let mut autorouter = common::load_design(
|
||||
"tests/single_layer/4x_3rd_order_smd_lc_filters/4x_3rd_order_smd_lc_filters.dsn",
|
||||
);
|
||||
common::assert_navvertex_count(&mut autorouter, "J1-1", "L1-1", 2062);
|
||||
common::assert_navnode_count(&mut autorouter, "J1-1", "L1-1", 2062);
|
||||
let mut invoker = common::create_invoker_and_assert(autorouter);
|
||||
common::replay_and_assert(
|
||||
&mut invoker,
|
||||
|
|
@ -92,7 +92,7 @@ fn test_tht_3pin_xlr_to_tht_3pin_xlr() {
|
|||
let mut autorouter = common::load_design(
|
||||
"tests/single_layer/tht_3pin_xlr_to_tht_3pin_xlr/tht_3pin_xlr_to_tht_3pin_xlr.dsn",
|
||||
);
|
||||
//common::assert_navvertex_count(&mut autorouter, "R1-2", "J1-2", ?);
|
||||
//common::assert_navnode_count(&mut autorouter, "R1-2", "J1-2", ?);
|
||||
let mut invoker = common::create_invoker_and_assert(autorouter);
|
||||
common::replay_and_assert(
|
||||
&mut invoker,
|
||||
|
|
|
|||
Loading…
Reference in New Issue