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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
use crate::geom::{self, Vector3};
use crate::math::{BaseFloat, Euler, Rad};
use daggy;
pub type Index = daggy::EdgeIndex<usize>;
pub type Indices = daggy::EdgeIndices<usize>;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Edge<S = geom::scalar::Default> {
pub kind: Kind,
pub weight: S,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Kind {
pub axis: Axis,
pub relative: Relative,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Axis {
X,
Y,
Z,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Relative {
Position,
Orientation,
Scale,
}
impl Kind {
pub fn new(axis: Axis, relative: Relative) -> Self {
Kind { axis, relative }
}
pub fn x(relative: Relative) -> Self {
Kind::new(Axis::X, relative)
}
pub fn y(relative: Relative) -> Self {
Kind::new(Axis::Y, relative)
}
pub fn z(relative: Relative) -> Self {
Kind::new(Axis::Z, relative)
}
pub fn position(axis: Axis) -> Self {
let relative = Relative::Position;
Kind { axis, relative }
}
pub fn orientation(axis: Axis) -> Self {
let relative = Relative::Orientation;
Kind { axis, relative }
}
pub fn scale(axis: Axis) -> Self {
let relative = Relative::Scale;
Kind { axis, relative }
}
pub fn x_position() -> Self {
Kind::x(Relative::Position)
}
pub fn x_orientation() -> Self {
Kind::x(Relative::Orientation)
}
pub fn x_scale() -> Self {
Kind::x(Relative::Scale)
}
pub fn y_position() -> Self {
Kind::y(Relative::Position)
}
pub fn y_orientation() -> Self {
Kind::y(Relative::Orientation)
}
pub fn y_scale() -> Self {
Kind::y(Relative::Scale)
}
pub fn z_position() -> Self {
Kind::z(Relative::Position)
}
pub fn z_orientation() -> Self {
Kind::z(Relative::Orientation)
}
pub fn z_scale() -> Self {
Kind::z(Relative::Scale)
}
}
impl<S> Edge<S> {
pub fn new(kind: Kind, weight: S) -> Self {
Edge { kind, weight }
}
pub fn x(relative: Relative, weight: S) -> Self {
Edge::new(Kind::x(relative), weight)
}
pub fn y(relative: Relative, weight: S) -> Self {
Edge::new(Kind::y(relative), weight)
}
pub fn z(relative: Relative, weight: S) -> Self {
Edge::new(Kind::z(relative), weight)
}
pub fn position(axis: Axis, weight: S) -> Self {
Edge::new(Kind::position(axis), weight)
}
pub fn orientation(axis: Axis, weight: S) -> Self {
Edge::new(Kind::orientation(axis), weight)
}
pub fn scale(axis: Axis, weight: S) -> Self {
Edge::new(Kind::scale(axis), weight)
}
pub fn x_position(weight: S) -> Self {
Edge::new(Kind::x_position(), weight)
}
pub fn x_orientation(weight: S) -> Self {
Edge::new(Kind::x_orientation(), weight)
}
pub fn x_scale(weight: S) -> Self {
Edge::new(Kind::x_scale(), weight)
}
pub fn y_position(weight: S) -> Self {
Edge::new(Kind::y_position(), weight)
}
pub fn y_orientation(weight: S) -> Self {
Edge::new(Kind::y_orientation(), weight)
}
pub fn y_scale(weight: S) -> Self {
Edge::new(Kind::y_scale(), weight)
}
pub fn z_position(weight: S) -> Self {
Edge::new(Kind::z_position(), weight)
}
pub fn z_orientation(weight: S) -> Self {
Edge::new(Kind::z_orientation(), weight)
}
pub fn z_scale(weight: S) -> Self {
Edge::new(Kind::z_scale(), weight)
}
}
pub fn displace<S>(v: Vector3<S>) -> [Edge<S>; 3] {
[
Edge::x_position(v.x),
Edge::y_position(v.y),
Edge::z_position(v.z),
]
}
pub fn rotate<S: BaseFloat>(e: Euler<Rad<S>>) -> [Edge<S>; 3] {
[
Edge::x_orientation(e.x.0),
Edge::y_orientation(e.x.0),
Edge::z_orientation(e.z.0),
]
}
pub fn scale<S: Copy>(scale: S) -> [Edge<S>; 3] {
[
Edge::x_scale(scale),
Edge::y_scale(scale),
Edge::z_scale(scale),
]
}