-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow to filter and group by property #879
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #879 +/- ##
=======================================
Coverage 96.65% 96.65%
=======================================
Files 31 31
Lines 9177 9184 +7
=======================================
+ Hits 8870 8877 +7
Misses 307 307 ☔ View full report in Codecov by Sentry. |
@snoyer thank you for sharing your mastery of Python. Was there a reason to not include Using shape properties directly as The |
It didn't occur to me at all! I wanted to do Regarding Either way, let me know if I should add |
If this is possible as described then absolutely yes it should be deprecated. The naming is already confusing since
Good point. |
Please add |
done
Turns out you can already do from itertools import product
from build123d import Box, ShapeList, Solid, Vertex
from ocp_vscode import ColorMap, show
boxes = ShapeList(
Box(1, 1, 1).scale(0.75 if (i, j) == (1, 2) else 0.25).translate((i, j, 0))
for i, j in product(range(-5, 6), repeat=2)
)
# sort by distance to origin
boxes = boxes.sort_by(Vertex().distance)
show(*boxes, colors=ColorMap.listed(len(boxes))) # sort by distance to largest box
boxes = boxes.sort_by(boxes.sort_by(Solid.volume).last.distance)
show(*boxes, colors=ColorMap.listed(len(boxes))) |
Thank you. This is a really nice enhancement. I need to get my head around |
You're welcome :) This last example was a bit dense on purpose but if we break it down we have largest_box = boxes.sort_by(Solid.volume).last # sorting by property as per this PR
boxes = boxes.sort_by(largest_box.distance) # sorting by callable as was already possible the key here is that the
|
Got it, thanks. There will need to be some good documentation around these capabilities as it probably will be a little more difficult for new users to understand as there isn't a simple list of things that can be done now (which is kinda the whole point but still...). |
This would allow
as an alternative to