mirror of https://codeberg.org/topola/topola.git
autorouter,router: shorten and clarify terminology
Rename "triangulation vertex" to just "trianvertex". Rename "navigation vertex" to just "navvertex". The standalone word "vertex" was overused and in some cases confusing.
This commit is contained in:
parent
02a5e13e23
commit
a80dfc10be
|
|
@ -15,7 +15,7 @@ use thiserror::Error;
|
|||
use crate::{
|
||||
autorouter::{
|
||||
board::Board,
|
||||
ratsnest::{Ratsnest, RatsnestVertexIndex},
|
||||
ratsnest::{Ratsnest, RatvertexIndex},
|
||||
selection::Selection,
|
||||
},
|
||||
drawing::{
|
||||
|
|
@ -28,7 +28,7 @@ use crate::{
|
|||
navmesh::{Navmesh, NavmeshError},
|
||||
Router, RouterError, RouterObserverTrait,
|
||||
},
|
||||
triangulation::GetVertexIndex,
|
||||
triangulation::GetTrianvertexIndex,
|
||||
};
|
||||
|
||||
#[derive(Error, Debug, Clone)]
|
||||
|
|
@ -180,10 +180,10 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
.graph()
|
||||
.node_weight(source)
|
||||
.unwrap()
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
{
|
||||
RatsnestVertexIndex::FixedDot(dot) => dot,
|
||||
RatsnestVertexIndex::Zone(zone) => self.board.layout_mut().zone_apex(zone),
|
||||
RatvertexIndex::FixedDot(dot) => dot,
|
||||
RatvertexIndex::Zone(zone) => self.board.layout_mut().zone_apex(zone),
|
||||
};
|
||||
|
||||
let target_dot = match self
|
||||
|
|
@ -191,10 +191,10 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
.graph()
|
||||
.node_weight(target)
|
||||
.unwrap()
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
{
|
||||
RatsnestVertexIndex::FixedDot(dot) => dot,
|
||||
RatsnestVertexIndex::Zone(zone) => self.board.layout_mut().zone_apex(zone),
|
||||
RatvertexIndex::FixedDot(dot) => dot,
|
||||
RatvertexIndex::Zone(zone) => self.board.layout_mut().zone_apex(zone),
|
||||
};
|
||||
|
||||
(source_dot, target_dot)
|
||||
|
|
@ -212,13 +212,13 @@ impl<R: RulesTrait> Autorouter<R> {
|
|||
.graph()
|
||||
.node_weight(source)
|
||||
.unwrap()
|
||||
.vertex_index();
|
||||
.trianvertex_index();
|
||||
let to_vertex = self
|
||||
.ratsnest
|
||||
.graph()
|
||||
.node_weight(target)
|
||||
.unwrap()
|
||||
.vertex_index();
|
||||
.trianvertex_index();
|
||||
|
||||
selection.contains_node(&self.board, source_vertex.into())
|
||||
&& selection.contains_node(&self.board, to_vertex.into())
|
||||
|
|
|
|||
|
|
@ -24,38 +24,38 @@ use crate::{
|
|||
zone::{MakePolyShape, ZoneWeight},
|
||||
Layout,
|
||||
},
|
||||
triangulation::{GetVertexIndex, Triangulation},
|
||||
triangulation::{GetTrianvertexIndex, Triangulation},
|
||||
};
|
||||
|
||||
#[enum_dispatch(GetNodeIndex)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum RatsnestVertexIndex {
|
||||
pub enum RatvertexIndex {
|
||||
FixedDot(FixedDotIndex),
|
||||
Zone(GenericIndex<ZoneWeight>),
|
||||
}
|
||||
|
||||
impl From<RatsnestVertexIndex> for crate::layout::NodeIndex {
|
||||
fn from(vertex: RatsnestVertexIndex) -> crate::layout::NodeIndex {
|
||||
impl From<RatvertexIndex> for crate::layout::NodeIndex {
|
||||
fn from(vertex: RatvertexIndex) -> crate::layout::NodeIndex {
|
||||
match vertex {
|
||||
RatsnestVertexIndex::FixedDot(dot) => crate::layout::NodeIndex::Primitive(dot.into()),
|
||||
RatsnestVertexIndex::Zone(zone) => crate::layout::NodeIndex::Compound(zone.into()),
|
||||
RatvertexIndex::FixedDot(dot) => crate::layout::NodeIndex::Primitive(dot.into()),
|
||||
RatvertexIndex::Zone(zone) => crate::layout::NodeIndex::Compound(zone.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct VertexWeight {
|
||||
vertex: RatsnestVertexIndex,
|
||||
pub struct RatvertexWeight {
|
||||
vertex: RatvertexIndex,
|
||||
pub pos: Point,
|
||||
}
|
||||
|
||||
impl GetVertexIndex<RatsnestVertexIndex> for VertexWeight {
|
||||
fn vertex_index(&self) -> RatsnestVertexIndex {
|
||||
impl GetTrianvertexIndex<RatvertexIndex> for RatvertexWeight {
|
||||
fn trianvertex_index(&self) -> RatvertexIndex {
|
||||
self.vertex
|
||||
}
|
||||
}
|
||||
|
||||
impl HasPosition for VertexWeight {
|
||||
impl HasPosition for RatvertexWeight {
|
||||
type Scalar = f64;
|
||||
fn position(&self) -> Point2<Self::Scalar> {
|
||||
Point2::new(self.pos.x(), self.pos.y())
|
||||
|
|
@ -63,12 +63,12 @@ impl HasPosition for VertexWeight {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct EdgeWeight {
|
||||
pub struct RatlineWeight {
|
||||
pub band: Option<BandIndex>,
|
||||
}
|
||||
|
||||
pub struct Ratsnest {
|
||||
graph: UnGraph<VertexWeight, EdgeWeight, usize>,
|
||||
graph: UnGraph<RatvertexWeight, RatlineWeight, usize>,
|
||||
}
|
||||
|
||||
impl Ratsnest {
|
||||
|
|
@ -101,8 +101,8 @@ impl Ratsnest {
|
|||
}
|
||||
|
||||
triangulations.get_mut(&(layer, net)).unwrap().add_vertex(
|
||||
VertexWeight {
|
||||
vertex: RatsnestVertexIndex::FixedDot(dot),
|
||||
RatvertexWeight {
|
||||
vertex: RatvertexIndex::FixedDot(dot),
|
||||
pos: node.primitive(layout.drawing()).shape().center(),
|
||||
},
|
||||
)?;
|
||||
|
|
@ -125,8 +125,8 @@ impl Ratsnest {
|
|||
triangulations
|
||||
.get_mut(&(layer, net))
|
||||
.unwrap()
|
||||
.add_vertex(VertexWeight {
|
||||
vertex: RatsnestVertexIndex::Zone(zone),
|
||||
.add_vertex(RatvertexWeight {
|
||||
vertex: RatvertexIndex::Zone(zone),
|
||||
pos: layout.zone(zone).shape().center(),
|
||||
})?
|
||||
}
|
||||
|
|
@ -154,8 +154,16 @@ impl Ratsnest {
|
|||
|
||||
this.graph.retain_edges(|g, i| {
|
||||
if let Some((source, target)) = g.edge_endpoints(i) {
|
||||
let source_index = g.node_weight(source).unwrap().vertex_index().node_index();
|
||||
let target_index = g.node_weight(target).unwrap().vertex_index().node_index();
|
||||
let source_index = g
|
||||
.node_weight(source)
|
||||
.unwrap()
|
||||
.trianvertex_index()
|
||||
.node_index();
|
||||
let target_index = g
|
||||
.node_weight(target)
|
||||
.unwrap()
|
||||
.trianvertex_index()
|
||||
.node_index();
|
||||
!unionfind.equiv(source_index, target_index)
|
||||
} else {
|
||||
true
|
||||
|
|
@ -169,7 +177,7 @@ impl Ratsnest {
|
|||
self.graph.edge_weight_mut(ratline).unwrap().band = Some(band);
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &UnGraph<VertexWeight, EdgeWeight, usize> {
|
||||
pub fn graph(&self) -> &UnGraph<RatvertexWeight, RatlineWeight, usize> {
|
||||
&self.graph
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ use topola::{
|
|||
math::Circle,
|
||||
router::{
|
||||
draw::DrawException,
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, VertexIndex},
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, NavvertexIndex},
|
||||
tracer::{Trace, Tracer},
|
||||
EmptyRouterObserver, RouterObserverTrait,
|
||||
},
|
||||
|
|
@ -46,7 +46,7 @@ struct SharedData {
|
|||
pub from: Option<FixedDotIndex>,
|
||||
pub to: Option<FixedDotIndex>,
|
||||
pub navmesh: Option<Navmesh>,
|
||||
pub path: Vec<VertexIndex>,
|
||||
pub path: Vec<NavvertexIndex>,
|
||||
pub ghosts: Vec<PrimitiveShape>,
|
||||
pub highlighteds: Vec<PrimitiveIndex>,
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ impl<R: RulesTrait + std::fmt::Debug> RouterObserverTrait<R> for DebugRouterObse
|
|||
shared_data.highlighteds = highlighteds;
|
||||
std::thread::sleep_ms(delay);
|
||||
}
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: VertexIndex) {
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: NavvertexIndex) {
|
||||
//dbg!(_tracer, _vertex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use topola::geometry::shape::ShapeTrait;
|
|||
use topola::layout::zone::MakePolyShape;
|
||||
use topola::layout::Layout;
|
||||
use topola::router::draw::DrawException;
|
||||
use topola::router::navmesh::{Navmesh, NavmeshEdgeReference, VertexIndex};
|
||||
use topola::router::navmesh::{Navmesh, NavmeshEdgeReference, NavvertexIndex};
|
||||
use topola::router::tracer::{Trace, Tracer};
|
||||
use topola::router::RouterObserverTrait;
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ impl<'a, R: RulesTrait> RouterObserverTrait<R> for DebugRouterObserver<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: VertexIndex) {}
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: NavvertexIndex) {}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
|
|
@ -353,7 +353,7 @@ fn render_times(
|
|||
mut router_or_layout: RouterOrLayout<impl RulesTrait>,
|
||||
_unused: Option<()>,
|
||||
mut maybe_navmesh: Option<Navmesh>,
|
||||
path: &[VertexIndex],
|
||||
path: &[NavvertexIndex],
|
||||
ghosts: &[PrimitiveShape],
|
||||
highlighteds: &[PrimitiveIndex],
|
||||
times: i64,
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ use crate::{
|
|||
},
|
||||
graph::GetNodeIndex,
|
||||
layout::Layout,
|
||||
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
|
||||
triangulation::{GetTrianvertexIndex, Triangulation, TriangulationEdgeReference},
|
||||
};
|
||||
|
||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum VertexIndex {
|
||||
pub enum NavvertexIndex {
|
||||
FixedDot(FixedDotIndex),
|
||||
FixedBend(FixedBendIndex),
|
||||
LooseBend(LooseBendIndex),
|
||||
|
|
@ -34,44 +34,44 @@ pub enum VertexIndex {
|
|||
|
||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
||||
enum TriangulationVertexIndex {
|
||||
enum TrianvertexIndex {
|
||||
FixedDot(FixedDotIndex),
|
||||
FixedBend(FixedBendIndex),
|
||||
}
|
||||
|
||||
impl From<VertexIndex> for PrimitiveIndex {
|
||||
fn from(vertex: VertexIndex) -> Self {
|
||||
impl From<NavvertexIndex> for PrimitiveIndex {
|
||||
fn from(vertex: NavvertexIndex) -> Self {
|
||||
match vertex {
|
||||
VertexIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||
VertexIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||
VertexIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||
NavvertexIndex::FixedDot(dot) => PrimitiveIndex::FixedDot(dot),
|
||||
NavvertexIndex::FixedBend(bend) => PrimitiveIndex::FixedBend(bend),
|
||||
NavvertexIndex::LooseBend(bend) => PrimitiveIndex::LooseBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TriangulationVertexIndex> for VertexIndex {
|
||||
fn from(vertex: TriangulationVertexIndex) -> Self {
|
||||
impl From<TrianvertexIndex> for NavvertexIndex {
|
||||
fn from(vertex: TrianvertexIndex) -> Self {
|
||||
match vertex {
|
||||
TriangulationVertexIndex::FixedDot(dot) => VertexIndex::FixedDot(dot),
|
||||
TriangulationVertexIndex::FixedBend(bend) => VertexIndex::FixedBend(bend),
|
||||
TrianvertexIndex::FixedDot(dot) => NavvertexIndex::FixedDot(dot),
|
||||
TrianvertexIndex::FixedBend(bend) => NavvertexIndex::FixedBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct TriangulationVertexWeight {
|
||||
vertex: TriangulationVertexIndex,
|
||||
struct TrianvertexWeight {
|
||||
trianvertex: TrianvertexIndex,
|
||||
rails: Vec<LooseBendIndex>,
|
||||
pos: Point,
|
||||
}
|
||||
|
||||
impl GetVertexIndex<TriangulationVertexIndex> for TriangulationVertexWeight {
|
||||
fn vertex_index(&self) -> TriangulationVertexIndex {
|
||||
self.vertex
|
||||
impl GetTrianvertexIndex<TrianvertexIndex> for TrianvertexWeight {
|
||||
fn trianvertex_index(&self) -> TrianvertexIndex {
|
||||
self.trianvertex
|
||||
}
|
||||
}
|
||||
|
||||
impl HasPosition for TriangulationVertexWeight {
|
||||
impl HasPosition for TrianvertexWeight {
|
||||
type Scalar = f64;
|
||||
fn position(&self) -> Point2<Self::Scalar> {
|
||||
Point2::new(self.pos.x(), self.pos.y())
|
||||
|
|
@ -80,8 +80,8 @@ impl HasPosition for TriangulationVertexWeight {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Navmesh {
|
||||
triangulation: Triangulation<TriangulationVertexIndex, TriangulationVertexWeight, ()>,
|
||||
vertex_to_triangulation_vertex: Vec<Option<TriangulationVertexIndex>>,
|
||||
triangulation: Triangulation<TrianvertexIndex, TrianvertexWeight, ()>,
|
||||
navvertex_to_trianvertex: Vec<Option<TrianvertexIndex>>,
|
||||
from: FixedDotIndex,
|
||||
to: FixedDotIndex,
|
||||
}
|
||||
|
|
@ -100,11 +100,11 @@ impl Navmesh {
|
|||
) -> Result<Self, NavmeshError> {
|
||||
let mut this = Self {
|
||||
triangulation: Triangulation::new(layout.drawing().geometry().graph().node_bound()),
|
||||
vertex_to_triangulation_vertex: Vec::new(),
|
||||
navvertex_to_trianvertex: Vec::new(),
|
||||
from,
|
||||
to,
|
||||
};
|
||||
this.vertex_to_triangulation_vertex
|
||||
this.navvertex_to_trianvertex
|
||||
.resize(layout.drawing().geometry().graph().node_bound(), None);
|
||||
|
||||
let layer = layout.drawing().primitive(from).layer();
|
||||
|
|
@ -117,15 +117,15 @@ impl Navmesh {
|
|||
if node == from.into() || node == to.into() || Some(primitive_net) != maybe_net {
|
||||
match node {
|
||||
PrimitiveIndex::FixedDot(dot) => {
|
||||
this.triangulation.add_vertex(TriangulationVertexWeight {
|
||||
vertex: dot.into(),
|
||||
this.triangulation.add_vertex(TrianvertexWeight {
|
||||
trianvertex: dot.into(),
|
||||
rails: vec![],
|
||||
pos: primitive.shape().center(),
|
||||
})?;
|
||||
}
|
||||
PrimitiveIndex::FixedBend(bend) => {
|
||||
this.triangulation.add_vertex(TriangulationVertexWeight {
|
||||
vertex: bend.into(),
|
||||
this.triangulation.add_vertex(TrianvertexWeight {
|
||||
trianvertex: bend.into(),
|
||||
rails: vec![],
|
||||
pos: primitive.shape().center(),
|
||||
})?;
|
||||
|
|
@ -144,7 +144,7 @@ impl Navmesh {
|
|||
.weight_mut(layout.drawing().primitive(bend).core().into())
|
||||
.rails
|
||||
.push(bend.into());
|
||||
this.vertex_to_triangulation_vertex[bend.node_index().index()] =
|
||||
this.navvertex_to_trianvertex[bend.node_index().index()] =
|
||||
Some(layout.drawing().primitive(bend).core().into());
|
||||
}
|
||||
_ => (),
|
||||
|
|
@ -154,12 +154,12 @@ impl Navmesh {
|
|||
Ok(this)
|
||||
}
|
||||
|
||||
fn triangulation_vertex(&self, vertex: VertexIndex) -> TriangulationVertexIndex {
|
||||
fn triangulation_vertex(&self, vertex: NavvertexIndex) -> TrianvertexIndex {
|
||||
match vertex {
|
||||
VertexIndex::FixedDot(dot) => TriangulationVertexIndex::FixedDot(dot),
|
||||
VertexIndex::FixedBend(bend) => TriangulationVertexIndex::FixedBend(bend),
|
||||
VertexIndex::LooseBend(bend) => {
|
||||
self.vertex_to_triangulation_vertex[bend.node_index().index()].unwrap()
|
||||
NavvertexIndex::FixedDot(dot) => TrianvertexIndex::FixedDot(dot),
|
||||
NavvertexIndex::FixedBend(bend) => TrianvertexIndex::FixedBend(bend),
|
||||
NavvertexIndex::LooseBend(bend) => {
|
||||
self.navvertex_to_trianvertex[bend.node_index().index()].unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -174,8 +174,8 @@ impl Navmesh {
|
|||
}
|
||||
|
||||
impl visit::GraphBase for Navmesh {
|
||||
type NodeId = VertexIndex;
|
||||
type EdgeId = (VertexIndex, VertexIndex);
|
||||
type NodeId = NavvertexIndex;
|
||||
type EdgeId = (NavvertexIndex, NavvertexIndex);
|
||||
}
|
||||
|
||||
impl visit::Data for Navmesh {
|
||||
|
|
@ -185,13 +185,13 @@ impl visit::Data for Navmesh {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NavmeshEdgeReference {
|
||||
from: VertexIndex,
|
||||
to: VertexIndex,
|
||||
from: NavvertexIndex,
|
||||
to: NavvertexIndex,
|
||||
}
|
||||
|
||||
impl visit::EdgeRef for NavmeshEdgeReference {
|
||||
type NodeId = VertexIndex;
|
||||
type EdgeId = (VertexIndex, VertexIndex);
|
||||
type NodeId = NavvertexIndex;
|
||||
type EdgeId = (NavvertexIndex, NavvertexIndex);
|
||||
type Weight = ();
|
||||
|
||||
fn source(&self) -> Self::NodeId {
|
||||
|
|
@ -212,7 +212,7 @@ impl visit::EdgeRef for NavmeshEdgeReference {
|
|||
}
|
||||
|
||||
impl<'a> visit::IntoNeighbors for &'a Navmesh {
|
||||
type Neighbors = Box<dyn Iterator<Item = VertexIndex> + 'a>;
|
||||
type Neighbors = Box<dyn Iterator<Item = NavvertexIndex> + 'a>;
|
||||
|
||||
fn neighbors(self, vertex: Self::NodeId) -> Self::Neighbors {
|
||||
Box::new(
|
||||
|
|
@ -224,7 +224,7 @@ impl<'a> visit::IntoNeighbors for &'a Navmesh {
|
|||
.weight(neighbor)
|
||||
.rails
|
||||
.iter()
|
||||
.map(|index| VertexIndex::from(*index)),
|
||||
.map(|index| NavvertexIndex::from(*index)),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
|
@ -232,8 +232,8 @@ impl<'a> visit::IntoNeighbors for &'a Navmesh {
|
|||
}
|
||||
|
||||
fn edge_with_near_edges(
|
||||
triangulation: &Triangulation<TriangulationVertexIndex, TriangulationVertexWeight, ()>,
|
||||
edge: TriangulationEdgeReference<TriangulationVertexIndex, ()>,
|
||||
triangulation: &Triangulation<TrianvertexIndex, TrianvertexWeight, ()>,
|
||||
edge: TriangulationEdgeReference<TrianvertexIndex, ()>,
|
||||
) -> impl Iterator<Item = NavmeshEdgeReference> {
|
||||
let mut from_vertices = vec![edge.source().into()];
|
||||
|
||||
|
|
@ -243,7 +243,7 @@ fn edge_with_near_edges(
|
|||
.weight(edge.source())
|
||||
.rails
|
||||
.iter()
|
||||
.map(|bend| VertexIndex::from(*bend)),
|
||||
.map(|bend| NavvertexIndex::from(*bend)),
|
||||
);
|
||||
|
||||
let mut to_vertices = vec![edge.target().into()];
|
||||
|
|
@ -254,7 +254,7 @@ fn edge_with_near_edges(
|
|||
.weight(edge.target())
|
||||
.rails
|
||||
.iter()
|
||||
.map(|bend| VertexIndex::from(*bend)),
|
||||
.map(|bend| NavvertexIndex::from(*bend)),
|
||||
);
|
||||
|
||||
// Return cartesian product.
|
||||
|
|
@ -281,9 +281,9 @@ impl<'a> visit::IntoEdgeReferences for &'a Navmesh {
|
|||
}
|
||||
|
||||
fn vertex_edges(
|
||||
triangulation: &Triangulation<TriangulationVertexIndex, TriangulationVertexWeight, ()>,
|
||||
from: VertexIndex,
|
||||
to: TriangulationVertexIndex,
|
||||
triangulation: &Triangulation<TrianvertexIndex, TrianvertexWeight, ()>,
|
||||
from: NavvertexIndex,
|
||||
to: TrianvertexIndex,
|
||||
) -> impl Iterator<Item = NavmeshEdgeReference> {
|
||||
let from_vertices = vec![from];
|
||||
let mut to_vertices = vec![to.into()];
|
||||
|
|
@ -294,7 +294,7 @@ fn vertex_edges(
|
|||
.weight(to)
|
||||
.rails
|
||||
.iter()
|
||||
.map(|bend| VertexIndex::from(*bend)),
|
||||
.map(|bend| NavvertexIndex::from(*bend)),
|
||||
);
|
||||
|
||||
// Return cartesian product.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use crate::{
|
|||
router::{
|
||||
astar::{astar, AstarError, AstarStrategy, PathTracker},
|
||||
draw::DrawException,
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, VertexIndex},
|
||||
navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavvertexIndex},
|
||||
tracer::{Trace, Tracer},
|
||||
},
|
||||
};
|
||||
|
|
@ -42,7 +42,7 @@ pub trait RouterObserverTrait<R: RulesTrait> {
|
|||
edge: NavmeshEdgeReference,
|
||||
result: Result<(), DrawException>,
|
||||
);
|
||||
fn on_estimate(&mut self, tracer: &Tracer<R>, vertex: VertexIndex);
|
||||
fn on_estimate(&mut self, tracer: &Tracer<R>, vertex: NavvertexIndex);
|
||||
}
|
||||
|
||||
pub struct EmptyRouterObserver;
|
||||
|
|
@ -58,7 +58,7 @@ impl<R: RulesTrait> RouterObserverTrait<R> for EmptyRouterObserver {
|
|||
_result: Result<(), DrawException>,
|
||||
) {
|
||||
}
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: VertexIndex) {}
|
||||
fn on_estimate(&mut self, _tracer: &Tracer<R>, _vertex: NavvertexIndex) {}
|
||||
}
|
||||
|
||||
pub struct Router<'a, R: RulesTrait> {
|
||||
|
|
@ -94,7 +94,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Navmesh, f64,
|
|||
{
|
||||
fn is_goal(
|
||||
&mut self,
|
||||
vertex: VertexIndex,
|
||||
vertex: NavvertexIndex,
|
||||
tracker: &PathTracker<&Navmesh>,
|
||||
) -> Option<BandIndex> {
|
||||
let new_path = tracker.reconstruct_path_to(vertex);
|
||||
|
|
@ -131,7 +131,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Navmesh, f64,
|
|||
}
|
||||
}
|
||||
|
||||
fn estimate_cost(&mut self, vertex: VertexIndex) -> f64 {
|
||||
fn estimate_cost(&mut self, vertex: NavvertexIndex) -> f64 {
|
||||
self.observer.on_estimate(&self.tracer, vertex);
|
||||
|
||||
let start_point = PrimitiveIndex::from(vertex)
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ use crate::{
|
|||
layout::Layout,
|
||||
router::{
|
||||
draw::{Draw, DrawException},
|
||||
navmesh::{Navmesh, VertexIndex},
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Trace {
|
||||
pub path: Vec<VertexIndex>,
|
||||
pub path: Vec<NavvertexIndex>,
|
||||
pub head: Head,
|
||||
pub width: f64,
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
|||
pub fn rework_path(
|
||||
&mut self,
|
||||
trace: &mut Trace,
|
||||
path: &[VertexIndex],
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), DrawException> {
|
||||
let prefix_length = trace
|
||||
|
|
@ -74,7 +74,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
|||
pub fn path(
|
||||
&mut self,
|
||||
trace: &mut Trace,
|
||||
path: &[VertexIndex],
|
||||
path: &[NavvertexIndex],
|
||||
width: f64,
|
||||
) -> Result<(), DrawException> {
|
||||
for (i, vertex) in path.iter().enumerate() {
|
||||
|
|
@ -99,7 +99,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
|||
pub fn step(
|
||||
&mut self,
|
||||
trace: &mut Trace,
|
||||
to: VertexIndex,
|
||||
to: NavvertexIndex,
|
||||
width: f64,
|
||||
) -> Result<(), DrawException> {
|
||||
trace.head = self.wrap(trace.head, to, width)?.into();
|
||||
|
|
@ -111,13 +111,13 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
|
|||
fn wrap(
|
||||
&mut self,
|
||||
head: Head,
|
||||
around: VertexIndex,
|
||||
around: NavvertexIndex,
|
||||
width: f64,
|
||||
) -> Result<SegbendHead, DrawException> {
|
||||
match around {
|
||||
VertexIndex::FixedDot(dot) => self.wrap_around_fixed_dot(head, dot, width),
|
||||
VertexIndex::FixedBend(_fixed_bend) => todo!(),
|
||||
VertexIndex::LooseBend(loose_bend) => {
|
||||
NavvertexIndex::FixedDot(dot) => self.wrap_around_fixed_dot(head, dot, width),
|
||||
NavvertexIndex::FixedBend(_fixed_bend) => todo!(),
|
||||
NavvertexIndex::LooseBend(loose_bend) => {
|
||||
self.wrap_around_loose_bend(head, loose_bend, width)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,40 +6,40 @@ use spade::{handles::FixedVertexHandle, DelaunayTriangulation, HasPosition, Inse
|
|||
|
||||
use crate::graph::GetNodeIndex;
|
||||
|
||||
pub trait GetVertexIndex<I> {
|
||||
fn vertex_index(&self) -> I;
|
||||
pub trait GetTrianvertexIndex<I> {
|
||||
fn trianvertex_index(&self) -> I;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Triangulation<
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition,
|
||||
EW: Copy + Default,
|
||||
> {
|
||||
triangulation: DelaunayTriangulation<VW, EW>,
|
||||
vertex_to_handle: Vec<Option<FixedVertexHandle>>,
|
||||
trianvertex_to_handle: Vec<Option<FixedVertexHandle>>,
|
||||
index_marker: PhantomData<I>,
|
||||
}
|
||||
|
||||
impl<
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> Triangulation<I, VW, EW>
|
||||
{
|
||||
pub fn new(node_bound: usize) -> Self {
|
||||
let mut this = Self {
|
||||
triangulation: <DelaunayTriangulation<VW, EW> as spade::Triangulation>::new(),
|
||||
vertex_to_handle: Vec::new(),
|
||||
trianvertex_to_handle: Vec::new(),
|
||||
index_marker: PhantomData,
|
||||
};
|
||||
this.vertex_to_handle.resize(node_bound, None);
|
||||
this.trianvertex_to_handle.resize(node_bound, None);
|
||||
this
|
||||
}
|
||||
|
||||
pub fn add_vertex(&mut self, weight: VW) -> Result<(), InsertionError> {
|
||||
let index = weight.vertex_index().node_index().index();
|
||||
self.vertex_to_handle[index] = Some(spade::Triangulation::insert(
|
||||
let index = weight.trianvertex_index().node_index().index();
|
||||
self.trianvertex_to_handle[index] = Some(spade::Triangulation::insert(
|
||||
&mut self.triangulation,
|
||||
weight,
|
||||
)?);
|
||||
|
|
@ -48,13 +48,13 @@ impl<
|
|||
|
||||
pub fn weight(&self, vertex: I) -> &VW {
|
||||
spade::Triangulation::s(&self.triangulation)
|
||||
.vertex_data(self.vertex_to_handle[vertex.node_index().index()].unwrap())
|
||||
.vertex_data(self.trianvertex_to_handle[vertex.node_index().index()].unwrap())
|
||||
}
|
||||
|
||||
pub fn weight_mut(&mut self, vertex: I) -> &mut VW {
|
||||
spade::Triangulation::vertex_data_mut(
|
||||
&mut self.triangulation,
|
||||
self.vertex_to_handle[vertex.node_index().index()].unwrap(),
|
||||
self.trianvertex_to_handle[vertex.node_index().index()].unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -67,17 +67,17 @@ impl<
|
|||
fn vertex(&self, handle: FixedVertexHandle) -> I {
|
||||
spade::Triangulation::vertex(&self.triangulation, handle)
|
||||
.as_ref()
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
}
|
||||
|
||||
fn handle(&self, vertex: I) -> FixedVertexHandle {
|
||||
self.vertex_to_handle[vertex.node_index().index()].unwrap()
|
||||
self.trianvertex_to_handle[vertex.node_index().index()].unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::GraphBase for Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -105,7 +105,7 @@ impl<EW: Copy + Default> PartialOrd for TriangulationEdgeWeightWrapper<EW> {
|
|||
|
||||
impl<
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::Data for Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -145,7 +145,7 @@ impl<I: Copy, EW: Copy + Default> visit::EdgeRef for TriangulationEdgeReference<
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::IntoNeighbors for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -163,7 +163,7 @@ impl<
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::IntoEdgeReferences for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -192,7 +192,7 @@ impl<
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::IntoEdges for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -222,7 +222,7 @@ impl<
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::IntoNodeIdentifiers for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -233,7 +233,7 @@ impl<
|
|||
spade::Triangulation::fixed_vertices(&self.triangulation).map(|vertex| {
|
||||
spade::Triangulation::s(&self.triangulation)
|
||||
.vertex_data(vertex)
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ impl<'a, I: Copy, VW: Copy> visit::NodeRef for TriangulationVertexReference<'a,
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex,
|
||||
VW: Copy + GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: Copy + GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::IntoNodeReferences for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
|
|
@ -273,7 +273,7 @@ impl<
|
|||
spade::Triangulation::fixed_vertices(&self.triangulation).map(|vertex| {
|
||||
let weight = spade::Triangulation::s(&self.triangulation).vertex_data(vertex);
|
||||
TriangulationVertexReference {
|
||||
index: weight.vertex_index(),
|
||||
index: weight.trianvertex_index(),
|
||||
weight,
|
||||
}
|
||||
}),
|
||||
|
|
@ -284,13 +284,13 @@ impl<
|
|||
impl<
|
||||
'a,
|
||||
I: Copy + PartialEq + GetNodeIndex + std::fmt::Debug,
|
||||
VW: GetVertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
VW: GetTrianvertexIndex<I> + HasPosition<Scalar = f64>,
|
||||
EW: Copy + Default,
|
||||
> visit::NodeIndexable for &'a Triangulation<I, VW, EW>
|
||||
{
|
||||
fn node_bound(&self) -> usize {
|
||||
//spade::Triangulation::num_vertices(&self.triangulation)
|
||||
self.vertex_to_handle.len()
|
||||
self.trianvertex_to_handle.len()
|
||||
}
|
||||
|
||||
fn to_index(&self, node: I) -> usize {
|
||||
|
|
@ -299,7 +299,7 @@ impl<
|
|||
|
||||
fn from_index(&self, index: usize) -> I {
|
||||
spade::Triangulation::s(&self.triangulation)
|
||||
.vertex_data(self.vertex_to_handle[index].unwrap())
|
||||
.vertex_index()
|
||||
.vertex_data(self.trianvertex_to_handle[index].unwrap())
|
||||
.trianvertex_index()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use topola::{
|
|||
dsn::design::DsnDesign,
|
||||
graph::GetNodeIndex,
|
||||
router::EmptyRouterObserver,
|
||||
triangulation::GetVertexIndex,
|
||||
triangulation::GetTrianvertexIndex,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
|
@ -63,7 +63,7 @@ fn test() {
|
|||
.graph()
|
||||
.node_weight(ratline.source())
|
||||
.unwrap()
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
.node_index();
|
||||
let to_index = invoker
|
||||
.autorouter()
|
||||
|
|
@ -71,7 +71,7 @@ fn test() {
|
|||
.graph()
|
||||
.node_weight(ratline.target())
|
||||
.unwrap()
|
||||
.vertex_index()
|
||||
.trianvertex_index()
|
||||
.node_index();
|
||||
assert_eq!(unionfind.find(from_index), unionfind.find(to_index));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use topola::{
|
|||
drawing::graph::GetMaybeNet,
|
||||
dsn::design::DsnDesign,
|
||||
graph::GetNodeIndex,
|
||||
triangulation::GetVertexIndex,
|
||||
triangulation::GetTrianvertexIndex,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use topola::{
|
|||
drawing::graph::GetMaybeNet,
|
||||
dsn::design::DsnDesign,
|
||||
graph::GetNodeIndex,
|
||||
triangulation::GetVertexIndex,
|
||||
triangulation::GetTrianvertexIndex,
|
||||
};
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue