mesh_graph/ops/cleanup/
edge_boundary.rs1use tracing::{error, instrument};
2
3use crate::{MeshGraph, VertexId, error_none};
4
5impl MeshGraph {
6 #[instrument(skip(self))]
11 pub fn make_outgoing_halfedge_boundary_if_possible(&mut self, vertex_id: VertexId) {
12 if !self.vertices.contains_key(vertex_id) {
13 error!("Vertex not found");
14 return;
15 }
16
17 let boundary_he_id = self.vertices[vertex_id]
18 .outgoing_halfedges(self)
19 .filter_map(|he_id| {
20 self.halfedges
21 .get(he_id)
22 .or_else(error_none!("Halfedge not found"))
23 .map(|he| (he, he_id))
24 })
25 .find(|(he, _)| he.is_boundary());
26
27 if let Some((_, boundary_he_id)) = boundary_he_id {
28 self.vertices[vertex_id].outgoing_halfedge = Some(boundary_he_id);
29 }
30 }
31
32 #[instrument(skip(self))]
37 pub fn make_all_outgoing_halfedges_boundary_if_possible(&mut self) {
38 let boundary_pairs = self
39 .halfedges
40 .iter()
41 .filter_map(|(he_id, he)| {
42 if he.is_boundary() {
43 he.start_vertex(self).map(|v_id| (v_id, he_id))
44 } else {
45 None
46 }
47 })
48 .collect::<Vec<_>>();
49
50 for (boundary_vertex_id, boundary_he_id) in boundary_pairs {
51 if let Some(vertex) = self.vertices.get_mut(boundary_vertex_id) {
52 vertex.outgoing_halfedge = Some(boundary_he_id);
53 } else {
54 error!("Vertex not found");
55 }
56 }
57 }
58}