Introduce QueryBorrow::iter_combinations #368
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey there, very nice project. As far as I'm aware, there currently isn't a way to safely and efficiently iterate over combinations of entities. This PR introduces QueryBorrow::iter_combinations, allowing for just that.
The operation is useful in situations where you need entities to interact with each other eg. collision between entities.
This implementation is based on the description of the same operation in bevy_ecs: https://github.com/bevyengine/bevy/blob/31d91466b4fb99786a8c61b82417372a42a3f531/crates/bevy_ecs/src/query/iter.rs#L546.
The API currently returns
[(Entity, Q::Item); K]
as I felt it was consistent with the other query iterator. This can easily be changed to([Entity; K], [Q::Item; K])
for consistency with the query_many family of functionsPlease let me know if you have any questions or changes.
I have signed the Google CLA linked in the CONTRIBUTING.md
Cheers,
Moulberry