File tree Expand file tree Collapse file tree 2 files changed +38
-19
lines changed Expand file tree Collapse file tree 2 files changed +38
-19
lines changed Original file line number Diff line number Diff line change @@ -398,31 +398,27 @@ def distribute(
398
398
else :
399
399
trimmed = True
400
400
401
- params = (
402
- (start + i * (stop - start ) / n for i in range (n )),
403
- (
404
- start + i * (stop - start ) / (n - 1 ) if n - 1 > 0 else start
405
- for i in range (n )
406
- ),
407
- )
401
+ # closed edge or wire parameters
402
+ params_closed = [start + i * (stop - start ) / n for i in range (n )]
403
+
404
+ # open or trimmed edge or wire parameters
405
+ params_open = [
406
+ start + i * (stop - start ) / (n - 1 ) if n - 1 > 0 else start
407
+ for i in range (n )
408
+ ]
408
409
409
410
locs = []
410
411
for el in self ._selection :
411
412
if isinstance (el , (Wire , Edge )):
413
+ if el .IsClosed () and not trimmed :
414
+ params = params_closed
415
+ else :
416
+ params = params_open
417
+
412
418
if rotate :
413
- locs .extend (
414
- el .locations (
415
- params [0 if el .IsClosed () and not trimmed else 1 ],
416
- planar = True ,
417
- )
418
- )
419
+ locs .extend (el .locations (params , planar = True ,))
419
420
else :
420
- locs .extend (
421
- Location (v )
422
- for v in el .positions (
423
- params [0 if el .IsClosed () and not trimmed else 1 ]
424
- )
425
- )
421
+ locs .extend (Location (v ) for v in el .positions (params ))
426
422
else :
427
423
raise ValueError (f"Unsupported selection: { el } " )
428
424
Original file line number Diff line number Diff line change @@ -154,6 +154,29 @@ def test_distribute():
154
154
(3.358757210636101 , - 3.005203820042827 , 0.0 )
155
155
)
156
156
157
+ s5 = (
158
+ Sketch ()
159
+ .arc ((0 , 2 ), 4 , 0 , 90 )
160
+ .arc ((0 , - 2 ), 4 , 0 , - 90 )
161
+ .edges ()
162
+ .distribute (4 , 0 , 1 )
163
+ .circle (0.5 )
164
+ )
165
+
166
+ assert len (s5 ._selection ) == approx (8 )
167
+
168
+ s5 .reset ().faces (">X" ).faces (">Y" )
169
+
170
+ assert s5 ._selection [0 ].Center ().toTuple () == approx ((4.0 , 2.0 , 0.0 ))
171
+
172
+ s5 .reset ().faces (">X" ).faces ("<Y" )
173
+
174
+ assert s5 ._selection [0 ].Center ().toTuple () == approx ((4.0 , - 2.0 , 0.0 ))
175
+
176
+ s5 .reset ().faces (">Y" )
177
+
178
+ assert s5 ._selection [0 ].Center ().toTuple () == approx ((0.0 , 6.0 , 0.0 ))
179
+
157
180
158
181
def test_rarray ():
159
182
You can’t perform that action at this time.
0 commit comments