1use crate::{HalfedgeId, MeshGraph};
2
3pub struct CircularHalfedgesIterator<'a> {
5 start_halfedge: Option<HalfedgeId>,
6 mesh_graph: &'a MeshGraph,
7 current_halfedge: Option<HalfedgeId>,
8 get_next_halfedge: fn(HalfedgeId, &'a MeshGraph) -> Option<HalfedgeId>,
9}
10
11impl<'a> CircularHalfedgesIterator<'a> {
12 pub fn new(
13 start_halfedge: Option<HalfedgeId>,
14 mesh_graph: &'a MeshGraph,
15 get_next_halfedge: fn(HalfedgeId, &'a MeshGraph) -> Option<HalfedgeId>,
16 ) -> Self {
17 Self {
18 start_halfedge,
19 mesh_graph,
20 current_halfedge: None,
21 get_next_halfedge,
22 }
23 }
24}
25
26impl<'a> Iterator for CircularHalfedgesIterator<'a> {
27 type Item = HalfedgeId;
28
29 fn next(&mut self) -> Option<Self::Item> {
30 if let Some(current_halfedge) = self.current_halfedge {
31 self.current_halfedge = (self.get_next_halfedge)(current_halfedge, self.mesh_graph);
32
33 if self.current_halfedge == self.start_halfedge {
34 return None;
35 }
36 } else {
37 self.current_halfedge = self.start_halfedge;
38 }
39
40 self.current_halfedge
41 }
42}