fj_core/operations/geometry/
half_edge.rs1use fj_math::Point;
2
3use crate::{
4 geometry::{CurveBoundary, Geometry, HalfEdgeGeometry, SurfacePath},
5 layers::Layer,
6 objects::HalfEdge,
7 operations::insert::Insert,
8 storage::Handle,
9 Core,
10};
11
12pub trait UpdateHalfEdgeGeometry {
14 fn set_path(
16 self,
17 path: SurfacePath,
18 geometry: &mut Layer<Geometry>,
19 ) -> Self;
20
21 #[must_use]
23 fn update_path(
24 &self,
25 update: impl FnOnce(SurfacePath) -> SurfacePath,
26 core: &mut Core,
27 ) -> Self;
28
29 #[must_use]
31 fn update_boundary(
32 &self,
33 update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
34 core: &mut Core,
35 ) -> Self;
36}
37
38impl UpdateHalfEdgeGeometry for Handle<HalfEdge> {
39 fn set_path(
40 self,
41 path: SurfacePath,
42 geometry: &mut Layer<Geometry>,
43 ) -> Self {
44 geometry.define_half_edge(self.clone(), HalfEdgeGeometry { path });
45 self
46 }
47
48 fn update_path(
49 &self,
50 update: impl FnOnce(SurfacePath) -> SurfacePath,
51 core: &mut Core,
52 ) -> Self {
53 let path = update(core.layers.geometry.of_half_edge(self).path);
54
55 let half_edge = HalfEdge::new(
56 path,
57 self.boundary(),
58 self.curve().clone(),
59 self.start_vertex().clone(),
60 )
61 .insert(core);
62
63 core.layers
64 .geometry
65 .define_half_edge(half_edge.clone(), HalfEdgeGeometry { path });
66
67 half_edge
68 }
69
70 fn update_boundary(
71 &self,
72 update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
73 core: &mut Core,
74 ) -> Self {
75 HalfEdge::new(
76 core.layers.geometry.of_half_edge(self).path,
77 update(self.boundary()),
78 self.curve().clone(),
79 self.start_vertex().clone(),
80 )
81 .insert(core)
82 }
83}