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
91
92
93
94
95
96
97
98
mod curve;
mod cycle;
mod edge;
mod face;
mod shell;
mod sketch;
mod solid;
mod surface;
mod vertex;
use fj_math::{Transform, Vector};
use crate::{
objects::Objects,
partial::{HasPartial, MaybePartial, Partial},
storage::Handle,
validate::ValidationError,
};
pub trait TransformObject: Sized {
fn transform(
self,
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError>;
fn translate(
self,
offset: impl Into<Vector<3>>,
objects: &Objects,
) -> Result<Self, ValidationError> {
self.transform(&Transform::translation(offset), objects)
}
fn rotate(
self,
axis_angle: impl Into<Vector<3>>,
objects: &Objects,
) -> Result<Self, ValidationError> {
self.transform(&Transform::rotation(axis_angle), objects)
}
}
impl<T> TransformObject for Handle<T>
where
T: HasPartial,
T::Partial: TransformObject,
{
fn transform(
self,
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError> {
self.to_partial()
.transform(transform, objects)?
.build(objects)
}
}
impl<T> TransformObject for MaybePartial<T>
where
T: HasPartial,
Handle<T>: TransformObject,
T::Partial: TransformObject,
{
fn transform(
self,
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError> {
match self {
Self::Full(full) => {
Ok(Self::Full(full.transform(transform, objects)?))
}
Self::Partial(partial) => {
Ok(Self::Partial(partial.transform(transform, objects)?))
}
}
}
}