layout: remove concepts of connectivity, bands, and continents for now

We'll use `UnionFind` where needed for now.
This commit is contained in:
Mikolaj Wielgus 2024-05-13 18:43:42 +02:00
parent 8a3bf45fd8
commit 4c6fa0e5d3
8 changed files with 17 additions and 140 deletions

View File

@ -21,7 +21,7 @@ use crate::{
graph::{GetLayer, GetMaybeNet},
rules::RulesTrait,
},
layout::{connectivity::BandIndex, Layout, NodeIndex},
layout::{Layout, NodeIndex},
router::{navmesh::Navmesh, Router, RouterObserverTrait, RoutingError},
triangulation::GetVertexIndex,
};

View File

@ -330,7 +330,7 @@ fn render_times(
font_context: &CanvasFontContext,
view: &mut View,
mut router_or_layout: RouterOrLayout<impl RulesTrait>,
maybe_band: Option<BandIndex>,
_unused: Option<()>,
mut maybe_navmesh: Option<Navmesh>,
path: &[VertexIndex],
ghosts: &[PrimitiveShape],
@ -381,7 +381,7 @@ fn render_times(
RouterOrLayout::Router(ref mut router) => {
let state = event_pump.mouse_state();
if let Some(band) = maybe_band {
/*if let Some(band) = maybe_band {
router
.reroute_band(
band,
@ -398,7 +398,7 @@ fn render_times(
)
.ok();
maybe_navmesh = None;
}
}*/
router.layout().clone()
}

View File

@ -5,8 +5,6 @@ use crate::geometry::{
primitive::{PrimitiveShape, PrimitiveShapeTrait},
GetOffset, GetWidth,
};
use crate::graph::{GenericIndex, GetNodeIndex};
use crate::layout::connectivity::{BandIndex, ContinentIndex};
use crate::{
drawing::{
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
@ -21,6 +19,7 @@ use crate::{
Drawing,
},
geometry::GenericNode,
graph::{GenericIndex, GetNodeIndex},
};
#[enum_dispatch]
@ -249,36 +248,6 @@ where
pub type FixedDot<'a, CW, R> = GenericPrimitive<'a, FixedDotWeight, CW, R>;
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> {
fn shape(&self) -> PrimitiveShape {
self.drawing.geometry().dot_shape(self.index.into())

View File

@ -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,
}

View File

@ -21,12 +21,7 @@ use crate::{
DotWeightTrait, GenericNode, Geometry, GeometryLabel, GetWidth, SegWeightTrait,
},
graph::{GenericIndex, GetNodeIndex},
layout::{
connectivity::{
BandIndex, BandWeight, ConnectivityLabel, ConnectivityWeight, ContinentIndex,
},
zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
},
layout::zone::{GetMaybeApex, MakePolyShape, PourZoneIndex, SolidZoneIndex, Zone, ZoneWeight},
math::Circle,
};
@ -35,45 +30,17 @@ pub type NodeIndex = GenericNode<PrimitiveIndex, GenericIndex<ZoneWeight>>;
#[derive(Debug)]
pub struct Layout<R: RulesTrait> {
drawing: Drawing<ZoneWeight, R>,
connectivity: StableDiGraph<ConnectivityWeight, ConnectivityLabel, usize>,
}
impl<R: RulesTrait> Layout<R> {
pub fn new(drawing: Drawing<ZoneWeight, R>) -> Self {
Self {
drawing,
connectivity: StableDiGraph::default(),
}
}
pub fn remove_band(&mut self, band: BandIndex) {
todo!()
Self { drawing }
}
pub fn remove_segbend(&mut self, segbend: &Segbend, face: LooseDotIndex) {
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(
&mut self,
from: DotIndex,
@ -152,24 +119,11 @@ impl<R: RulesTrait> Layout<R> {
self.drawing.move_dot(dot, to)
}
pub fn band_from(&self, band: BandIndex) -> FixedDotIndex {
todo!()
}
pub fn band_to(&self, band: BandIndex) -> Option<FixedDotIndex> {
todo!()
}
pub fn band_length(&self, band: BandIndex) -> f64 {
pub fn band_length(&self, face: DotIndex) -> f64 {
// TODO.
0.0
}
pub fn continent(&self, dot: FixedDotIndex) -> ContinentIndex {
// TODO.
ContinentIndex::new(0.into())
}
pub fn zone_nodes(&self) -> impl Iterator<Item = GenericIndex<ZoneWeight>> + '_ {
self.drawing.rtree().iter().filter_map(|wrapper| {
if let NodeIndex::Compound(zone) = wrapper.data {

View File

@ -1,4 +1,3 @@
pub mod connectivity;
mod layout;
pub mod zone;

View File

@ -7,8 +7,8 @@ use spade::InsertionError;
use thiserror::Error;
use crate::drawing::graph::{GetLayer, GetMaybeNet};
use crate::drawing::guide::HeadTrait;
use crate::geometry::primitive::PrimitiveShapeTrait;
use crate::layout::connectivity::BandIndex;
use crate::layout::Layout;
use crate::{
drawing::{
@ -123,7 +123,7 @@ impl<'a, RO: RouterObserverTrait<R>, R: RulesTrait> AstarStrategy<&Navmesh, f64>
.layout
.lock()
.unwrap()
.band_length(self.trace.band);
.band_length(self.trace.head.face());
let width = self.trace.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
.lock()
.unwrap()
.band_length(self.trace.band);
.band_length(self.trace.head.face());
if result.is_ok() {
self.tracer.undo_step(&mut self.trace);
@ -183,11 +183,10 @@ impl<'a, R: RulesTrait> Router<'a, R> {
&mut self,
width: f64,
observer: &mut impl RouterObserverTrait<R>,
) -> Result<BandIndex, RoutingError> {
) -> Result<(), RoutingError> {
let mut tracer = self.tracer();
let trace = tracer.start(self.navmesh.from(), width);
let band = trace.band;
let (_cost, _path) = astar(
&self.navmesh,
@ -200,10 +199,10 @@ impl<'a, R: RulesTrait> Router<'a, R> {
source: RoutingErrorKind::AStar,
})?;
Ok(band)
Ok(())
}
pub fn reroute_band(
/*pub fn reroute_band(
&mut self,
band: BandIndex,
to: Point,
@ -218,7 +217,7 @@ impl<'a, R: RulesTrait> Router<'a, R> {
}
self.route_band(width, observer)
}
}*/
fn tracer(&mut self) -> Tracer<R> {
Tracer::new(self.layout.clone())

View File

@ -9,7 +9,7 @@ use crate::{
guide::{BareHead, Head, SegbendHead},
rules::RulesTrait,
},
layout::{connectivity::BandIndex, Layout},
layout::Layout,
router::{
draw::{Draw, DrawException},
navmesh::{Navmesh, VertexIndex},
@ -20,7 +20,6 @@ use crate::{
pub struct Trace {
pub path: Vec<VertexIndex>,
pub head: Head,
pub band: BandIndex,
pub width: f64,
}
@ -35,11 +34,9 @@ impl<R: RulesTrait> Tracer<R> {
}
pub fn start(&mut self, from: FixedDotIndex, width: f64) -> Trace {
let band = self.layout.lock().unwrap().start_band(from);
Trace {
path: vec![from.into()],
head: BareHead { dot: from }.into(),
band,
width,
}
}
@ -51,7 +48,7 @@ impl<R: RulesTrait> Tracer<R> {
width: f64,
) -> Result<(), DrawException> {
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())]