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

use crate::{
    objects::{GlobalCurve, Objects},
    partial::PartialCurve,
    storage::Handle,
    validate::ValidationError,
};

use super::TransformObject;

impl TransformObject for Handle<GlobalCurve> {
    fn transform(
        self,
        _: &Transform,
        objects: &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.
        //
        // All we need to do here is create a new `GlobalCurve` instance, to
        // make sure the transformed `GlobalCurve` has a different identity than
        // the original one.
        Ok(objects.global_curves.insert(GlobalCurve)?)
    }
}

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.0.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 {
            surface,
            path: self.path,
            global_form: global_form.map(Into::into),
        })
    }
}