mesh_graph/elements/
face.rs1use glam::Vec3;
2
3use crate::MeshGraph;
4
5use super::{FaceId, HalfedgeId, VertexId};
6
7#[derive(Default, Debug, Clone, Copy)]
8pub struct Face {
9 pub halfedge: HalfedgeId,
12
13 pub index: usize,
15
16 pub id: FaceId,
18}
19
20impl parry3d::partitioning::IndexedData for Face {
21 fn default() -> Self {
22 Default::default()
23 }
24
25 fn index(&self) -> usize {
26 self.index
27 }
28}
29
30impl Face {
31 pub fn halfedges(&self, mesh_graph: &MeshGraph) -> Vec<HalfedgeId> {
34 let mut edges = Vec::with_capacity(3);
36 edges.push(self.halfedge);
37
38 let he = mesh_graph.halfedges[self.halfedge];
39 let next_id = he.next.unwrap();
40 edges.push(next_id);
41 edges.push(mesh_graph.halfedges[next_id].next.unwrap());
42
43 edges
44 }
45
46 pub fn vertices(&self, mesh_graph: &MeshGraph) -> Vec<VertexId> {
49 let mut vertices = Vec::with_capacity(3);
50
51 for halfedge in self.halfedges(mesh_graph) {
52 vertices.push(mesh_graph.halfedges[halfedge].end_vertex);
53 }
54
55 vertices
56 }
57
58 pub fn center(&self, mesh_graph: &MeshGraph) -> Vec3 {
60 let mut sum = Vec3::ZERO;
61 for vertex in self.vertices(mesh_graph) {
62 sum += mesh_graph.positions[vertex];
63 }
64 sum / 3.0
65 }
66}