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
.drawing()
.rtree()
@ -61,9 +61,9 @@ impl Overlay {
}
}
fn toggle_selection_if_contains_point<R: RulesTrait>(
fn toggle_selection_if_contains_point(
&mut self,
layout: &Layout<R>,
layout: &Layout<impl RulesTrait>,
node: NodeIndex,
p: Point,
) -> bool {

View File

@ -7,17 +7,18 @@ use petgraph::visit::{self, NodeIndexable};
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
use spade::{HasPosition, InsertionError, Point2};
use crate::drawing::rules::RulesTrait;
use crate::{
drawing::{
bend::{FixedBendIndex, LooseBendIndex},
dot::FixedDotIndex,
graph::{MakePrimitive, PrimitiveIndex},
primitive::{GetCore, MakePrimitiveShape, Primitive},
rules::RulesTrait,
Drawing,
},
geometry::primitive::PrimitiveShapeTrait,
graph::GetNodeIndex,
layout::Layout,
router::triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
};
@ -82,22 +83,19 @@ pub struct 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 {
triangulation: Triangulation::new(drawing),
triangulation: Triangulation::new(layout.drawing()),
vertex_to_triangulation_vertex: Vec::new(),
};
this.vertex_to_triangulation_vertex
.resize(drawing.geometry().graph().node_bound(), None);
.resize(layout.drawing().geometry().graph().node_bound(), None);
this
}
pub fn generate(
&mut self,
drawing: &Drawing<impl Copy, impl RulesTrait>,
) -> Result<(), InsertionError> {
for node in drawing.primitive_nodes() {
let center = node.primitive(drawing).shape().center();
pub fn generate(&mut self, layout: &Layout<impl RulesTrait>) -> Result<(), InsertionError> {
for node in layout.drawing().primitive_nodes() {
let center = node.primitive(layout.drawing()).shape().center();
match node {
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.
match node {
PrimitiveIndex::LooseBend(bend) => {
self.triangulation
.weight_mut(drawing.primitive(bend).core().into())
.weight_mut(layout.drawing().primitive(bend).core().into())
.rails
.push(bend.into());
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
// right.
//self.mesh.triangulate(&self.layout)?;
let mut mesh = Mesh::new(self.layout.drawing());
mesh.generate(self.layout.drawing())
.map_err(|err| RoutingError {
let mut mesh = Mesh::new(&self.layout);
mesh.generate(&self.layout).map_err(|err| RoutingError {
from,
to,
source: err.into(),