|
37 | 37 |
|
38 | 38 | Modes = Literal["a", "s", "i", "c"] # add, subtract, intersect, construct |
39 | 39 | Point = Union[Vector, Tuple[Real, Real]] |
| 40 | +TOL = 1e-6 |
40 | 41 |
|
41 | 42 | T = TypeVar("T", bound="Sketch") |
42 | 43 | SketchVal = Union[Shape, Location] |
@@ -346,7 +347,7 @@ def parray(self: T, r: Real, a1: Real, da: Real, n: int, rotate: bool = True) -> |
346 | 347 |
|
347 | 348 | locs = [] |
348 | 349 |
|
349 | | - if abs(remainder(da, 360)) < 1e-6: |
| 350 | + if abs(remainder(da, 360)) < TOL: |
350 | 351 | angle = da / n |
351 | 352 | else: |
352 | 353 | angle = da / (n - 1) if n > 1 else a1 |
@@ -392,32 +393,35 @@ def distribute( |
392 | 393 | if not self._selection: |
393 | 394 | raise ValueError("Nothing selected to distribute over") |
394 | 395 |
|
395 | | - if 1 - abs(stop - start) < 1e-6: |
| 396 | + if 1 - abs(stop - start) < TOL: |
396 | 397 | trimmed = False |
397 | 398 | else: |
398 | 399 | trimmed = True |
399 | 400 |
|
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 | + ] |
409 | 408 |
|
410 | 409 | locs = [] |
411 | 410 | for el in self._selection: |
412 | 411 | if isinstance(el, (Wire, Edge)): |
413 | 412 | if rotate: |
414 | 413 | 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 | + ) |
416 | 418 | ) |
417 | 419 | else: |
418 | 420 | locs.extend( |
419 | 421 | 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 | + ) |
421 | 425 | ) |
422 | 426 | else: |
423 | 427 | raise ValueError(f"Unsupported selection: {el}") |
|
0 commit comments