Skip to content

Commit 73a4d7d

Browse files
committed
* Remove nested function
* Add module level TOL
1 parent 04c289a commit 73a4d7d

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

cadquery/sketch.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
Modes = Literal["a", "s", "i", "c"] # add, subtract, intersect, construct
3939
Point = Union[Vector, Tuple[Real, Real]]
40+
TOL = 1e-6
4041

4142
T = TypeVar("T", bound="Sketch")
4243
SketchVal = Union[Shape, Location]
@@ -346,7 +347,7 @@ def parray(self: T, r: Real, a1: Real, da: Real, n: int, rotate: bool = True) ->
346347

347348
locs = []
348349

349-
if abs(remainder(da, 360)) < 1e-6:
350+
if abs(remainder(da, 360)) < TOL:
350351
angle = da / n
351352
else:
352353
angle = da / (n - 1) if n > 1 else a1
@@ -392,32 +393,35 @@ def distribute(
392393
if not self._selection:
393394
raise ValueError("Nothing selected to distribute over")
394395

395-
if 1 - abs(stop - start) < 1e-6:
396+
if 1 - abs(stop - start) < TOL:
396397
trimmed = False
397398
else:
398399
trimmed = True
399400

400-
def params(closed: bool = True, trimmed: bool = True):
401-
if closed and not trimmed:
402-
rv = [start + i * (stop - start) / n for i in range(n)]
403-
else:
404-
rv = [
405-
start + i * (stop - start) / (n - 1) if n - 1 > 0 else start
406-
for i in range(n)
407-
]
408-
return rv
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+
]
409408

410409
locs = []
411410
for el in self._selection:
412411
if isinstance(el, (Wire, Edge)):
413412
if rotate:
414413
locs.extend(
415-
el.locations(params(el.IsClosed(), trimmed), planar=True)
414+
el.locations(
415+
params[0 if el.IsClosed() and not trimmed else 1],
416+
planar=True,
417+
)
416418
)
417419
else:
418420
locs.extend(
419421
Location(v)
420-
for v in el.positions(params(el.IsClosed(), trimmed))
422+
for v in el.positions(
423+
params[0 if el.IsClosed() and not trimmed else 1]
424+
)
421425
)
422426
else:
423427
raise ValueError(f"Unsupported selection: {el}")

0 commit comments

Comments
 (0)