1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use fj_math::Point;

use crate::{
    geometry::{CurveBoundary, SurfacePath},
    objects::{Curve, HalfEdge, Vertex},
    storage::Handle,
};

/// Update a [`HalfEdge`]
pub trait UpdateHalfEdge {
    /// Update the path of the edge
    #[must_use]
    fn update_path(
        &self,
        update: impl FnOnce(SurfacePath) -> SurfacePath,
    ) -> Self;

    /// Update the boundary of the edge
    #[must_use]
    fn update_boundary(
        &self,
        update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
    ) -> Self;

    /// Update the curve of the edge
    #[must_use]
    fn update_curve(
        &self,
        update: impl FnOnce(&Handle<Curve>) -> Handle<Curve>,
    ) -> Self;

    /// Update the start vertex of the edge
    #[must_use]
    fn update_start_vertex(
        &self,
        update: impl FnOnce(&Handle<Vertex>) -> Handle<Vertex>,
    ) -> Self;
}

impl UpdateHalfEdge for HalfEdge {
    fn update_path(
        &self,
        update: impl FnOnce(SurfacePath) -> SurfacePath,
    ) -> Self {
        HalfEdge::new(
            update(self.path()),
            self.boundary(),
            self.curve().clone(),
            self.start_vertex().clone(),
        )
    }

    fn update_boundary(
        &self,
        update: impl FnOnce(CurveBoundary<Point<1>>) -> CurveBoundary<Point<1>>,
    ) -> Self {
        HalfEdge::new(
            self.path(),
            update(self.boundary()),
            self.curve().clone(),
            self.start_vertex().clone(),
        )
    }

    fn update_curve(
        &self,
        update: impl FnOnce(&Handle<Curve>) -> Handle<Curve>,
    ) -> Self {
        HalfEdge::new(
            self.path(),
            self.boundary(),
            update(self.curve()),
            self.start_vertex().clone(),
        )
    }

    fn update_start_vertex(
        &self,
        update: impl FnOnce(&Handle<Vertex>) -> Handle<Vertex>,
    ) -> Self {
        HalfEdge::new(
            self.path(),
            self.boundary(),
            self.curve().clone(),
            update(self.start_vertex()),
        )
    }
}