mirror of https://codeberg.org/topola/topola.git
layout: remove concepts of connectivity, bands, and continents for now
We'll use `UnionFind` where needed for now.
This commit is contained in:
parent
8a3bf45fd8
commit
4c6fa0e5d3
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
graph::{GetLayer, GetMaybeNet},
|
graph::{GetLayer, GetMaybeNet},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
layout::{connectivity::BandIndex, Layout, NodeIndex},
|
layout::{Layout, NodeIndex},
|
||||||
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
|
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
|
||||||
triangulation::GetVertexIndex,
|
triangulation::GetVertexIndex,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,7 @@ fn render_times(
|
||||||
font_context: &CanvasFontContext,
|
font_context: &CanvasFontContext,
|
||||||
view: &mut View,
|
view: &mut View,
|
||||||
mut router_or_layout: RouterOrLayout<impl RulesTrait>,
|
mut router_or_layout: RouterOrLayout<impl RulesTrait>,
|
||||||
maybe_band: Option<BandIndex>,
|
_unused: Option<()>,
|
||||||
mut maybe_navmesh: Option<Navmesh>,
|
mut maybe_navmesh: Option<Navmesh>,
|
||||||
path: &[VertexIndex],
|
path: &[VertexIndex],
|
||||||
ghosts: &[PrimitiveShape],
|
ghosts: &[PrimitiveShape],
|
||||||
|
|
@ -381,7 +381,7 @@ fn render_times(
|
||||||
RouterOrLayout::Router(ref mut router) => {
|
RouterOrLayout::Router(ref mut router) => {
|
||||||
let state = event_pump.mouse_state();
|
let state = event_pump.mouse_state();
|
||||||
|
|
||||||
if let Some(band) = maybe_band {
|
/*if let Some(band) = maybe_band {
|
||||||
router
|
router
|
||||||
.reroute_band(
|
.reroute_band(
|
||||||
band,
|
band,
|
||||||
|
|
@ -398,7 +398,7 @@ fn render_times(
|
||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
maybe_navmesh = None;
|
maybe_navmesh = None;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
router.layout().clone()
|
router.layout().clone()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ use crate::geometry::{
|
||||||
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
GetOffset, GetWidth,
|
GetOffset, GetWidth,
|
||||||
};
|
};
|
||||||
use crate::graph::{GenericIndex, GetNodeIndex};
|
|
||||||
use crate::layout::connectivity::{BandIndex, ContinentIndex};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
|
||||||
|
|
@ -21,6 +19,7 @@ use crate::{
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::GenericNode,
|
geometry::GenericNode,
|
||||||
|
graph::{GenericIndex, GetNodeIndex},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -249,36 +248,6 @@ where
|
||||||
pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>;
|
pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>;
|
||||||
impl_fixed_primitive!(FixedDot, FixedDotWeight);
|
impl_fixed_primitive!(FixedDot, FixedDotWeight);
|
||||||
|
|
||||||
impl<'a, CW: Copy, R: RulesTrait> FixedDot<'a, CW, R> {
|
|
||||||
pub fn first_loose(&self, _band: BandIndex) -> Option<LooseIndex> {
|
|
||||||
self.drawing
|
|
||||||
.geometry()
|
|
||||||
.joineds(self.index.into())
|
|
||||||
.into_iter()
|
|
||||||
.find_map(|ni| {
|
|
||||||
let weight = self
|
|
||||||
.drawing
|
|
||||||
.geometry()
|
|
||||||
.graph()
|
|
||||||
.node_weight(ni.node_index())
|
|
||||||
.unwrap();
|
|
||||||
if matches!(
|
|
||||||
weight,
|
|
||||||
GenericNode::Primitive(PrimitiveWeight::LoneLooseSeg(..))
|
|
||||||
) {
|
|
||||||
Some(LoneLooseSegIndex::new(ni.node_index()).into())
|
|
||||||
} else if matches!(
|
|
||||||
weight,
|
|
||||||
GenericNode::Primitive(PrimitiveWeight::SeqLooseSeg(..))
|
|
||||||
) {
|
|
||||||
Some(SeqLooseSegIndex::new(ni.node_index()).into())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedDot<'a, CW, R> {
|
impl<'a, CW: Copy, R: RulesTrait> MakePrimitiveShape for FixedDot<'a, CW, R> {
|
||||||
fn shape(&self) -> PrimitiveShape {
|
fn shape(&self) -> PrimitiveShape {
|
||||||
self.drawing.geometry().dot_shape(self.index.into())
|
self.drawing.geometry().dot_shape(self.index.into())
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
use enum_dispatch::enum_dispatch;
|
|
||||||
use petgraph::stable_graph::StableDiGraph;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
drawing::{dot::FixedDotIndex, graph::GetMaybeNet, primitive::Primitive, rules::RulesTrait},
|
|
||||||
graph::GenericIndex,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type ConnectivityGraph = StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum ConnectivityWeight {
|
|
||||||
Continent(ContinentWeight),
|
|
||||||
Band(BandWeight),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub struct ContinentWeight {
|
|
||||||
pub maybe_net: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetMaybeNet for ContinentWeight {
|
|
||||||
fn maybe_net(&self) -> Option<usize> {
|
|
||||||
self.maybe_net
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type ContinentIndex = GenericIndex<ContinentWeight>;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub struct BandWeight {
|
|
||||||
pub from: FixedDotIndex,
|
|
||||||
pub to: Option<FixedDotIndex>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type BandIndex = GenericIndex<BandWeight>;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum ConnectivityLabel {
|
|
||||||
Band,
|
|
||||||
}
|
|
||||||
|
|
@ -21,12 +21,7 @@ use crate::{
|
||||||
DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait,
|
DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait,
|
||||||
},
|
},
|
||||||
graph::{GenericIndex, GetNodeIndex},
|
graph::{GenericIndex, GetNodeIndex},
|
||||||
layout::{
|
layout::zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
|
||||||
connectivity::{
|
|
||||||
BandIndex, BandWeight, ConnectivityLabel, ConnectivityWeight, ContinentIndex,
|
|
||||||
},
|
|
||||||
zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
|
|
||||||
},
|
|
||||||
math::Circle,
|
math::Circle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -35,45 +30,17 @@ pub type NodeIndex = GenericNode<PrimitiveIndex, GenericIndex<ZoneWeight>>;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Layout<R: RulesTrait> {
|
pub struct Layout<R: RulesTrait> {
|
||||||
drawing: Drawing<ZoneWeight, R>,
|
drawing: Drawing<ZoneWeight, R>,
|
||||||
connectivity: StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: RulesTrait> Layout<R> {
|
impl<R: RulesTrait> Layout<R> {
|
||||||
pub fn new(drawing: Drawing<ZoneWeight, R>) -> Self {
|
pub fn new(drawing: Drawing<ZoneWeight, R>) -> Self {
|
||||||
Self {
|
Self { drawing }
|
||||||
drawing,
|
|
||||||
connectivity: StableDiGraph::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_band(&mut self, band: BandIndex) {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) {
|
pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) {
|
||||||
self.drawing.remove_segbend(segbend, face)
|
self.drawing.remove_segbend(segbend, face)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_band(&mut self, from: FixedDotIndex) -> BandIndex {
|
|
||||||
let band = self
|
|
||||||
.connectivity
|
|
||||||
.add_node(ConnectivityWeight::Band(BandWeight { from, to: None }));
|
|
||||||
self.connectivity.update_edge(
|
|
||||||
self.continent(from.into()).node_index(),
|
|
||||||
band,
|
|
||||||
ConnectivityLabel::Band,
|
|
||||||
);
|
|
||||||
BandIndex::new(band)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn finish_band(&mut self, band: BandIndex, to: FixedDotIndex) {
|
|
||||||
self.connectivity.update_edge(
|
|
||||||
band.node_index(),
|
|
||||||
self.continent(to.into()).node_index(),
|
|
||||||
ConnectivityLabel::Band,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_segbend(
|
pub fn insert_segbend(
|
||||||
&mut self,
|
&mut self,
|
||||||
from: DotIndex,
|
from: DotIndex,
|
||||||
|
|
@ -152,24 +119,11 @@ impl<R: RulesTrait> Layout<R> {
|
||||||
self.drawing.move_dot(dot, to)
|
self.drawing.move_dot(dot, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn band_from(&self, band: BandIndex) -> FixedDotIndex {
|
pub fn band_length(&self, face: DotIndex) -> f64 {
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn band_to(&self, band: BandIndex) -> Option<FixedDotIndex> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn band_length(&self, band: BandIndex) -> f64 {
|
|
||||||
// TODO.
|
// TODO.
|
||||||
0.0
|
0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn continent(&self, dot: FixedDotIndex) -> ContinentIndex {
|
|
||||||
// TODO.
|
|
||||||
ContinentIndex::new(0.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn zone_nodes(&self) -> impl Iterator<Item = GenericIndex<ZoneWeight>> + '_ {
|
pub fn zone_nodes(&self) -> impl Iterator<Item = GenericIndex<ZoneWeight>> + '_ {
|
||||||
self.drawing.rtree().iter().filter_map(|wrapper| {
|
self.drawing.rtree().iter().filter_map(|wrapper| {
|
||||||
if let NodeIndex::Compound(zone) = wrapper.data {
|
if let NodeIndex::Compound(zone) = wrapper.data {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod connectivity;
|
|
||||||
mod layout;
|
mod layout;
|
||||||
pub mod zone;
|
pub mod zone;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ use spade::InsertionError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::drawing::graph::{GetLayer, GetMaybeNet};
|
use crate::drawing::graph::{GetLayer, GetMaybeNet};
|
||||||
|
use crate::drawing::guide::HeadTrait;
|
||||||
use crate::geometry::primitive::PrimitiveShapeTrait;
|
use crate::geometry::primitive::PrimitiveShapeTrait;
|
||||||
use crate::layout::connectivity::BandIndex;
|
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
|
|
@ -123,7 +123,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Navmesh, f64>
|
||||||
.layout
|
.layout
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.band_length(self.trace.band);
|
.band_length(self.trace.head.face());
|
||||||
|
|
||||||
let width = self.trace.width;
|
let width = self.trace.width;
|
||||||
let result = self.tracer.step(&mut self.trace, edge.target(), width);
|
let result = self.tracer.step(&mut self.trace, edge.target(), width);
|
||||||
|
|
@ -135,7 +135,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Navmesh, f64>
|
||||||
.layout
|
.layout
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.band_length(self.trace.band);
|
.band_length(self.trace.head.face());
|
||||||
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
self.tracer.undo_step(&mut self.trace);
|
self.tracer.undo_step(&mut self.trace);
|
||||||
|
|
@ -183,11 +183,10 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
||||||
&mut self,
|
&mut self,
|
||||||
width: f64,
|
width: f64,
|
||||||
observer: &mut impl RouterObserverTrait<R>,
|
observer: &mut impl RouterObserverTrait<R>,
|
||||||
) -> Result<BandIndex, RoutingError> {
|
) -> Result<(), RoutingError> {
|
||||||
let mut tracer = self.tracer();
|
let mut tracer = self.tracer();
|
||||||
|
|
||||||
let trace = tracer.start(self.navmesh.from(), width);
|
let trace = tracer.start(self.navmesh.from(), width);
|
||||||
let band = trace.band;
|
|
||||||
|
|
||||||
let (_cost, _path) = astar(
|
let (_cost, _path) = astar(
|
||||||
&self.navmesh,
|
&self.navmesh,
|
||||||
|
|
@ -200,10 +199,10 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
||||||
source: RoutingErrorKind::AStar,
|
source: RoutingErrorKind::AStar,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(band)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reroute_band(
|
/*pub fn reroute_band(
|
||||||
&mut self,
|
&mut self,
|
||||||
band: BandIndex,
|
band: BandIndex,
|
||||||
to: Point,
|
to: Point,
|
||||||
|
|
@ -218,7 +217,7 @@ impl<'a, R: RulesTrait> Router<'a, R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.route_band(width, observer)
|
self.route_band(width, observer)
|
||||||
}
|
}*/
|
||||||
|
|
||||||
fn tracer(&mut self) -> Tracer<R> {
|
fn tracer(&mut self) -> Tracer<R> {
|
||||||
Tracer::new(self.layout.clone())
|
Tracer::new(self.layout.clone())
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
guide::{BareHead, Head, SegbendHead},
|
guide::{BareHead, Head, SegbendHead},
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
layout::{connectivity::BandIndex, Layout},
|
layout::Layout,
|
||||||
router::{
|
router::{
|
||||||
draw::{Draw, DrawException},
|
draw::{Draw, DrawException},
|
||||||
navmesh::{Navmesh, VertexIndex},
|
navmesh::{Navmesh, VertexIndex},
|
||||||
|
|
@ -20,7 +20,6 @@ use crate::{
|
||||||
pub struct Trace {
|
pub struct Trace {
|
||||||
pub path: Vec<VertexIndex>,
|
pub path: Vec<VertexIndex>,
|
||||||
pub head: Head,
|
pub head: Head,
|
||||||
pub band: BandIndex,
|
|
||||||
pub width: f64,
|
pub width: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,11 +34,9 @@ impl<R: RulesTrait> Tracer<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self, from: FixedDotIndex, width: f64) -> Trace {
|
pub fn start(&mut self, from: FixedDotIndex, width: f64) -> Trace {
|
||||||
let band = self.layout.lock().unwrap().start_band(from);
|
|
||||||
Trace {
|
Trace {
|
||||||
path: vec![from.into()],
|
path: vec![from.into()],
|
||||||
head: BareHead { dot: from }.into(),
|
head: BareHead { dot: from }.into(),
|
||||||
band,
|
|
||||||
width,
|
width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +48,7 @@ impl<R: RulesTrait> Tracer<R> {
|
||||||
width: f64,
|
width: f64,
|
||||||
) -> Result<(), DrawException> {
|
) -> Result<(), DrawException> {
|
||||||
Draw::new(&mut self.layout.lock().unwrap()).finish_in_dot(trace.head, into, width)?;
|
Draw::new(&mut self.layout.lock().unwrap()).finish_in_dot(trace.head, into, width)?;
|
||||||
Ok(self.layout.lock().unwrap().finish_band(trace.band, into))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(ret.is_ok() -> trace.path.len() == path.len())]
|
#[debug_ensures(ret.is_ok() -> trace.path.len() == path.len())]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue