router: operate on `Layout`, not `Drawing`

This commit is contained in:
Mikolaj Wielgus 2024-04-20 00:31:20 +02:00
parent 94c88a51f8
commit fba86ceccd
3 changed files with 20 additions and 23 deletions

View File

@ -33,7 +33,7 @@ impl Overlay {
} }
} }
pub fn click<R: RulesTrait>(&mut self, layout: &Layout<R>, at: Point) { pub fn click(&mut self, layout: &Layout<impl RulesTrait>, at: Point) {
let geoms: Vec<_> = layout let geoms: Vec<_> = layout
.drawing() .drawing()
.rtree() .rtree()
@ -61,9 +61,9 @@ impl Overlay {
} }
} }
fn toggle_selection_if_contains_point<R: RulesTrait>( fn toggle_selection_if_contains_point(
&mut self, &mut self,
layout: &Layout<R>, layout: &Layout<impl RulesTrait>,
node: NodeIndex, node: NodeIndex,
p: Point, p: Point,
) -> bool { ) -> bool {

View File

@ -7,17 +7,18 @@ use petgraph::visit::{self, NodeIndexable};
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef}; use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
use spade::{HasPosition, InsertionError, Point2}; use spade::{HasPosition, InsertionError, Point2};
use crate::drawing::rules::RulesTrait;
use crate::{ use crate::{
drawing::{ drawing::{
bend::{FixedBendIndex, LooseBendIndex}, bend::{FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex, dot::FixedDotIndex,
graph::{MakePrimitive, PrimitiveIndex}, graph::{MakePrimitive, PrimitiveIndex},
primitive::{GetCore, MakePrimitiveShape, Primitive}, primitive::{GetCore, MakePrimitiveShape, Primitive},
rules::RulesTrait,
Drawing, Drawing,
}, },
geometry::primitive::PrimitiveShapeTrait, geometry::primitive::PrimitiveShapeTrait,
graph::GetNodeIndex, graph::GetNodeIndex,
layout::Layout,
router::triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference}, router::triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
}; };
@ -82,22 +83,19 @@ pub struct Mesh {
} }
impl Mesh { impl Mesh {
pub fn new(drawing: &Drawing<impl Copy, impl RulesTrait>) -> Self { pub fn new(layout: &Layout<impl RulesTrait>) -> Self {
let mut this = Self { let mut this = Self {
triangulation: Triangulation::new(drawing), triangulation: Triangulation::new(layout.drawing()),
vertex_to_triangulation_vertex: Vec::new(), vertex_to_triangulation_vertex: Vec::new(),
}; };
this.vertex_to_triangulation_vertex this.vertex_to_triangulation_vertex
.resize(drawing.geometry().graph().node_bound(), None); .resize(layout.drawing().geometry().graph().node_bound(), None);
this this
} }
pub fn generate( pub fn generate(&mut self, layout: &Layout<impl RulesTrait>) -> Result<(), InsertionError> {
&mut self, for node in layout.drawing().primitive_nodes() {
drawing: &Drawing<impl Copy, impl RulesTrait>, let center = node.primitive(layout.drawing()).shape().center();
) -> Result<(), InsertionError> {
for node in drawing.primitive_nodes() {
let center = node.primitive(drawing).shape().center();
match node { match node {
PrimitiveIndex::FixedDot(dot) => { PrimitiveIndex::FixedDot(dot) => {
@ -118,16 +116,16 @@ impl Mesh {
} }
} }
for node in drawing.primitive_nodes() { for node in layout.drawing().primitive_nodes() {
// Add rails as vertices. This is how the mesh differs from the triangulation. // Add rails as vertices. This is how the mesh differs from the triangulation.
match node { match node {
PrimitiveIndex::LooseBend(bend) => { PrimitiveIndex::LooseBend(bend) => {
self.triangulation self.triangulation
.weight_mut(drawing.primitive(bend).core().into()) .weight_mut(layout.drawing().primitive(bend).core().into())
.rails .rails
.push(bend.into()); .push(bend.into());
self.vertex_to_triangulation_vertex[bend.node_index().index()] = self.vertex_to_triangulation_vertex[bend.node_index().index()] =
Some(drawing.primitive(bend).core().into()); Some(layout.drawing().primitive(bend).core().into());
} }
_ => (), _ => (),
} }

View File

@ -149,9 +149,8 @@ impl<R: RulesTrait> Router<R> {
// XXX: Should we actually store the mesh? May be useful for debugging, but doesn't look // XXX: Should we actually store the mesh? May be useful for debugging, but doesn't look
// right. // right.
//self.mesh.triangulate(&self.layout)?; //self.mesh.triangulate(&self.layout)?;
let mut mesh = Mesh::new(self.layout.drawing()); let mut mesh = Mesh::new(&self.layout);
mesh.generate(self.layout.drawing()) mesh.generate(&self.layout).map_err(|err| RoutingError {
.map_err(|err| RoutingError {
from, from,
to, to,
source: err.into(), source: err.into(),