refactor(router/navmesh): Rename "navvertex" to "navnode"

Easier to pronounce.
This commit is contained in:
Mikolaj Wielgus 2025-05-22 16:32:14 +02:00
parent 8d0681c07d
commit 24d119ad04
11 changed files with 131 additions and 130 deletions

View File

@ -24,7 +24,7 @@ use topola::{
graph::MakeRef, graph::MakeRef,
layout::{poly::MakePolygon, via::ViaWeight}, layout::{poly::MakePolygon, via::ViaWeight},
math::{Circle, RotationSense}, math::{Circle, RotationSense},
router::navmesh::NavvertexIndex, router::navmesh::NavnodeIndex,
}; };
use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace}; use crate::{config::Config, menu_bar::MenuBar, painter::Painter, workspace::Workspace};
@ -333,16 +333,16 @@ impl Viewport {
} }
for index in navmesh.graph().node_indices() { for index in navmesh.graph().node_indices() {
let navvertex = NavvertexIndex(index); let navnode = NavnodeIndex(index);
let mut pos = PrimitiveIndex::from( let mut pos = PrimitiveIndex::from(
navmesh.node_weight(navvertex).unwrap().node, navmesh.node_weight(navnode).unwrap().node,
) )
.primitive(board.layout().drawing()) .primitive(board.layout().drawing())
.shape() .shape()
.center(); .center();
pos += match navmesh pos += match navmesh
.node_weight(navvertex) .node_weight(navnode)
.unwrap() .unwrap()
.maybe_sense .maybe_sense
{ {
@ -356,14 +356,14 @@ impl Viewport {
//TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)" //TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)"
let score_text = &astar let score_text = &astar
.scores .scores
.get(&navvertex) .get(&navnode)
.map_or_else(String::new, |s| format!("g={:.2}", s)); .map_or_else(String::new, |s| format!("g={:.2}", s));
let estimate_score_text = &astar let estimate_score_text = &astar
.estimate_scores .estimate_scores
.get(&navvertex) .get(&navnode)
.map_or_else(String::new, |s| format!("(f={:.2})", s)); .map_or_else(String::new, |s| format!("(f={:.2})", s));
let debug_text = let debug_text =
activity.navvertex_debug_text(navvertex).unwrap_or(""); activity.navnode_debug_text(navnode).unwrap_or("");
painter.paint_text( painter.paint_text(
pos, pos,

View File

@ -18,7 +18,7 @@ use crate::{
router::{ router::{
astar::AstarStepper, astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavnodeIndex},
}, },
stepper::Step, stepper::Step,
}; };
@ -76,11 +76,11 @@ pub trait GetObstacles {
/// Trait for getting text strings with debug information attached to navmesh /// Trait for getting text strings with debug information attached to navmesh
/// edges and vertices. /// edges and vertices.
pub trait GetNavmeshDebugTexts { pub trait GetNavmeshDebugTexts {
fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { fn navnode_debug_text(&self, _navnode: NavnodeIndex) -> Option<&str> {
None None
} }
fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { fn navedge_debug_text(&self, _navedge: (NavnodeIndex, NavnodeIndex)) -> Option<&str> {
None None
} }
} }

View File

@ -23,7 +23,7 @@ use crate::{
router::{ router::{
astar::AstarStepper, astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavnodeIndex},
}, },
stepper::{Abort, Step}, stepper::{Abort, Step},
}; };
@ -150,11 +150,11 @@ impl GetObstacles for ActivityStepperWithStatus {
} }
impl GetNavmeshDebugTexts for ActivityStepperWithStatus { impl GetNavmeshDebugTexts for ActivityStepperWithStatus {
fn navvertex_debug_text(&self, navvertex: NavvertexIndex) -> Option<&str> { fn navnode_debug_text(&self, navnode: NavnodeIndex) -> Option<&str> {
self.activity.navvertex_debug_text(navvertex) 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) self.activity.navedge_debug_text(navedge)
} }
} }

View File

@ -16,7 +16,7 @@ use crate::{
router::{ router::{
astar::AstarStepper, astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavnodeIndex},
}, },
stepper::{Abort, Step}, stepper::{Abort, Step},
}; };
@ -78,11 +78,11 @@ impl GetObstacles for InteractionStepper {
} }
impl GetNavmeshDebugTexts 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!() todo!()
} }
fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { fn navedge_debug_text(&self, _navedge: (NavnodeIndex, NavnodeIndex)) -> Option<&str> {
todo!() todo!()
} }
} }

View File

@ -18,7 +18,7 @@ use crate::{
use super::{ use super::{
draw::Draw, draw::Draw,
navcorder::{Navcorder, NavcorderException}, navcorder::{Navcorder, NavcorderException},
navmesh::{BinavvertexNodeIndex, Navmesh, NavvertexIndex}, navmesh::{BinavnodeNodeIndex, Navmesh, NavnodeIndex},
}; };
/// The `Navcord` is a data structure that holds the movable non-borrowing data /// 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. /// The layout edit which we are currently recording.
pub recorder: LayoutEdit, pub recorder: LayoutEdit,
/// The currently attempted path. /// The currently attempted path.
pub path: Vec<NavvertexIndex>, pub path: Vec<NavnodeIndex>,
/// The head of the currently routed band. /// The head of the currently routed band.
pub head: Head, pub head: Head,
/// If the band is finished, stores the termseg that was used to finish it. /// If the band is finished, stores the termseg that was used to finish it.
@ -49,25 +49,25 @@ impl Navcord {
pub fn new( pub fn new(
recorder: LayoutEdit, recorder: LayoutEdit,
source: FixedDotIndex, source: FixedDotIndex,
source_navvertex: NavvertexIndex, source_navnode: NavnodeIndex,
width: f64, width: f64,
) -> Navcord { ) -> Navcord {
Self { Self {
recorder, recorder,
path: vec![source_navvertex], path: vec![source_navnode],
head: BareHead { face: source }.into(), head: BareHead { face: source }.into(),
final_termseg: None, final_termseg: None,
width, 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( fn wrap(
&mut self, &mut self,
layout: &mut Layout<impl AccessRules>, layout: &mut Layout<impl AccessRules>,
navmesh: &Navmesh, navmesh: &Navmesh,
head: Head, head: Head,
around: NavvertexIndex, around: NavnodeIndex,
) -> Result<CaneHead, NavcorderException> { ) -> Result<CaneHead, NavcorderException> {
let around_node_weight = navmesh.node_weight(around).unwrap(); let around_node_weight = navmesh.node_weight(around).unwrap();
let sense = around_node_weight let sense = around_node_weight
@ -75,17 +75,17 @@ impl Navcord {
.ok_or(NavcorderException::CannotWrap)?; .ok_or(NavcorderException::CannotWrap)?;
match around_node_weight.node { match around_node_weight.node {
BinavvertexNodeIndex::FixedDot(dot) => { BinavnodeNodeIndex::FixedDot(dot) => {
layout.cane_around_dot(&mut self.recorder, head, dot, sense, self.width) 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, &mut self.recorder,
head, head,
fixed_bend.into(), fixed_bend.into(),
sense, sense,
self.width, self.width,
), ),
BinavvertexNodeIndex::LooseBend(loose_bend) => layout.cane_around_bend( BinavnodeNodeIndex::LooseBend(loose_bend) => layout.cane_around_bend(
&mut self.recorder, &mut self.recorder,
head, head,
loose_bend.into(), loose_bend.into(),
@ -97,18 +97,18 @@ impl Navcord {
} }
/// Advance the navcord and the currently routed band by one step to the /// 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_ok() -> self.path.len() == old(self.path.len() + 1))]
#[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))] #[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))]
pub fn step_to<R: AccessRules>( pub fn step_to<R: AccessRules>(
&mut self, &mut self,
layout: &mut Layout<R>, layout: &mut Layout<R>,
navmesh: &Navmesh, navmesh: &Navmesh,
to: NavvertexIndex, to: NavnodeIndex,
) -> Result<(), NavcorderException> { ) -> Result<(), NavcorderException> {
if to == navmesh.destination_navvertex() { if to == navmesh.destination_navnode() {
let to_node_weight = navmesh.node_weight(to).unwrap(); 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!(); unreachable!();
}; };
@ -122,7 +122,7 @@ impl Navcord {
} }
// Now that the new part of the trace has been created, push the // 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 // on the next `.step_to(...)` call or retreat from it later using
// `.step_back(...)`. // `.step_back(...)`.
self.path.push(to); self.path.push(to);
@ -148,7 +148,7 @@ impl Navcord {
} }
// Now that the last head of the currently routed band was deleted, pop // 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. // to date.
self.path.pop(); self.path.pop();
Ok(()) Ok(())

View File

@ -13,7 +13,7 @@ use crate::{
use super::{ use super::{
draw::{Draw, DrawException}, draw::{Draw, DrawException},
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavnodeIndex},
}; };
#[derive(Error, Debug, Clone, Copy)] #[derive(Error, Debug, Clone, Copy)]
@ -29,7 +29,7 @@ pub trait Navcorder {
&mut self, &mut self,
recorder: LayoutEdit, recorder: LayoutEdit,
source: FixedDotIndex, source: FixedDotIndex,
source_navvertex: NavvertexIndex, source_navnode: NavnodeIndex,
width: f64, width: f64,
) -> Navcord; ) -> Navcord;
@ -44,14 +44,14 @@ pub trait Navcorder {
&mut self, &mut self,
navmesh: &Navmesh, navmesh: &Navmesh,
navcord: &mut Navcord, navcord: &mut Navcord,
path: &[NavvertexIndex], path: &[NavnodeIndex],
) -> Result<(), NavcorderException>; ) -> Result<(), NavcorderException>;
fn path( fn path(
&mut self, &mut self,
navmesh: &Navmesh, navmesh: &Navmesh,
navcord: &mut Navcord, navcord: &mut Navcord,
path: &[NavvertexIndex], path: &[NavnodeIndex],
) -> Result<(), NavcorderException>; ) -> Result<(), NavcorderException>;
fn undo_path(&mut self, navcord: &mut Navcord, step_count: usize); fn undo_path(&mut self, navcord: &mut Navcord, step_count: usize);
@ -62,10 +62,10 @@ impl<R: AccessRules> Navcorder for Layout<R> {
&mut self, &mut self,
recorder: LayoutEdit, recorder: LayoutEdit,
source: FixedDotIndex, source: FixedDotIndex,
source_navvertex: NavvertexIndex, source_navnode: NavnodeIndex,
width: f64, width: f64,
) -> Navcord { ) -> Navcord {
Navcord::new(recorder, source, source_navvertex, width) Navcord::new(recorder, source, source_navnode, width)
} }
fn finish( fn finish(
@ -83,7 +83,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
&mut self, &mut self,
navmesh: &Navmesh, navmesh: &Navmesh,
navcord: &mut Navcord, navcord: &mut Navcord,
path: &[NavvertexIndex], path: &[NavnodeIndex],
) -> Result<(), NavcorderException> { ) -> Result<(), NavcorderException> {
let prefix_length = navcord let prefix_length = navcord
.path .path
@ -102,7 +102,7 @@ impl<R: AccessRules> Navcorder for Layout<R> {
&mut self, &mut self,
navmesh: &Navmesh, navmesh: &Navmesh,
navcord: &mut Navcord, navcord: &mut Navcord,
path: &[NavvertexIndex], path: &[NavnodeIndex],
) -> Result<(), NavcorderException> { ) -> Result<(), NavcorderException> {
for (i, vertex) in path.iter().enumerate() { for (i, vertex) in path.iter().enumerate() {
if let Err(err) = navcord.step_to(self, navmesh, *vertex) { if let Err(err) = navcord.step_to(self, navmesh, *vertex) {

View File

@ -39,54 +39,54 @@ use crate::{
use super::RouterOptions; use super::RouterOptions;
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] #[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 { 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> { fn petgraph_index(&self) -> NodeIndex<usize> {
self.0 self.0
} }
} }
/// A binavvertex is a pair of navvertices, one clockwise and the other /// A binavnode is a pair of navnodes, one clockwise and the other
/// counterclockwise. Unlike their constituents, binavvertices are themselves /// counterclockwise. Unlike their constituents, binavnodes are themselves
/// not considered navvertices. /// not considered navnodes.
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)] #[enum_dispatch(GetPetgraphIndex, MakePrimitive)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinavvertexNodeIndex { pub enum BinavnodeNodeIndex {
FixedDot(FixedDotIndex), FixedDot(FixedDotIndex),
FixedBend(FixedBendIndex), FixedBend(FixedBendIndex),
LooseBend(LooseBendIndex), LooseBend(LooseBendIndex),
} }
impl From<BinavvertexNodeIndex> for PrimitiveIndex { impl From<BinavnodeNodeIndex> for PrimitiveIndex {
fn from(vertex: BinavvertexNodeIndex) -> Self { fn from(vertex: BinavnodeNodeIndex) -> Self {
match vertex { match vertex {
BinavvertexNodeIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot), BinavnodeNodeIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
BinavvertexNodeIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend), BinavnodeNodeIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
BinavvertexNodeIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend), BinavnodeNodeIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
} }
} }
} }
impl From<BinavvertexNodeIndex> for GearIndex { impl From<BinavnodeNodeIndex> for GearIndex {
fn from(vertex: BinavvertexNodeIndex) -> Self { fn from(vertex: BinavnodeNodeIndex) -> Self {
match vertex { match vertex {
BinavvertexNodeIndex::FixedDot(dot) => GearIndex::FixedDot(dot), BinavnodeNodeIndex::FixedDot(dot) => GearIndex::FixedDot(dot),
BinavvertexNodeIndex::FixedBend(bend) => GearIndex::FixedBend(bend), BinavnodeNodeIndex::FixedBend(bend) => GearIndex::FixedBend(bend),
BinavvertexNodeIndex::LooseBend(bend) => GearIndex::LooseBend(bend), BinavnodeNodeIndex::LooseBend(bend) => GearIndex::LooseBend(bend),
} }
} }
} }
/// Trianvertices are the vertices of the triangulation before it is converted /// Trianvertices are the vertices of the triangulation before it is converted
/// to the navmesh by multiplying each of them into more vertices (called /// 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 navmesh.
/// ///
/// The name "trianvertex" is a shortening of "triangulation vertex". /// The name "trianvertex" is a shortening of "triangulation vertex".
@ -97,11 +97,11 @@ enum TrianvertexNodeIndex {
FixedBend(FixedBendIndex), FixedBend(FixedBendIndex),
} }
impl From<TrianvertexNodeIndex> for BinavvertexNodeIndex { impl From<TrianvertexNodeIndex> for BinavnodeNodeIndex {
fn from(vertex: TrianvertexNodeIndex) -> Self { fn from(vertex: TrianvertexNodeIndex) -> Self {
match vertex { match vertex {
TrianvertexNodeIndex::FixedDot(dot) => BinavvertexNodeIndex::FixedDot(dot), TrianvertexNodeIndex::FixedDot(dot) => BinavnodeNodeIndex::FixedDot(dot),
TrianvertexNodeIndex::FixedBend(bend) => BinavvertexNodeIndex::FixedBend(bend), 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 /// 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> /// during autorouting: <https://topola.dev/blog/2024/07/20/junejuly-2024-development-update/#advanced-debug-visualization>
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct NavvertexWeight { pub struct NavnodeWeight {
pub node: BinavvertexNodeIndex, 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)`). /// one is clockwise (`Some(true)`), the other counterclockwise (`Some(false)`).
/// The origin and destination nodes however have /// The origin and destination nodes however have
/// only one corresponding navmesh vertex each (`None`). /// only one corresponding navmesh vertex each (`None`).
@ -155,11 +156,11 @@ pub enum NavmeshError {
/// The name "navmesh" is a blend of "navigation mesh". /// The name "navmesh" is a blend of "navigation mesh".
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Navmesh { pub struct Navmesh {
graph: UnGraph<NavvertexWeight, (), usize>, graph: UnGraph<NavnodeWeight, (), usize>,
origin: FixedDotIndex, origin: FixedDotIndex,
origin_navvertex: NavvertexIndex, origin_navnode: NavnodeIndex,
destination: FixedDotIndex, destination: FixedDotIndex,
destination_navvertex: NavvertexIndex, destination_navnode: NavnodeIndex,
} }
impl Navmesh { impl Navmesh {
@ -213,37 +214,37 @@ impl Navmesh {
destination: FixedDotIndex, destination: FixedDotIndex,
options: RouterOptions, options: RouterOptions,
) -> Result<Self, NavmeshError> { ) -> Result<Self, NavmeshError> {
let mut graph: UnGraph<NavvertexWeight, (), usize> = UnGraph::default(); let mut graph: UnGraph<NavnodeWeight, (), usize> = UnGraph::default();
let mut origin_navvertex = None; let mut origin_navnode = None;
let mut destination_navvertex = None; let mut destination_navnode = None;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
for trianvertex in triangulation.node_identifiers() { for trianvertex in triangulation.node_identifiers() {
if trianvertex == origin.into() { if trianvertex == origin.into() {
let navvertex = graph.add_node(NavvertexWeight { let navnode = graph.add_node(NavnodeWeight {
node: trianvertex.into(), node: trianvertex.into(),
maybe_sense: None, maybe_sense: None,
}); });
origin_navvertex = Some(navvertex); origin_navnode = Some(navnode);
map.insert(trianvertex, vec![(navvertex, navvertex)]); map.insert(trianvertex, vec![(navnode, navnode)]);
} else if trianvertex == destination.into() { } else if trianvertex == destination.into() {
let navvertex = graph.add_node(NavvertexWeight { let navnode = graph.add_node(NavnodeWeight {
node: trianvertex.into(), node: trianvertex.into(),
maybe_sense: None, maybe_sense: None,
}); });
destination_navvertex = Some(navvertex); destination_navnode = Some(navnode);
map.insert(trianvertex, vec![(navvertex, navvertex)]); map.insert(trianvertex, vec![(navnode, navnode)]);
} else { } else {
map.insert(trianvertex, vec![]); map.insert(trianvertex, vec![]);
let mut gear = let mut gear =
Into::<GearIndex>::into(Into::<BinavvertexNodeIndex>::into(trianvertex)); Into::<GearIndex>::into(Into::<BinavnodeNodeIndex>::into(trianvertex));
if options.squeeze_through_under_bends { 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 graph,
&mut map, &mut map,
trianvertex, trianvertex,
@ -252,7 +253,7 @@ impl Navmesh {
if options.wrap_around_bands { if options.wrap_around_bands {
while let Some(bend) = gear.ref_(layout.drawing()).next_gear() { 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 graph,
&mut map, &mut map,
trianvertex, trianvertex,
@ -269,14 +270,14 @@ impl Navmesh {
gear = bend.into(); gear = bend.into();
} }
Self::add_node_to_graph_and_map_as_binavvertex( Self::add_node_to_graph_and_map_as_binavnode(
&mut graph, &mut graph,
&mut map, &mut map,
trianvertex, trianvertex,
bend.into(), bend.into(),
); );
} else { } else {
Self::add_node_to_graph_and_map_as_binavvertex( Self::add_node_to_graph_and_map_as_binavnode(
&mut graph, &mut graph,
&mut map, &mut map,
trianvertex, trianvertex,
@ -287,12 +288,12 @@ impl Navmesh {
} }
for edge in triangulation.edge_references() { for edge in triangulation.edge_references() {
for (from_navvertex1, from_navvertex2) in map[&edge.source()].iter() { for (from_navnode1, from_navnode2) in map[&edge.source()].iter() {
for (to_navvertex1, to_navvertex2) in map[&edge.target()].iter() { for (to_navnode1, to_navnode2) in map[&edge.target()].iter() {
graph.update_edge(*from_navvertex1, *to_navvertex1, ()); graph.update_edge(*from_navnode1, *to_navnode1, ());
graph.update_edge(*from_navvertex1, *to_navvertex2, ()); graph.update_edge(*from_navnode1, *to_navnode2, ());
graph.update_edge(*from_navvertex2, *to_navvertex1, ()); graph.update_edge(*from_navnode2, *to_navnode1, ());
graph.update_edge(*from_navvertex2, *to_navvertex2, ()); graph.update_edge(*from_navnode2, *to_navnode2, ());
} }
} }
} }
@ -300,35 +301,35 @@ impl Navmesh {
Ok(Self { Ok(Self {
graph, graph,
origin, origin,
origin_navvertex: NavvertexIndex(origin_navvertex.unwrap()), origin_navnode: NavnodeIndex(origin_navnode.unwrap()),
destination, destination,
destination_navvertex: NavvertexIndex(destination_navvertex.unwrap()), destination_navnode: NavnodeIndex(destination_navnode.unwrap()),
}) })
} }
fn add_node_to_graph_and_map_as_binavvertex( fn add_node_to_graph_and_map_as_binavnode(
graph: &mut UnGraph<NavvertexWeight, (), usize>, graph: &mut UnGraph<NavnodeWeight, (), usize>,
map: &mut BTreeMap<TrianvertexNodeIndex, Vec<(NodeIndex<usize>, NodeIndex<usize>)>>, map: &mut BTreeMap<TrianvertexNodeIndex, Vec<(NodeIndex<usize>, NodeIndex<usize>)>>,
trianvertex: TrianvertexNodeIndex, trianvertex: TrianvertexNodeIndex,
node: BinavvertexNodeIndex, node: BinavnodeNodeIndex,
) { ) {
let navvertex1 = graph.add_node(NavvertexWeight { let navnode1 = graph.add_node(NavnodeWeight {
node, node,
maybe_sense: Some(RotationSense::Counterclockwise), maybe_sense: Some(RotationSense::Counterclockwise),
}); });
let navvertex2 = graph.add_node(NavvertexWeight { let navnode2 = graph.add_node(NavnodeWeight {
node, node,
maybe_sense: Some(RotationSense::Clockwise), maybe_sense: Some(RotationSense::Clockwise),
}); });
map.get_mut(&trianvertex) map.get_mut(&trianvertex)
.unwrap() .unwrap()
.push((navvertex1, navvertex2)); .push((navnode1, navnode2));
} }
/// Returns the navmesh's underlying petgraph graph structure. /// Returns the navmesh's underlying petgraph graph structure.
pub fn graph(&self) -> &UnGraph<NavvertexWeight, (), usize> { pub fn graph(&self) -> &UnGraph<NavnodeWeight, (), usize> {
&self.graph &self.graph
} }
@ -337,9 +338,9 @@ impl Navmesh {
self.origin self.origin
} }
/// Returns the navvertex of the origin node. /// Returns the navnode of the origin node.
pub fn origin_navvertex(&self) -> NavvertexIndex { pub fn origin_navnode(&self) -> NavnodeIndex {
self.origin_navvertex self.origin_navnode
} }
/// Returns the destination node. /// Returns the destination node.
@ -347,19 +348,19 @@ impl Navmesh {
self.destination self.destination
} }
/// Returns the navvertex of the destination node. /// Returns the navnode of the destination node.
pub fn destination_navvertex(&self) -> NavvertexIndex { pub fn destination_navnode(&self) -> NavnodeIndex {
self.destination_navvertex self.destination_navnode
} }
} }
impl GraphBase for Navmesh { impl GraphBase for Navmesh {
type NodeId = NavvertexIndex; type NodeId = NavnodeIndex;
type EdgeId = (NavvertexIndex, NavvertexIndex); type EdgeId = (NavnodeIndex, NavnodeIndex);
} }
impl Data for Navmesh { impl Data for Navmesh {
type NodeWeight = NavvertexWeight; type NodeWeight = NavnodeWeight;
type EdgeWeight = (); type EdgeWeight = ();
} }
@ -375,13 +376,13 @@ impl DataMap for Navmesh {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct NavmeshEdgeReference { pub struct NavmeshEdgeReference {
from: NavvertexIndex, from: NavnodeIndex,
to: NavvertexIndex, to: NavnodeIndex,
} }
impl EdgeRef for NavmeshEdgeReference { impl EdgeRef for NavmeshEdgeReference {
type NodeId = NavvertexIndex; type NodeId = NavnodeIndex;
type EdgeId = (NavvertexIndex, NavvertexIndex); type EdgeId = (NavnodeIndex, NavnodeIndex);
type Weight = (); type Weight = ();
fn source(&self) -> Self::NodeId { fn source(&self) -> Self::NodeId {
@ -402,13 +403,13 @@ impl EdgeRef for NavmeshEdgeReference {
} }
impl<'a> IntoNeighbors for &'a Navmesh { 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 { fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors {
Box::new( Box::new(
self.graph self.graph
.neighbors(vertex.petgraph_index()) .neighbors(vertex.petgraph_index())
.map(NavvertexIndex), .map(NavnodeIndex),
) )
} }
} }
@ -422,8 +423,8 @@ impl<'a> IntoEdgeReferences for &'a Navmesh {
self.graph self.graph
.edge_references() .edge_references()
.map(|edge| NavmeshEdgeReference { .map(|edge| NavmeshEdgeReference {
from: NavvertexIndex(edge.source()), from: NavnodeIndex(edge.source()),
to: NavvertexIndex(edge.target()), to: NavnodeIndex(edge.target()),
}), }),
) )
} }
@ -437,8 +438,8 @@ impl<'a> IntoEdges for &'a Navmesh {
self.graph self.graph
.edges(vertex.petgraph_index()) .edges(vertex.petgraph_index())
.map(|edge| NavmeshEdgeReference { .map(|edge| NavmeshEdgeReference {
from: NavvertexIndex(edge.source()), from: NavnodeIndex(edge.source()),
to: NavvertexIndex(edge.target()), to: NavnodeIndex(edge.target()),
}), }),
) )
} }

View File

@ -49,14 +49,14 @@ impl RouteStepper {
width: f64, width: f64,
) -> Self { ) -> Self {
let source = navmesh.origin(); let source = navmesh.origin();
let source_navvertex = navmesh.origin_navvertex(); let source_navnode = navmesh.origin_navnode();
let target = navmesh.destination(); let target = navmesh.destination();
let layout = router.layout_mut(); 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 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 ghosts = vec![];
let obstacles = 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)), Ok(ControlFlow::Break((_cost, _path, band))) => Ok(ControlFlow::Break(band)),
Err(e) => { Err(e) => {
// NOTE(fogti): The 1 instead 0 is because the first element in the path // 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() { for _ in 1..self.navcord.path.len() {
self.navcord.step_back(layout); self.navcord.step_back(layout);
} }

View File

@ -29,7 +29,7 @@ use super::{
draw::DrawException, draw::DrawException,
navcord::Navcord, navcord::Navcord,
navcorder::{Navcorder, NavcorderException}, navcorder::{Navcorder, NavcorderException},
navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavvertexIndex}, navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavnodeIndex},
route::RouteStepper, route::RouteStepper,
}; };
@ -65,12 +65,12 @@ impl<R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex> for RouterAst
fn is_goal( fn is_goal(
&mut self, &mut self,
navmesh: &Navmesh, navmesh: &Navmesh,
vertex: NavvertexIndex, vertex: NavnodeIndex,
tracker: &PathTracker<Navmesh>, tracker: &PathTracker<Navmesh>,
) -> Option<BandTermsegIndex> { ) -> Option<BandTermsegIndex> {
let new_path = tracker.reconstruct_path_to(vertex); let new_path = tracker.reconstruct_path_to(vertex);
if vertex == navmesh.destination_navvertex() { if vertex == navmesh.destination_navnode() {
self.layout self.layout
.rework_path(navmesh, self.navcord, &new_path[..new_path.len() - 1]) .rework_path(navmesh, self.navcord, &new_path[..new_path.len() - 1])
.unwrap(); .unwrap();
@ -137,7 +137,7 @@ impl<R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex> for RouterAst
self.navcord.step_back(self.layout); 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) let start_point = PrimitiveIndex::from(navmesh.node_weight(vertex).unwrap().node)
.primitive(self.layout.drawing()) .primitive(self.layout.drawing())
.shape() .shape()

View File

@ -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>, autorouter: &mut Autorouter<SpecctraMesadata>,
origin_pin: &str, origin_pin: &str,
destination_pin: &str, destination_pin: &str,

View File

@ -17,7 +17,7 @@ mod common;
#[test] #[test]
fn test_0603_breakout() { fn test_0603_breakout() {
let mut autorouter = common::load_design("tests/single_layer/0603_breakout/0603_breakout.dsn"); 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); let mut invoker = common::create_invoker_and_assert(autorouter);
common::replay_and_assert( common::replay_and_assert(
&mut invoker, &mut invoker,
@ -35,7 +35,7 @@ fn test_tht_diode_bridge_rectifier() {
let mut autorouter = common::load_design( let mut autorouter = common::load_design(
"tests/single_layer/tht_diode_bridge_rectifier/tht_diode_bridge_rectifier.dsn", "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); let mut invoker = common::create_invoker_and_assert(autorouter);
common::replay_and_assert( common::replay_and_assert(
&mut invoker, &mut invoker,
@ -71,7 +71,7 @@ fn test_4x_3rd_order_smd_lc_filters() {
let mut autorouter = common::load_design( let mut autorouter = common::load_design(
"tests/single_layer/4x_3rd_order_smd_lc_filters/4x_3rd_order_smd_lc_filters.dsn", "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); let mut invoker = common::create_invoker_and_assert(autorouter);
common::replay_and_assert( common::replay_and_assert(
&mut invoker, &mut invoker,
@ -92,7 +92,7 @@ fn test_tht_3pin_xlr_to_tht_3pin_xlr() {
let mut autorouter = common::load_design( let mut autorouter = common::load_design(
"tests/single_layer/tht_3pin_xlr_to_tht_3pin_xlr/tht_3pin_xlr_to_tht_3pin_xlr.dsn", "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); let mut invoker = common::create_invoker_and_assert(autorouter);
common::replay_and_assert( common::replay_and_assert(
&mut invoker, &mut invoker,