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

use crate::{
    objects::Objects,
    partial::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex},
    validate::ValidationError,
};

use super::TransformObject;

impl TransformObject for PartialVertex {
    fn transform(
        self,
        transform: &Transform,
        objects: &Objects,
    ) -> Result<Self, ValidationError> {
        let curve = self.curve().transform(transform, objects)?;
        let surface_form = self
            .surface_form()
            .into_partial()
            .transform(transform, objects)?;

        // Don't need to transform `self.position`, as that is in curve
        // coordinates and thus transforming the curve takes care of it.
        Ok(Self::default()
            .with_position(self.position())
            .with_curve(curve)
            .with_surface_form(surface_form))
    }
}

impl TransformObject for PartialSurfaceVertex {
    fn transform(
        self,
        transform: &Transform,
        objects: &Objects,
    ) -> Result<Self, ValidationError> {
        let surface = self
            .surface()
            .map(|surface| surface.transform(transform, objects))
            .transpose()?;
        let global_form = self.global_form().transform(transform, objects)?;

        // Don't need to transform `self.position`, as that is in surface
        // coordinates and thus transforming the surface takes care of it.
        Ok(Self::default()
            .with_position(self.position())
            .with_surface(surface)
            .with_global_form(Some(global_form)))
    }
}

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

        Ok(Self::default().with_position(position))
    }
}