mirror of https://codeberg.org/topola/topola.git
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:
parent
c46d8c7434
commit
b84dab9d09
|
|
@ -356,20 +356,25 @@ impl Layout {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dots(&self) -> impl Iterator<Item = FixedDotIndex> + '_ {
|
pub fn nodes(&self) -> impl Iterator<Item = Index> + '_ {
|
||||||
self.nodes()
|
self.node_indexes().map(|ni| {
|
||||||
.filter_map(|ni| ni.as_fixed_dot().map(|di| *di))
|
self.graph
|
||||||
|
.node_weight(ni.node_index())
|
||||||
|
.unwrap()
|
||||||
|
.retag(ni.node_index())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shapes(&self) -> impl Iterator<Item = Shape> + '_ {
|
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 {
|
pub fn node_count(&self) -> usize {
|
||||||
self.graph.node_count()
|
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)
|
self.rtree.iter().map(|wrapper| wrapper.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
src/mesh.rs
22
src/mesh.rs
|
|
@ -8,7 +8,7 @@ use spade::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
graph::{DotIndex, FixedDotIndex, GetNodeIndex},
|
graph::{DotIndex, FixedDotIndex, GetNodeIndex, Index},
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
};
|
};
|
||||||
use crate::{primitive::MakeShape, shape::ShapeTrait};
|
use crate::{primitive::MakeShape, shape::ShapeTrait};
|
||||||
|
|
@ -51,16 +51,18 @@ impl Mesh {
|
||||||
self.dot_to_vertex = Vec::new();
|
self.dot_to_vertex = Vec::new();
|
||||||
self.dot_to_vertex.resize(layout.graph.node_bound(), None);
|
self.dot_to_vertex.resize(layout.graph.node_bound(), None);
|
||||||
|
|
||||||
for dot in layout.dots() {
|
for node in layout.nodes() {
|
||||||
let center = layout.primitive(dot).shape().center();
|
if let Index::FixedDot(dot) = node {
|
||||||
|
let center = layout.primitive(dot).shape().center();
|
||||||
|
|
||||||
self.dot_to_vertex[dot.node_index().index()] = Some(VertexIndex {
|
self.dot_to_vertex[dot.node_index().index()] = Some(VertexIndex {
|
||||||
handle: self.triangulation.insert(Vertex {
|
handle: self.triangulation.insert(Vertex {
|
||||||
dot,
|
dot,
|
||||||
x: center.x(),
|
x: center.x(),
|
||||||
y: center.y(),
|
y: center.y(),
|
||||||
})?,
|
})?,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue