Add HalfEdge, add it to Face

This commit is contained in:
Hanno Braun 2025-02-24 19:04:06 +01:00
parent 8d54268c72
commit bce3e7a158
3 changed files with 30 additions and 6 deletions

View File

@ -9,12 +9,12 @@ use crate::{
object::{Handle, HandleAny, Object}, object::{Handle, HandleAny, Object},
}; };
use super::vertex::Vertex; use super::{half_edge::HalfEdge, vertex::Vertex};
#[derive(Debug)] #[derive(Debug)]
pub struct Face { pub struct Face {
surface: Plane, surface: Plane,
vertices: Vec<Handle<Vertex>>, vertices: Vec<Handle<HalfEdge>>,
} }
impl Face { impl Face {
@ -22,7 +22,10 @@ impl Face {
surface: Plane, surface: Plane,
vertices: impl IntoIterator<Item = Handle<Vertex>>, vertices: impl IntoIterator<Item = Handle<Vertex>>,
) -> Self { ) -> Self {
let vertices = vertices.into_iter().collect(); let vertices = vertices
.into_iter()
.map(|vertex| Handle::new(HalfEdge::new(vertex)))
.collect();
Self { surface, vertices } Self { surface, vertices }
} }
@ -31,14 +34,14 @@ impl Face {
} }
pub fn vertices(&self) -> impl Iterator<Item = &Handle<Vertex>> { pub fn vertices(&self) -> impl Iterator<Item = &Handle<Vertex>> {
self.vertices.iter() self.vertices.iter().map(|half_edge| half_edge.start())
} }
pub fn half_edges(&self) -> impl Iterator<Item = [&Handle<Vertex>; 2]> { pub fn half_edges(&self) -> impl Iterator<Item = [&Handle<Vertex>; 2]> {
self.vertices self.vertices
.iter() .iter()
.circular_tuple_windows() .circular_tuple_windows()
.map(|(a, b)| [a, b]) .map(|(a, b)| [a.start(), b.start()])
} }
} }
@ -48,7 +51,10 @@ impl Object for Face {
} }
fn tri_mesh(&self) -> TriMesh { fn tri_mesh(&self) -> TriMesh {
triangulate(&self.vertices, self.surface()) let mut vertices = Vec::new();
vertices.extend(self.vertices().cloned());
triangulate(&vertices, self.surface())
} }
fn children(&self) -> Vec<HandleAny> { fn children(&self) -> Vec<HandleAny> {

View File

@ -0,0 +1,17 @@
use crate::object::Handle;
use super::vertex::Vertex;
pub struct HalfEdge {
start: Handle<Vertex>,
}
impl HalfEdge {
pub fn new(start: Handle<Vertex>) -> Self {
Self { start }
}
pub fn start(&self) -> &Handle<Vertex> {
&self.start
}
}

View File

@ -1,3 +1,4 @@
pub mod face; pub mod face;
pub mod half_edge;
pub mod solid; pub mod solid;
pub mod vertex; pub mod vertex;