@@ -11,19 +11,27 @@ use bezier_rs::{Cap, Join, Subpath, SubpathTValue, TValue};
11
11
use glam:: { DAffine2 , DVec2 } ;
12
12
use rand:: { Rng , SeedableRng } ;
13
13
14
+ /// Implemented for types that can be converted to an iterator of vector data.
15
+ /// Used for the fill and stroke node so they can be used on VectorData or GraphicGroup
14
16
trait VectorIterMut {
15
- fn vector_iter_mut ( & mut self ) -> impl ExactSizeIterator < Item = & mut VectorData > ;
17
+ fn vector_iter_mut ( & mut self ) -> impl Iterator < Item = ( & mut VectorData , DAffine2 ) > ;
16
18
}
17
19
18
20
impl VectorIterMut for GraphicGroup {
19
- fn vector_iter_mut ( & mut self ) -> impl ExactSizeIterator < Item = & mut VectorData > {
20
- self . iter_mut ( ) . filter_map ( |( element, _) | element. as_vector_data_mut ( ) ) . collect :: < Vec < _ > > ( ) . into_iter ( )
21
+ fn vector_iter_mut ( & mut self ) -> impl Iterator < Item = ( & mut VectorData , DAffine2 ) > {
22
+ let parent_transform = self . transform ;
23
+ // Grab only the direct children (perhaps unintuitive?)
24
+ self . iter_mut ( ) . filter_map ( |( element, _) | element. as_vector_data_mut ( ) ) . map ( move |vector| {
25
+ let transform = parent_transform * vector. transform ;
26
+ ( vector, transform)
27
+ } )
21
28
}
22
29
}
23
30
24
31
impl VectorIterMut for VectorData {
25
- fn vector_iter_mut ( & mut self ) -> impl ExactSizeIterator < Item = & mut VectorData > {
26
- std:: iter:: once ( self )
32
+ fn vector_iter_mut ( & mut self ) -> impl Iterator < Item = ( & mut VectorData , DAffine2 ) > {
33
+ let transform = self . transform ;
34
+ std:: iter:: once ( ( self , transform) )
27
35
}
28
36
}
29
37
@@ -51,13 +59,12 @@ async fn assign_colors<F: 'n + Send, T: VectorIterMut>(
51
59
repeat_every : u32 ,
52
60
) -> T {
53
61
let mut input = vector_group. eval ( footprint) . await ;
54
- let vector_data = input. vector_iter_mut ( ) ;
55
- let length = vector_data. len ( ) ;
62
+ let length = input. vector_iter_mut ( ) . count ( ) ;
56
63
let gradient = if reverse { gradient. reversed ( ) } else { gradient } ;
57
64
58
65
let mut rng = rand:: rngs:: StdRng :: seed_from_u64 ( seed. into ( ) ) ;
59
66
60
- for ( i, vector_data) in vector_data . enumerate ( ) {
67
+ for ( i, ( vector_data, _ ) ) in input . vector_iter_mut ( ) . enumerate ( ) {
61
68
let factor = match randomize {
62
69
true => rng. gen :: < f64 > ( ) ,
63
70
false => match repeat_every {
@@ -82,12 +89,23 @@ async fn assign_colors<F: 'n + Send, T: VectorIterMut>(
82
89
}
83
90
84
91
#[ node_macro:: node( category( "Vector: Style" ) , path( graphene_core:: vector) ) ]
85
- async fn fill < F : ' n + Send , T : Into < Fill > + ' n + Send > (
92
+ async fn fill < F : ' n + Send , FillTy : Into < Fill > + ' n + Send , TargetTy : VectorIterMut + ' n + Send > (
86
93
#[ implementations(
87
94
( ) ,
88
95
( ) ,
89
96
( ) ,
90
97
( ) ,
98
+ ( ) ,
99
+ ( ) ,
100
+ ( ) ,
101
+ ( ) ,
102
+ Footprint ,
103
+ Footprint ,
104
+ Footprint ,
105
+ Footprint ,
106
+ Footprint ,
107
+ Footprint ,
108
+ Footprint ,
91
109
Footprint ,
92
110
) ]
93
111
footprint : F ,
@@ -96,9 +114,20 @@ async fn fill<F: 'n + Send, T: Into<Fill> + 'n + Send>(
96
114
( ) -> VectorData ,
97
115
( ) -> VectorData ,
98
116
( ) -> VectorData ,
117
+ ( ) -> GraphicGroup ,
118
+ ( ) -> GraphicGroup ,
119
+ ( ) -> GraphicGroup ,
120
+ ( ) -> GraphicGroup ,
121
+ Footprint -> VectorData ,
122
+ Footprint -> VectorData ,
123
+ Footprint -> VectorData ,
99
124
Footprint -> VectorData ,
125
+ Footprint -> GraphicGroup ,
126
+ Footprint -> GraphicGroup ,
127
+ Footprint -> GraphicGroup ,
128
+ Footprint -> GraphicGroup ,
100
129
) ]
101
- vector_data : impl Node < F , Output = VectorData > ,
130
+ vector_data : impl Node < F , Output = TargetTy > ,
102
131
#[ implementations(
103
132
Fill ,
104
133
Option <Color >,
@@ -108,59 +137,88 @@ async fn fill<F: 'n + Send, T: Into<Fill> + 'n + Send>(
108
137
Option <Color >,
109
138
Color ,
110
139
Gradient ,
140
+ Fill ,
141
+ Option <Color >,
142
+ Color ,
143
+ Gradient ,
144
+ Fill ,
145
+ Option <Color >,
146
+ Color ,
147
+ Gradient ,
111
148
) ]
112
149
#[ default ( Color :: BLACK ) ]
113
- fill : T ,
150
+ fill : FillTy ,
114
151
_backup_color : Option < Color > ,
115
152
_backup_gradient : Gradient ,
116
- ) -> VectorData {
117
- let mut vector_data = vector_data. eval ( footprint) . await ;
118
- vector_data. style . set_fill ( fill. into ( ) ) ;
153
+ ) -> TargetTy {
154
+ let mut target = vector_data. eval ( footprint) . await ;
155
+ let fill: Fill = fill. into ( ) ;
156
+ for ( target, _transform) in target. vector_iter_mut ( ) {
157
+ target. style . set_fill ( fill. clone ( ) ) ;
158
+ }
119
159
120
- vector_data
160
+ target
121
161
}
122
162
123
163
#[ node_macro:: node( category( "Vector: Style" ) , path( graphene_core:: vector) ) ]
124
- async fn stroke < F : ' n + Send , T : Into < Option < Color > > + ' n + Send > (
164
+ async fn stroke < F : ' n + Send , ColourTy : Into < Option < Color > > + ' n + Send , TargetTy : VectorIterMut + ' n + Send > (
125
165
#[ implementations(
126
166
( ) ,
127
167
( ) ,
168
+ ( ) ,
169
+ ( ) ,
170
+ Footprint ,
171
+ Footprint ,
172
+ Footprint ,
128
173
Footprint ,
129
174
) ]
130
175
footprint : F ,
131
176
#[ implementations(
132
177
( ) -> VectorData ,
133
178
( ) -> VectorData ,
179
+ ( ) -> GraphicGroup ,
180
+ ( ) -> GraphicGroup ,
134
181
Footprint -> VectorData ,
182
+ Footprint -> VectorData ,
183
+ Footprint -> GraphicGroup ,
184
+ Footprint -> GraphicGroup ,
135
185
) ]
136
- vector_data : impl Node < F , Output = VectorData > ,
186
+ vector_data : impl Node < F , Output = TargetTy > ,
137
187
#[ implementations(
138
188
Option <Color >,
139
189
Color ,
140
190
Option <Color >,
141
191
Color ,
192
+ Option <Color >,
193
+ Color ,
194
+ Option <Color >,
195
+ Color ,
142
196
) ]
143
197
#[ default ( Color :: BLACK ) ]
144
- color : T ,
198
+ color : ColourTy ,
145
199
#[ default( 2. ) ] weight : f64 ,
146
200
dash_lengths : Vec < f64 > ,
147
201
dash_offset : f64 ,
148
202
line_cap : crate :: vector:: style:: LineCap ,
149
203
line_join : LineJoin ,
150
204
#[ default( 4. ) ] miter_limit : f64 ,
151
- ) -> VectorData {
152
- let mut vector_data = vector_data. eval ( footprint) . await ;
153
- vector_data . style . set_stroke ( Stroke {
205
+ ) -> TargetTy {
206
+ let mut target = vector_data. eval ( footprint) . await ;
207
+ let stroke = Stroke {
154
208
color : color. into ( ) ,
155
209
weight,
156
210
dash_lengths,
157
211
dash_offset,
158
212
line_cap,
159
213
line_join,
160
214
line_join_miter_limit : miter_limit,
161
- transform : vector_data. transform ,
162
- } ) ;
163
- vector_data
215
+ transform : DAffine2 :: IDENTITY ,
216
+ } ;
217
+ for ( target, transform) in target. vector_iter_mut ( ) {
218
+ target. style . set_stroke ( Stroke { transform, ..stroke. clone ( ) } ) ;
219
+ }
220
+
221
+ target
164
222
}
165
223
166
224
#[ node_macro:: node( category( "Vector" ) , path( graphene_core:: vector) ) ]
0 commit comments