mirror of https://codeberg.org/topola/topola.git
feat(router/navmesh): Add not-yet-functional leap navnodes to navmesh
This commit is contained in:
parent
fe6a286e32
commit
260f2066cc
|
|
@ -274,9 +274,9 @@ impl Viewport {
|
|||
{
|
||||
from += match from_sense {
|
||||
RotationSense::Counterclockwise => {
|
||||
[0.0, 150.0].into()
|
||||
[0.0, 200.0].into()
|
||||
}
|
||||
RotationSense::Clockwise => [-0.0, -150.0].into(),
|
||||
RotationSense::Clockwise => [-0.0, -200.0].into(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -287,9 +287,9 @@ impl Viewport {
|
|||
{
|
||||
to += match to_sense {
|
||||
RotationSense::Counterclockwise => {
|
||||
[0.0, 150.0].into()
|
||||
[0.0, 200.0].into()
|
||||
}
|
||||
RotationSense::Clockwise => [-0.0, -150.0].into(),
|
||||
RotationSense::Clockwise => [-0.0, -200.0].into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,10 +139,10 @@ pub enum NavnodeWeight {
|
|||
|
||||
/// Navnode corresponding to a counterclockwise wrap around the layout node.
|
||||
CounterclockwiseStep(NavigableNodeIndex),
|
||||
/// Navnode corresponding to a leap between two step or terminal navnodes.
|
||||
Leap(NavigableNodeIndex),
|
||||
/// Navnode corresponding to a clockwise wrap around the layout node.
|
||||
ClockwiseStep(NavigableNodeIndex),
|
||||
/// Navnode corresponding to a leap between two step or terminal navnodes.
|
||||
//Leap(NavigableNodeIndex),
|
||||
|
||||
/// Unlike the others, origin and destination layout nodes each are assigned
|
||||
/// only one navnode, which we call the "terminal navnode".
|
||||
|
|
@ -154,6 +154,7 @@ impl NavnodeWeight {
|
|||
match self {
|
||||
NavnodeWeight::CounterclockwiseStep(node) => *node,
|
||||
NavnodeWeight::ClockwiseStep(node) => *node,
|
||||
NavnodeWeight::Leap(node) => *node,
|
||||
NavnodeWeight::Terminal(node) => *node,
|
||||
}
|
||||
}
|
||||
|
|
@ -162,6 +163,7 @@ impl NavnodeWeight {
|
|||
match self {
|
||||
NavnodeWeight::CounterclockwiseStep(..) => Some(RotationSense::Counterclockwise),
|
||||
NavnodeWeight::ClockwiseStep(..) => Some(RotationSense::Clockwise),
|
||||
NavnodeWeight::Leap(..) => None,
|
||||
NavnodeWeight::Terminal(..) => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +175,7 @@ pub enum NavmeshError {
|
|||
Insertion(#[from] InsertionError),
|
||||
}
|
||||
|
||||
/// The navmesh holds the entire Topola's search space represented as a graph.
|
||||
/// The navmesh holds the entire router's search space represented as a graph.
|
||||
/// Topola's routing works by navigating over this graph with a pathfinding
|
||||
/// algorithm such as A* while drawing a track segment (always a cane except
|
||||
/// when going directly to destination) on the layout for each leap and
|
||||
|
|
@ -251,12 +253,12 @@ impl Navmesh {
|
|||
let navnode = graph.add_node(NavnodeWeight::Terminal(trianvertex.into()));
|
||||
|
||||
origin_navnode = Some(navnode);
|
||||
map.insert(trianvertex, vec![(navnode, navnode)]);
|
||||
map.insert(trianvertex, vec![(navnode, navnode, navnode)]);
|
||||
} else if trianvertex == destination.into() {
|
||||
let navnode = graph.add_node(NavnodeWeight::Terminal(trianvertex.into()));
|
||||
|
||||
destination_navnode = Some(navnode);
|
||||
map.insert(trianvertex, vec![(navnode, navnode)]);
|
||||
map.insert(trianvertex, vec![(navnode, navnode, navnode)]);
|
||||
} else {
|
||||
map.insert(trianvertex, vec![]);
|
||||
|
||||
|
|
@ -264,7 +266,7 @@ impl Navmesh {
|
|||
Into::<GearIndex>::into(Into::<NavigableNodeIndex>::into(trianvertex));
|
||||
|
||||
if options.squeeze_through_under_bends {
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
Self::add_node_to_graph_and_map_as_trinavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -273,7 +275,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_binavnode(
|
||||
Self::add_node_to_graph_and_map_as_trinavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -290,14 +292,14 @@ impl Navmesh {
|
|||
gear = bend.into();
|
||||
}
|
||||
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
Self::add_node_to_graph_and_map_as_trinavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
bend.into(),
|
||||
);
|
||||
} else {
|
||||
Self::add_node_to_graph_and_map_as_binavnode(
|
||||
Self::add_node_to_graph_and_map_as_trinavnode(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
|
|
@ -308,12 +310,17 @@ impl Navmesh {
|
|||
}
|
||||
|
||||
for edge in triangulation.edge_references() {
|
||||
for (from_navnode1, from_navnode2) in map[&edge.source()].iter() {
|
||||
for (to_navnode1, to_navnode2) in map[&edge.target()].iter() {
|
||||
for (from_navnode1, from_navnode2, from_navnode3) in map[&edge.source()].iter() {
|
||||
for (to_navnode1, to_navnode2, to_navnode3) in map[&edge.target()].iter() {
|
||||
graph.update_edge(*from_navnode1, *to_navnode1, ());
|
||||
graph.update_edge(*from_navnode1, *to_navnode2, ());
|
||||
graph.update_edge(*from_navnode1, *to_navnode3, ());
|
||||
graph.update_edge(*from_navnode2, *to_navnode1, ());
|
||||
graph.update_edge(*from_navnode2, *to_navnode2, ());
|
||||
graph.update_edge(*from_navnode2, *to_navnode3, ());
|
||||
graph.update_edge(*from_navnode3, *to_navnode1, ());
|
||||
graph.update_edge(*from_navnode3, *to_navnode2, ());
|
||||
graph.update_edge(*from_navnode3, *to_navnode3, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -327,18 +334,22 @@ impl Navmesh {
|
|||
})
|
||||
}
|
||||
|
||||
fn add_node_to_graph_and_map_as_binavnode(
|
||||
fn add_node_to_graph_and_map_as_trinavnode(
|
||||
graph: &mut UnGraph<NavnodeWeight, (), usize>,
|
||||
map: &mut BTreeMap<TrianvertexNodeIndex, Vec<(NodeIndex<usize>, NodeIndex<usize>)>>,
|
||||
map: &mut BTreeMap<
|
||||
TrianvertexNodeIndex,
|
||||
Vec<(NodeIndex<usize>, NodeIndex<usize>, NodeIndex<usize>)>,
|
||||
>,
|
||||
trianvertex: TrianvertexNodeIndex,
|
||||
node: NavigableNodeIndex,
|
||||
) {
|
||||
let navnode1 = graph.add_node(NavnodeWeight::CounterclockwiseStep(node));
|
||||
let navnode2 = graph.add_node(NavnodeWeight::ClockwiseStep(node));
|
||||
let navnode2 = graph.add_node(NavnodeWeight::Leap(node));
|
||||
let navnode3 = graph.add_node(NavnodeWeight::ClockwiseStep(node));
|
||||
|
||||
map.get_mut(&trianvertex)
|
||||
.unwrap()
|
||||
.push((navnode1, navnode2));
|
||||
.push((navnode1, navnode2, navnode3));
|
||||
}
|
||||
|
||||
/// Returns the navmesh's underlying petgraph graph structure.
|
||||
|
|
|
|||
Loading…
Reference in New Issue