mirror of https://codeberg.org/topola/topola.git
mesh: Use a `.map()` instead of custom iterator `struct`s
This commit is contained in:
parent
3acbbc1565
commit
9a5b046724
112
src/mesh.rs
112
src/mesh.rs
|
|
@ -98,7 +98,7 @@ impl Mesh {
|
||||||
|
|
||||||
impl visit::GraphBase for Mesh {
|
impl visit::GraphBase for Mesh {
|
||||||
type NodeId = VertexIndex;
|
type NodeId = VertexIndex;
|
||||||
type EdgeId = FixedDirectedEdgeHandle;
|
type EdgeId = (VertexIndex, VertexIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MeshVisitMap {
|
pub struct MeshVisitMap {
|
||||||
|
|
@ -160,25 +160,22 @@ impl visit::Data for Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct MeshEdgeReference<'a> {
|
pub struct MeshEdgeReference {
|
||||||
handle: DirectedEdgeHandle<'a, Vertex, (), (), ()>,
|
from: VertexIndex,
|
||||||
|
to: VertexIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> visit::EdgeRef for MeshEdgeReference<'a> {
|
impl<'a> visit::EdgeRef for MeshEdgeReference {
|
||||||
type NodeId = VertexIndex;
|
type NodeId = VertexIndex;
|
||||||
type EdgeId = FixedDirectedEdgeHandle;
|
type EdgeId = (VertexIndex, VertexIndex);
|
||||||
type Weight = ();
|
type Weight = ();
|
||||||
|
|
||||||
fn source(&self) -> Self::NodeId {
|
fn source(&self) -> Self::NodeId {
|
||||||
VertexIndex {
|
self.from
|
||||||
handle: self.handle.from().fix(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target(&self) -> Self::NodeId {
|
fn target(&self) -> Self::NodeId {
|
||||||
VertexIndex {
|
self.to
|
||||||
handle: self.handle.to().fix(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn weight(&self) -> &Self::Weight {
|
fn weight(&self) -> &Self::Weight {
|
||||||
|
|
@ -186,78 +183,61 @@ impl<'a> visit::EdgeRef for MeshEdgeReference<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> Self::EdgeId {
|
fn id(&self) -> Self::EdgeId {
|
||||||
self.handle.fix()
|
(self.from, self.to)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MeshEdgeReferences<'a> {
|
|
||||||
iter: DirectedEdgeIterator<'a, Vertex, (), (), ()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for MeshEdgeReferences<'a> {
|
|
||||||
type Item = MeshEdgeReference<'a>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
let handle = self.iter.next()?;
|
|
||||||
Some(MeshEdgeReference { handle })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> visit::IntoEdgeReferences for &'a Mesh {
|
impl<'a> visit::IntoEdgeReferences for &'a Mesh {
|
||||||
type EdgeRef = MeshEdgeReference<'a>;
|
type EdgeRef = MeshEdgeReference;
|
||||||
type EdgeReferences = MeshEdgeReferences<'a>;
|
type EdgeReferences = Box<dyn Iterator<Item = MeshEdgeReference> + 'a>;
|
||||||
|
|
||||||
fn edge_references(self) -> Self::EdgeReferences {
|
fn edge_references(self) -> Self::EdgeReferences {
|
||||||
MeshEdgeReferences {
|
Box::new(
|
||||||
iter: self.triangulation.directed_edges(),
|
self.triangulation
|
||||||
}
|
.directed_edges()
|
||||||
}
|
.map(|edge| MeshEdgeReference {
|
||||||
}
|
from: VertexIndex {
|
||||||
|
handle: edge.from().fix(),
|
||||||
pub struct MeshNeighbors<'a> {
|
},
|
||||||
iter: Box<dyn Iterator<Item = DirectedEdgeHandle<'a, Vertex, (), (), ()>> + 'a>,
|
to: VertexIndex {
|
||||||
}
|
handle: edge.to().fix(),
|
||||||
|
},
|
||||||
impl<'a> Iterator for MeshNeighbors<'a> {
|
}),
|
||||||
type Item = VertexIndex;
|
)
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
let handle = self.iter.next()?;
|
|
||||||
Some(VertexIndex {
|
|
||||||
handle: handle.to().fix(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> visit::IntoNeighbors for &'a Mesh {
|
impl<'a> visit::IntoNeighbors for &'a Mesh {
|
||||||
type Neighbors = MeshNeighbors<'a>;
|
type Neighbors = Box<dyn Iterator<Item = VertexIndex> + 'a>;
|
||||||
|
|
||||||
fn neighbors(self, a: Self::NodeId) -> Self::Neighbors {
|
fn neighbors(self, a: Self::NodeId) -> Self::Neighbors {
|
||||||
MeshNeighbors {
|
Box::new(
|
||||||
iter: Box::new(self.triangulation.vertex(a.handle).out_edges()),
|
self.triangulation
|
||||||
}
|
.vertex(a.handle)
|
||||||
}
|
.out_edges()
|
||||||
}
|
.map(|handle| VertexIndex {
|
||||||
|
handle: handle.to().fix(),
|
||||||
pub struct MeshEdges<'a> {
|
}),
|
||||||
iter: Box<dyn Iterator<Item = DirectedEdgeHandle<'a, Vertex, (), (), ()>> + 'a>,
|
)
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for MeshEdges<'a> {
|
|
||||||
type Item = MeshEdgeReference<'a>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
let handle = self.iter.next()?;
|
|
||||||
Some(MeshEdgeReference { handle })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> visit::IntoEdges for &'a Mesh {
|
impl<'a> visit::IntoEdges for &'a Mesh {
|
||||||
type Edges = MeshEdges<'a>;
|
type Edges = Box<dyn Iterator<Item = MeshEdgeReference> + 'a>;
|
||||||
|
|
||||||
fn edges(self, a: Self::NodeId) -> Self::Edges {
|
fn edges(self, a: Self::NodeId) -> Self::Edges {
|
||||||
MeshEdges {
|
Box::new(
|
||||||
iter: Box::new(self.triangulation.vertex(a.handle).out_edges()),
|
self.triangulation
|
||||||
}
|
.vertex(a.handle)
|
||||||
|
.out_edges()
|
||||||
|
.map(|edge| MeshEdgeReference {
|
||||||
|
from: VertexIndex {
|
||||||
|
handle: edge.from().fix(),
|
||||||
|
},
|
||||||
|
to: VertexIndex {
|
||||||
|
handle: edge.to().fix(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue