layout: Return an iterator over nodes instead of dots

It's more general. Needed because mesh will be also generated from fixed
and loose bends.
This commit is contained in:
Mikolaj Wielgus 2023-10-30 16:05:36 +00:00
parent c46d8c7434
commit b84dab9d09
2 changed files with 22 additions and 15 deletions

View File

@ -356,20 +356,25 @@ impl Layout {
Ok(())
}
pub fn dots(&self) -> impl Iterator<Item = FixedDotIndex> + '_ {
self.nodes()
.filter_map(|ni| ni.as_fixed_dot().map(|di| *di))
pub fn nodes(&self) -> impl Iterator<Item = Index> + '_ {
self.node_indexes().map(|ni| {
self.graph
.node_weight(ni.node_index())
.unwrap()
.retag(ni.node_index())
})
}
pub fn shapes(&self) -> impl Iterator<Item = Shape> + '_ {
self.nodes().map(|ni| ni.primitive(&self.graph).shape())
self.node_indexes()
.map(|ni| ni.primitive(&self.graph).shape())
}
pub fn node_count(&self) -> usize {
self.graph.node_count()
}
fn nodes(&self) -> impl Iterator<Item = Index> + '_ {
fn node_indexes(&self) -> impl Iterator<Item = Index> + '_ {
self.rtree.iter().map(|wrapper| wrapper.data)
}
}

View File

@ -8,7 +8,7 @@ use spade::{
};
use crate::{
graph::{DotIndex, FixedDotIndex, GetNodeIndex},
graph::{DotIndex, FixedDotIndex, GetNodeIndex, Index},
layout::Layout,
};
use crate::{primitive::MakeShape, shape::ShapeTrait};
@ -51,16 +51,18 @@ impl Mesh {
self.dot_to_vertex = Vec::new();
self.dot_to_vertex.resize(layout.graph.node_bound(), None);
for dot in layout.dots() {
let center = layout.primitive(dot).shape().center();
for node in layout.nodes() {
if let Index::FixedDot(dot) = node {
let center = layout.primitive(dot).shape().center();
self.dot_to_vertex[dot.node_index().index()] = Some(VertexIndex {
handle: self.triangulation.insert(Vertex {
dot,
x: center.x(),
y: center.y(),
})?,
});
self.dot_to_vertex[dot.node_index().index()] = Some(VertexIndex {
handle: self.triangulation.insert(Vertex {
dot,
x: center.x(),
y: center.y(),
})?,
});
}
}
Ok(())