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

use crate::{
    objects::{GlobalVertex, SurfaceVertex, Vertex},
    partial::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex},
    stores::Stores,
};

use super::TransformObject;

impl TransformObject for Vertex {
    fn transform(self, transform: &Transform, stores: &Stores) -> Self {
        let curve = self.curve().clone().transform(transform, stores);
        let surface_form =
            self.surface_form().clone().transform(transform, stores);
        let global_form = self.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::new(self.position(), curve, surface_form, global_form)
    }
}

impl TransformObject for SurfaceVertex {
    fn transform(self, transform: &Transform, stores: &Stores) -> Self {
        let surface = self.surface().clone().transform(transform, stores);
        let global_form = self.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::new(self.position(), surface, global_form)
    }
}

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

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.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 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 }
    }
}