Skip to main content

geop_core_topology/euler/
replace_pcurve.rs

1use crate::{CoedgeId, Model, argument_validation::validate_pcurve_start_and_end};
2use geop_core_geometry::nurb_curve::NurbCurve2D;
3use geop_core_math::{
4    geop_error::{GeopError, GeopResult, WithContext},
5    scalars::Scalar,
6};
7
8impl<S: Scalar> Model<S> {
9    // Swap `coedge_id`'s pcurve for `pcurve` — e.g. fixing up a coedge that
10    // `mer` just moved onto a different face, whose old pcurve (valid for
11    // whatever face it used to sit on) has no reason to still be valid for
12    // its new one. `pcurve` must still land on the coedge's actual edge's
13    // 3-D endpoints under its (current) face's surface, checked before
14    // anything is mutated, so a rejected swap leaves the model untouched.
15    pub fn replace_pcurve(
16        self: &mut Model<S>,
17        coedge_id: CoedgeId,
18        pcurve: NurbCurve2D<S>,
19    ) -> GeopResult<()> {
20        let ctx = |e: GeopError| {
21            e.with_context(format!(
22                "Model::replace_pcurve(coedge_id={coedge_id}, pcurve={pcurve})"
23            ))
24        };
25
26        let coedge = self.get_coedge(coedge_id)?.clone();
27        let face = self.get_face(coedge.face)?.clone();
28        let start = self.coedge_start_vertex(coedge_id)?.clone();
29        let end = self.coedge_end_vertex(coedge_id)?.clone();
30        validate_pcurve_start_and_end(&face.surface, &pcurve, &start.point, &end.point)
31            .with_context(&ctx)?;
32
33        self.get_coedge_mut(coedge_id)?.pcurve = pcurve;
34        Ok(())
35    }
36}