mirror of https://codeberg.org/topola/topola.git
router: have a binavvertex on each bend
This commit is contained in:
parent
59f88e854c
commit
4d0c38664e
|
|
@ -94,13 +94,13 @@ impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus, AutorouterErro
|
|||
}
|
||||
AutorouteStatus::Finished => {
|
||||
if let Some(next_autoroute) = self.next_autoroute.take() {
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline1, self.ratline2]);
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline1, self.ratline2])?;
|
||||
self.autoroute = next_autoroute;
|
||||
|
||||
Ok(CompareDetoursStatus::Running)
|
||||
} else {
|
||||
self.done = true;
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1]);
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1])?;
|
||||
|
||||
Ok(CompareDetoursStatus::Finished(
|
||||
self.total_length1,
|
||||
|
|
|
|||
|
|
@ -149,7 +149,6 @@ impl Top {
|
|||
place_via.toggle_widget(ctx, ui, &mut self.is_placing_via);
|
||||
|
||||
remove_bands.button(ctx, ui);
|
||||
measure_length.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
|
|
|
|||
|
|
@ -99,10 +99,10 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
|||
let mut v = vec![];
|
||||
let mut gear = around;
|
||||
|
||||
while let Some(outer) = gear.ref_(self.drawing).next_gear() {
|
||||
let primitive = self.drawing.primitive(outer);
|
||||
while let Some(bend) = gear.ref_(self.drawing).next_gear() {
|
||||
let primitive = self.drawing.primitive(bend);
|
||||
|
||||
v.push(outer.into());
|
||||
v.push(bend.into());
|
||||
|
||||
let joints = primitive.joints();
|
||||
v.push(joints.0.into());
|
||||
|
|
@ -111,7 +111,7 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
|||
v.push(self.drawing.primitive(joints.0).seg().unwrap().into());
|
||||
v.push(self.drawing.primitive(joints.1).seg().unwrap().into());
|
||||
|
||||
gear = outer.into();
|
||||
gear = bend.into();
|
||||
}
|
||||
|
||||
v
|
||||
|
|
|
|||
|
|
@ -285,8 +285,8 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
}
|
||||
//
|
||||
if let Some(next_gear) = around.ref_(self).next_gear() {
|
||||
if let Some(wraparound_net) = next_gear.primitive(self).maybe_net() {
|
||||
if net == wraparound_net {
|
||||
if let Some(next_gear_net) = next_gear.primitive(self).maybe_net() {
|
||||
if net == next_gear_net {
|
||||
return Err(AlreadyConnected(net, next_gear.into()).into());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@ use crate::{
|
|||
drawing::{
|
||||
bend::{FixedBendIndex, LooseBendIndex},
|
||||
dot::FixedDotIndex,
|
||||
gear::{GearIndex, GetNextGear},
|
||||
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex},
|
||||
primitive::{MakePrimitiveShape, Primitive},
|
||||
rules::AccessRules,
|
||||
Drawing,
|
||||
},
|
||||
geometry::shape::AccessShape,
|
||||
graph::GetPetgraphIndex,
|
||||
graph::{GetPetgraphIndex, MakeRef},
|
||||
layout::Layout,
|
||||
router::astar::MakeEdgeRef,
|
||||
triangulation::{GetTrianvertexNodeIndex, Triangulation},
|
||||
|
|
@ -57,6 +58,16 @@ impl From<BinavvertexNodeIndex> for PrimitiveIndex {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BinavvertexNodeIndex> for GearIndex {
|
||||
fn from(vertex: BinavvertexNodeIndex) -> Self {
|
||||
match vertex {
|
||||
BinavvertexNodeIndex::FixedDot(dot) => GearIndex::FixedDot(dot),
|
||||
BinavvertexNodeIndex::FixedBend(bend) => GearIndex::FixedBend(bend),
|
||||
BinavvertexNodeIndex::LooseBend(bend) => GearIndex::LooseBend(bend),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[enum_dispatch(GetPetgraphIndex, MakePrimitive)]
|
||||
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
||||
enum TrianvertexNodeIndex {
|
||||
|
|
@ -152,10 +163,11 @@ impl Navmesh {
|
|||
}
|
||||
}
|
||||
|
||||
Self::new_from_triangulation(triangulation, origin, destination)
|
||||
Self::new_from_triangulation(layout, triangulation, origin, destination)
|
||||
}
|
||||
|
||||
fn new_from_triangulation(
|
||||
layout: &Layout<impl AccessRules>,
|
||||
triangulation: Triangulation<TrianvertexNodeIndex, TrianvertexWeight, ()>,
|
||||
origin: FixedDotIndex,
|
||||
destination: FixedDotIndex,
|
||||
|
|
@ -168,14 +180,14 @@ impl Navmesh {
|
|||
let mut map = HashMap::new();
|
||||
|
||||
for trianvertex in triangulation.node_identifiers() {
|
||||
let binavvertex = if trianvertex == origin.into() {
|
||||
if trianvertex == origin.into() {
|
||||
let navvertex = graph.add_node(NavvertexWeight {
|
||||
node: trianvertex.into(),
|
||||
maybe_cw: None,
|
||||
});
|
||||
|
||||
origin_navvertex = Some(navvertex);
|
||||
vec![(navvertex, navvertex)]
|
||||
map.insert(trianvertex, vec![(navvertex, navvertex)]);
|
||||
} else if trianvertex == destination.into() {
|
||||
let navvertex = graph.add_node(NavvertexWeight {
|
||||
node: trianvertex.into(),
|
||||
|
|
@ -183,22 +195,29 @@ impl Navmesh {
|
|||
});
|
||||
|
||||
destination_navvertex = Some(navvertex);
|
||||
vec![(navvertex, navvertex)]
|
||||
map.insert(trianvertex, vec![(navvertex, navvertex)]);
|
||||
} else {
|
||||
let navvertex1 = graph.add_node(NavvertexWeight {
|
||||
node: trianvertex.into(),
|
||||
maybe_cw: Some(false),
|
||||
});
|
||||
map.insert(trianvertex, vec![]);
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
trianvertex.into(),
|
||||
);
|
||||
|
||||
let navvertex2 = graph.add_node(NavvertexWeight {
|
||||
node: trianvertex.into(),
|
||||
maybe_cw: Some(true),
|
||||
});
|
||||
let mut gear =
|
||||
Into::<GearIndex>::into(Into::<BinavvertexNodeIndex>::into(trianvertex));
|
||||
|
||||
vec![(navvertex1, navvertex2)]
|
||||
while let Some(bend) = gear.ref_(layout.drawing()).next_gear() {
|
||||
Self::add_node_to_graph_and_map_as_binavvertex(
|
||||
&mut graph,
|
||||
&mut map,
|
||||
trianvertex,
|
||||
bend.into(),
|
||||
);
|
||||
gear = bend.into();
|
||||
}
|
||||
};
|
||||
|
||||
map.insert(trianvertex, binavvertex);
|
||||
}
|
||||
|
||||
for edge in triangulation.edge_references() {
|
||||
|
|
@ -221,6 +240,27 @@ impl Navmesh {
|
|||
})
|
||||
}
|
||||
|
||||
fn add_node_to_graph_and_map_as_binavvertex(
|
||||
graph: &mut UnGraph<NavvertexWeight, (), usize>,
|
||||
map: &mut HashMap<TrianvertexNodeIndex, Vec<(NodeIndex<usize>, NodeIndex<usize>)>>,
|
||||
trianvertex: TrianvertexNodeIndex,
|
||||
node: BinavvertexNodeIndex,
|
||||
) {
|
||||
let navvertex1 = graph.add_node(NavvertexWeight {
|
||||
node,
|
||||
maybe_cw: Some(false),
|
||||
});
|
||||
|
||||
let navvertex2 = graph.add_node(NavvertexWeight {
|
||||
node,
|
||||
maybe_cw: Some(true),
|
||||
});
|
||||
|
||||
map.get_mut(&trianvertex)
|
||||
.unwrap()
|
||||
.push((navvertex1, navvertex2));
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &UnGraph<NavvertexWeight, (), usize> {
|
||||
&self.graph
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue