mirror of https://codeberg.org/topola/topola.git
router: constructor should return an already prepared mesh
This commit is contained in:
parent
fba86ceccd
commit
014aa018a9
|
|
@ -83,30 +83,27 @@ pub struct Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mesh {
|
impl Mesh {
|
||||||
pub fn new(layout: &Layout<impl RulesTrait>) -> Self {
|
pub fn new(layout: &Layout<impl RulesTrait>) -> Result<Self, InsertionError> {
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
triangulation: Triangulation::new(layout.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(layout.drawing().geometry().graph().node_bound(), None);
|
.resize(layout.drawing().geometry().graph().node_bound(), None);
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate(&mut self, layout: &Layout<impl RulesTrait>) -> Result<(), InsertionError> {
|
|
||||||
for node in layout.drawing().primitive_nodes() {
|
for node in layout.drawing().primitive_nodes() {
|
||||||
let center = node.primitive(layout.drawing()).shape().center();
|
let center = node.primitive(layout.drawing()).shape().center();
|
||||||
|
|
||||||
match node {
|
match node {
|
||||||
PrimitiveIndex::FixedDot(dot) => {
|
PrimitiveIndex::FixedDot(dot) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
this.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: dot.into(),
|
vertex: dot.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: center,
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
PrimitiveIndex::FixedBend(bend) => {
|
PrimitiveIndex::FixedBend(bend) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
this.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: bend.into(),
|
vertex: bend.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: center,
|
||||||
|
|
@ -120,18 +117,18 @@ impl Mesh {
|
||||||
// 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
|
this.triangulation
|
||||||
.weight_mut(layout.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()] =
|
this.vertex_to_triangulation_vertex[bend.node_index().index()] =
|
||||||
Some(layout.drawing().primitive(bend).core().into());
|
Some(layout.drawing().primitive(bend).core().into());
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn triangulation_vertex(&self, vertex: VertexIndex) -> TriangulationVertexIndex {
|
pub fn triangulation_vertex(&self, vertex: VertexIndex) -> TriangulationVertexIndex {
|
||||||
|
|
|
||||||
|
|
@ -149,8 +149,7 @@ 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);
|
let mesh = Mesh::new(&self.layout).map_err(|err| RoutingError {
|
||||||
mesh.generate(&self.layout).map_err(|err| RoutingError {
|
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
source: err.into(),
|
source: err.into(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue