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

use crate::{
    objects::{GlobalVertex, Objects, SurfaceVertex, Vertex},
    services::Service,
};

use super::{TransformCache, TransformObject};

impl TransformObject for Vertex {
    fn transform_with_cache(
        self,
        transform: &Transform,
        objects: &mut Service<Objects>,
        cache: &mut TransformCache,
    ) -> Self {
        // Don't need to transform position, as that is defined in curve
        // coordinates and thus transforming the curve takes care of it.
        let position = self.position();

        let curve = self
            .curve()
            .clone()
            .transform_with_cache(transform, objects, cache);
        let surface_form = self
            .surface_form()
            .clone()
            .transform_with_cache(transform, objects, cache);

        Self::new(position, curve, surface_form)
    }
}

impl TransformObject for SurfaceVertex {
    fn transform_with_cache(
        self,
        transform: &Transform,
        objects: &mut Service<Objects>,
        cache: &mut TransformCache,
    ) -> Self {
        // Don't need to transform position, as that is defined in surface
        // coordinates and thus transforming the surface takes care of it.
        let position = self.position();

        let surface = self
            .surface()
            .clone()
            .transform_with_cache(transform, objects, cache);
        let global_form = self
            .global_form()
            .clone()
            .transform_with_cache(transform, objects, cache);

        Self::new(position, surface, global_form)
    }
}

impl TransformObject for GlobalVertex {
    fn transform_with_cache(
        self,
        transform: &Transform,
        _: &mut Service<Objects>,
        _: &mut TransformCache,
    ) -> Self {
        let position = transform.transform_point(&self.position());
        Self::new(position)
    }
}