mod basics;
mod iterator;
pub use iterator::*;
use super::HalfEdgeImplMeshType;
use crate::{
math::IndexType,
mesh::{DefaultVertexPayload, HalfEdgeVertex, MeshType, Vertex, VertexBasics, VertexPayload},
util::Deletable,
};
#[derive(Clone)]
pub struct HalfEdgeVertexImpl<T: HalfEdgeImplMeshType> {
id: T::V,
edge: T::E,
payload: T::VP,
}
impl<T: HalfEdgeImplMeshType> HalfEdgeVertexImpl<T> {
pub fn new(edge: T::E, payload: T::VP) -> Self {
Self {
id: IndexType::max(),
edge,
payload,
}
}
}
impl<T: HalfEdgeImplMeshType> HalfEdgeVertex<T> for HalfEdgeVertexImpl<T> {
fn set_edge(&mut self, edge: T::E) {
self.edge = edge;
}
}
impl<T: HalfEdgeImplMeshType> Vertex for HalfEdgeVertexImpl<T>
where
T: MeshType<Vertex = HalfEdgeVertexImpl<T>>,
{
type T = T;
}
impl<T: HalfEdgeImplMeshType> std::fmt::Debug for HalfEdgeVertexImpl<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{: >w$}) -{:-^w$}->; payload: {:?}",
self.id().index(),
self.edge.index(),
self.payload,
w = 3
)
}
}
impl<T: HalfEdgeImplMeshType> Deletable<T::V> for HalfEdgeVertexImpl<T> {
fn delete(&mut self) {
assert!(self.id != IndexType::max());
self.id = IndexType::max();
}
fn is_deleted(&self) -> bool {
self.id == IndexType::max()
}
fn set_id(&mut self, id: T::V) {
assert!(self.id == IndexType::max());
assert!(id != IndexType::max());
self.id = id;
}
fn allocate() -> Self {
Self {
id: IndexType::max(),
edge: IndexType::max(),
payload: T::VP::allocate(),
}
}
}
impl<T: HalfEdgeImplMeshType> Default for HalfEdgeVertexImpl<T>
where
T::VP: DefaultVertexPayload,
{
fn default() -> Self {
Self {
id: IndexType::max(),
edge: IndexType::max(),
payload: T::VP::default(),
}
}
}