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
use fj_interop::ext::ArrayExt;
use fj_math::Transform;

use crate::{
    objects::Objects,
    partial::{MaybePartial, PartialGlobalEdge, PartialHalfEdge},
    validate::ValidationError,
};

use super::TransformObject;

impl TransformObject for PartialHalfEdge {
    fn transform(
        self,
        transform: &Transform,
        objects: &Objects,
    ) -> Result<Self, ValidationError> {
        let curve: MaybePartial<_> = self
            .curve()
            .into_partial()
            .transform(transform, objects)?
            .into();
        let vertices = self.vertices().try_map_ext(
            |vertex| -> Result<_, ValidationError> {
                Ok(vertex
                    .into_partial()
                    .transform(transform, objects)?
                    .with_curve(curve.clone()))
            },
        )?;
        let global_form = self
            .global_form()
            .into_partial()
            .transform(transform, objects)?
            .with_curve(curve.global_form());

        Ok(Self::default()
            .with_curve(curve)
            .with_vertices(vertices)
            .with_global_form(global_form))
    }
}

impl TransformObject for PartialGlobalEdge {
    fn transform(
        self,
        transform: &Transform,
        objects: &Objects,
    ) -> Result<Self, ValidationError> {
        let curve = self.curve().transform(transform, objects)?;
        let vertices = self
            .vertices()
            .map(|vertices| {
                vertices.try_map_ext(|vertex| -> Result<_, ValidationError> {
                    vertex.transform(transform, objects)
                })
            })
            .transpose()?;

        Ok(Self::default()
            .with_curve(Some(curve))
            .with_vertices(vertices))
    }
}