Skip to main content

geop_core_topology/euler/
mvr.rs

1use crate::{FaceId, Model, Vertex, VertexId, boundary::BoundaryType};
2use geop_core_math::{
3    geop_error::{GeopError, GeopResult, WithContext},
4    scalars::Scalar,
5    vector::Vector3,
6};
7
8impl<S: Scalar> Model<S> {
9    // Add a new bare vertex at `point` as a fresh boundary of `face_id` (e.g. to
10    // later grow a hole loop off of via `mve_from_vertex`). Returns the new vertex.
11    pub fn mvr(self: &mut Model<S>, face_id: FaceId, point: Vector3<S>) -> GeopResult<VertexId> {
12        let ctx =
13            |e: GeopError| e.with_context(format!("Model::mvr(face_id={face_id}, point={point})"));
14
15        self.get_face(face_id).with_context(&ctx)?;
16
17        let vertex_id = self.insert_vertex(Vertex { point });
18        self.faces
19            .get_mut(&face_id)
20            .unwrap()
21            .holes
22            .push(BoundaryType::Vertex(vertex_id));
23
24        Ok(vertex_id)
25    }
26}