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
use crate::{
    objects::{Face, Region},
    operations::build::Polygon,
    storage::Handle,
};

/// Update a [`Face`]
pub trait UpdateFace {
    /// Update the region of the face
    #[must_use]
    fn update_region(
        &self,
        update: impl FnOnce(&Handle<Region>) -> Handle<Region>,
    ) -> Self;
}

impl UpdateFace for Face {
    fn update_region(
        &self,
        update: impl FnOnce(&Handle<Region>) -> Handle<Region>,
    ) -> Self {
        let region = update(self.region());
        Face::new(self.surface().clone(), region)
    }
}

impl<const D: usize> UpdateFace for Polygon<D> {
    fn update_region(
        &self,
        update: impl FnOnce(&Handle<Region>) -> Handle<Region>,
    ) -> Self {
        self.replace_face(self.face.update_region(update))
    }
}