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
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 surface = self
            .surface
            .map(|surface| surface.transform(transform, objects))
            .transpose()?;
        let curve: MaybePartial<_> = self
            .curve
            .clone()
            .into_partial()
            .transform(transform, objects)?
            .with_surface(surface.clone())
            .into();
        let vertices = self.vertices.clone().try_map_ext(
            |vertex| -> Result<_, ValidationError> {
                Ok(vertex
                    .into_partial()
                    .transform(transform, objects)?
                    .with_curve(Some(curve.clone()))
                    .into())
            },
        )?;
        let global_form = self
            .global_form
            .into_partial()
            .transform(transform, objects)?
            .with_curve(curve.global_form())
            .into();

        Ok(Self {
            surface,
            curve,
            vertices,
            global_form,
        })
    }
}

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

        Ok(Self {
            curve: curve.map(Into::into),
            vertices,
        })
    }
}