MCPcopy
hub / github.com/CadQuery/cadquery / distribute

Method distribute

cadquery/sketch.py:439–481  ·  view source on GitHub ↗

Distribute locations along selected edges or wires.

(
        self: T, n: int, start: Real = 0, stop: Real = 1, rotate: bool = True
    )

Source from the content-addressed store, hash-verified

437 )
438
439 def distribute(
440 self: T, n: int, start: Real = 0, stop: Real = 1, rotate: bool = True
441 ) -> T:
442 """
443 Distribute locations along selected edges or wires.
444 """
445
446 if n < 1:
447 raise ValueError(f"At least 1 element required, requested {n}")
448
449 if not self._selection:
450 raise ValueError("Nothing selected to distribute over")
451
452 if 1 - abs(stop - start) < TOL:
453 trimmed = False
454 else:
455 trimmed = True
456
457 # closed edge or wire parameters
458 params_closed = [start + i * (stop - start) / n for i in range(n)]
459
460 # open or trimmed edge or wire parameters
461 params_open = [
462 start + i * (stop - start) / (n - 1) if n - 1 > 0 else start
463 for i in range(n)
464 ]
465
466 locs = []
467 for el in self._selection:
468 if isinstance(el, (Wire, Edge)):
469 if el.IsClosed() and not trimmed:
470 params = params_closed
471 else:
472 params = params_open
473
474 if rotate:
475 locs.extend(el.locations(params, planar=True,))
476 else:
477 locs.extend(Location(v) for v in el.positions(params))
478 else:
479 raise ValueError(f"Unsupported selection: {el}")
480
481 return self.push(locs)
482
483 def push(
484 self: T, locs: Iterable[Union[Location, Point]], tag: Optional[str] = None,

Callers 2

test_distributeFunction · 0.80
test_mixed_closeFunction · 0.80

Calls 6

pushMethod · 0.95
LocationClass · 0.85
IsClosedMethod · 0.80
extendMethod · 0.80
locationsMethod · 0.80
positionsMethod · 0.45

Tested by 2

test_distributeFunction · 0.64
test_mixed_closeFunction · 0.64