Open adam-urbanczyk opened 6 months ago
Sure, yes either way. What's the [part of it] that you're interested in? The last
method is no doubt a wee bit hacky.
Also the IDE specific convenience methods are ugly.
I think the following:
__getitem__
filter
sort
and maybe
group
Seems good. Maybe the group feature can be refactored to simplify things. At a glance I suppose it might be possible to make a group()[]
method that can be used to create a callable that can be passed to filter
. Like
wp.filter(group(lambda face: face.Area(), tol=10)[0])
Suppose this would keep the overall API cleaner and remove the need for a temporary variable in the workplane object.
@adam-urbanczyk fyi I'm slow but I expect to open a draft PR soon. I'm going to suggest having both the original filter
and something like filtermap
with the former being simple filter expecting Callable[[CQObject], bool]
and the latter allowing for more complex use cases expecting Callable[[Iterable[CQObject]], Iterable[CQObject]]
.
Grouping could then be implemented without hacking Workplane
. There would be a utility Group
class that returns a suitable function when indexed (via __getitem__
) that can be used with filtermap
like so
wp.filtermap(Group(lambda face: face.Area(), tol=10)[0:1])
Sure, filtermap
might require some discussion though. I hope that you won't mind.
No problem at all. Feel free to be as direct with your specs/feedback as you like. If you ultimately don't want Group
I'll just yeet it out of the PR. :+1:
Would you consider opening a PR to CQ with the methods from this repo? If not, anything against adding [part of it] it to CQ?