use super::{HalfEdgeImplMeshType, HalfEdgeVertexImpl, IncidentToVertexIterator};
use crate::{
math::IndexType,
mesh::{EdgeBasics, HalfEdge, MeshBasics, VertexBasics},
};
impl<T: HalfEdgeImplMeshType> VertexBasics<T> for HalfEdgeVertexImpl<T> {
#[inline(always)]
fn id(&self) -> T::V {
self.id
}
#[inline(always)]
fn payload(&self) -> &T::VP {
&self.payload
}
#[inline(always)]
fn payload_mut(&mut self) -> &mut T::VP {
&mut self.payload
}
#[inline(always)]
fn is_boundary(&self, mesh: &T::Mesh) -> bool {
self.edges_out(mesh).any(|e| e.is_boundary(mesh))
}
#[inline(always)]
fn has_only_one_edge(&self, mesh: &T::Mesh) -> bool {
if let Some(e) = self.edge(mesh) {
e.prev_id() == e.twin_id()
} else {
false
}
}
#[inline(always)]
fn edge_id(&self, _mesh: &T::Mesh) -> T::E {
self.edge
}
#[inline(always)]
fn edge(&self, mesh: &T::Mesh) -> Option<T::Edge> {
if self.edge == IndexType::max() {
None
} else {
Some(mesh.edge(self.edge).clone())
}
}
#[inline(always)]
fn vertices<'a>(&'a self, mesh: &'a T::Mesh) -> impl Iterator<Item = T::Vertex> + 'a {
self.edges_out(mesh).map(|e| e.target(mesh).clone())
}
#[inline(always)]
fn faces<'a>(&'a self, mesh: &'a T::Mesh) -> impl Iterator<Item = T::Face> + 'a
where
T: 'a,
{
self.edges_out(mesh).filter_map(|e| e.face(mesh).cloned())
}
#[inline(always)]
fn edges_out<'a>(&'a self, mesh: &'a T::Mesh) -> impl Iterator<Item = T::Edge> + 'a {
if let Some(e) = self.edge(mesh) {
IncidentToVertexIterator::<T>::new(e, mesh)
} else {
return IncidentToVertexIterator::<T>::empty(mesh);
}
}
#[inline(always)]
fn edges_in<'a>(&'a self, mesh: &'a T::Mesh) -> impl Iterator<Item = T::Edge> + 'a {
(if let Some(e) = self.edge(mesh) {
IncidentToVertexIterator::<T>::new(e, mesh)
} else {
IncidentToVertexIterator::<T>::empty(mesh)
})
.map(|e| e.twin(mesh))
}
}