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

use crate::{
    objects::Objects,
    partial::{PartialCurve, PartialGlobalCurve},
    validate::ValidationError,
};

use super::TransformObject;

impl TransformObject for PartialGlobalCurve {
    fn transform(
        self,
        _: &Transform,
        _: &Objects,
    ) -> Result<Self, ValidationError> {
        // `GlobalCurve` doesn't contain any internal geometry. If it did, that
        // would just be redundant with the geometry of other objects, and this
        // other geometry is already being transformed by other implementations
        // of this trait.
        Ok(self)
    }
}

impl TransformObject for PartialCurve {
    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()
            .map(|global_form| global_form.transform(transform, objects))
            .transpose()?;

        // Don't need to transform `self.path`, as that's defined in surface
        // coordinates, and thus transforming `surface` takes care of it.
        Ok(Self::default()
            .with_surface(surface)
            .with_path(self.path())
            .with_global_form(global_form))
    }
}