use crate::common::macros::integrity_assert;
use crate::corner_table::CornerIndex;
use crate::corner_table::CornerTable;
impl<const ENABLE_UNSAFE: bool> CornerTable<ENABLE_UNSAFE> {
pub(crate) fn iter_ccw_swing(
&self,
start_corner: CornerIndex,
) -> CornerCcwIterator<'_, ENABLE_UNSAFE> {
integrity_assert!(start_corner.is_valid());
CornerCcwIterator {
mesh: self,
start_corner,
current_corner: Some(start_corner),
first_iteration: true,
}
}
}
pub(crate) struct CornerCcwIterator<'a, const ENABLE_UNSAFE: bool> {
mesh: &'a CornerTable<ENABLE_UNSAFE>,
start_corner: CornerIndex,
current_corner: Option<CornerIndex>,
first_iteration: bool,
}
impl<'a, const ENABLE_UNSAFE: bool> Iterator for CornerCcwIterator<'a, ENABLE_UNSAFE> {
type Item = CornerIndex;
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
let current = self.current_corner?;
if !self.first_iteration && current == self.start_corner {
return None;
}
self.first_iteration = false;
let next_corner = self.mesh.swing_ccw(current);
integrity_assert!(next_corner.is_valid());
self.current_corner = Some(next_corner);
Some(current)
}
}