cadquery
cadquery copied to clipboard
Support eachpoint with `cq.Shape` and `cq.Workplane` in addition to callbacks
E.g.
b = cq.Workplane().box(2,2,2)
s = cq.Workplane().sphere(0.5)
res = b.faces().eachpoint(s)
@adam-urbanczyk In continuation of your comment on #1574 , I would add cq.Wire in addition to cq.Shape and cq.Workplane to this issue.
cq.Wire is a cq.Shape
@adam-urbanczyk I got it working for a Shape by renaming the argument arg and dispatching on its type. However I need some guidance about what semantics you expect for a Workspace. Just moving the workspace by the following lambda obviously does not work:
if isinstance(arg, Workplane):
wp = arg
callback = lambda v : wp.move(v)
Something like this:
v.moved(loc) for v in arg.vals() if isinstance(v, Shape)
Something like this:
v.moved(loc) for v in arg.vals() if isinstance(v, Shape)
Thanks @adam-urbanczyk . In my PR I used the following. Let me know this is what you intended.
res = [
v.moved(p).move(loc)
for v in arg.vals()
for p in pnts
if isinstance(v, Shape)
]
I think this can be closed. One follow up issue though is cutEach typing.
This now works but fails mypy:
b = cq.Workplane().box(2, 2, 2)
s = cq.Workplane().sphere(0.5)
res = b.faces().cutEach(s)
test2.py:7: error: Argument 1 to "cutEach" of "Workplane" has incompatible type "Workplane"; expected "Callable[[Location], Shape]" [arg-type]