fj_core/operations/update/
half_edge.rs

1use crate::{
2    objects::{Curve, HalfEdge, Vertex},
3    operations::{derive::DeriveFrom, insert::Insert},
4    storage::Handle,
5    Core,
6};
7
8/// Update a [`HalfEdge`]
9pub trait UpdateHalfEdge {
10    /// Update the curve of the edge
11    #[must_use]
12    fn update_curve<T>(
13        &self,
14        update: impl FnOnce(&Handle<Curve>, &mut Core) -> T,
15        core: &mut Core,
16    ) -> Self
17    where
18        T: Insert<Inserted = Handle<Curve>>;
19
20    /// Update the start vertex of the edge
21    #[must_use]
22    fn update_start_vertex<T>(
23        &self,
24        update: impl FnOnce(&Handle<Vertex>, &mut Core) -> T,
25        core: &mut Core,
26    ) -> Self
27    where
28        T: Insert<Inserted = Handle<Vertex>>;
29}
30
31impl UpdateHalfEdge for HalfEdge {
32    fn update_curve<T>(
33        &self,
34        update: impl FnOnce(&Handle<Curve>, &mut Core) -> T,
35        core: &mut Core,
36    ) -> Self
37    where
38        T: Insert<Inserted = Handle<Curve>>,
39    {
40        HalfEdge::new(
41            self.path(),
42            self.boundary(),
43            update(self.curve(), core)
44                .insert(core)
45                .derive_from(self.curve(), core),
46            self.start_vertex().clone(),
47        )
48    }
49
50    fn update_start_vertex<T>(
51        &self,
52        update: impl FnOnce(&Handle<Vertex>, &mut Core) -> T,
53        core: &mut Core,
54    ) -> Self
55    where
56        T: Insert<Inserted = Handle<Vertex>>,
57    {
58        HalfEdge::new(
59            self.path(),
60            self.boundary(),
61            self.curve().clone(),
62            update(self.start_vertex(), core)
63                .insert(core)
64                .derive_from(self.start_vertex(), core),
65        )
66    }
67}