cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Support eachpoint with `cq.Shape` and `cq.Workplane` in addition to callbacks

Open adam-urbanczyk opened this issue 2 years ago • 5 comments

E.g.

b = cq.Workplane().box(2,2,2)
s = cq.Workplane().sphere(0.5)

res = b.faces().eachpoint(s)

adam-urbanczyk avatar Aug 31 '23 06:08 adam-urbanczyk

@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.

dov avatar Apr 28 '24 10:04 dov

cq.Wire is a cq.Shape

adam-urbanczyk avatar Apr 28 '24 11:04 adam-urbanczyk

@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)

dov avatar Apr 28 '24 15:04 dov

Something like this:

v.moved(loc) for v in arg.vals() if isinstance(v, Shape)

adam-urbanczyk avatar Apr 28 '24 15:04 adam-urbanczyk

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)
]

dov avatar Apr 29 '24 18:04 dov

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]

lorenzncode avatar Aug 16 '24 02:08 lorenzncode