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

use crate::{
    partial::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex},
    stores::Stores,
};

use super::TransformObject;

impl TransformObject for PartialVertex {
    fn transform(self, transform: &Transform, stores: &Stores) -> Self {
        let curve = self.curve.map(|curve| curve.transform(transform, stores));
        let surface_form = self.surface_form.map(|surface_form| {
            surface_form
                .into_partial()
                .transform(transform, stores)
                .into()
        });
        let global_form = self
            .global_form
            .map(|global_form| global_form.transform(transform, stores));

        // Don't need to transform `self.position`, as that is in curve
        // coordinates and thus transforming the curve takes care of it.
        Self {
            position: self.position,
            curve,
            surface_form,
            global_form,
        }
    }
}

impl TransformObject for PartialSurfaceVertex {
    fn transform(self, transform: &Transform, stores: &Stores) -> Self {
        let surface = self
            .surface
            .map(|surface| surface.transform(transform, stores));
        let global_form = self
            .global_form
            .map(|global_form| global_form.transform(transform, stores));

        // Don't need to transform `self.position`, as that is in surface
        // coordinates and thus transforming the surface takes care of it.
        Self {
            position: self.position,
            surface,
            global_form,
        }
    }
}

impl TransformObject for PartialGlobalVertex {
    fn transform(self, transform: &Transform, _: &Stores) -> Self {
        let position = self
            .position
            .map(|position| transform.transform_point(&position));

        Self { position }
    }
}