Skip to content

Commit 5867bc0

Browse files
committed
* Add test for multiple selected edges
* Split params into two variables
1 parent 9d6435c commit 5867bc0

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

cadquery/sketch.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,31 +398,27 @@ def distribute(
398398
else:
399399
trimmed = True
400400

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+
]
408409

409410
locs = []
410411
for el in self._selection:
411412
if isinstance(el, (Wire, Edge)):
413+
if el.IsClosed() and not trimmed:
414+
params = params_closed
415+
else:
416+
params = params_open
417+
412418
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,))
419420
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))
426422
else:
427423
raise ValueError(f"Unsupported selection: {el}")
428424

tests/test_sketch.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ def test_distribute():
154154
(3.358757210636101, -3.005203820042827, 0.0)
155155
)
156156

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+
157180

158181
def test_rarray():
159182

0 commit comments

Comments
 (0)