-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Merged by Bors] - Add documentation to QueryCombinationIter
#5739
Changes from all commits
1f81535
a04c319
e403f9e
b0304e4
7be57c9
8195f83
c7b2343
2a37c0e
91c0b9d
8ffe098
9166cd1
ea313b8
bbf8a1e
890624c
68df415
4aa7e20
d5372e9
74cf66c
01ff486
fa78f7c
1ad2328
6a9c560
684dff6
cdab909
69da34a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,59 @@ where | |
{ | ||
} | ||
|
||
/// An iterator over `K`-sized combinations of query items without repetition. | ||
/// | ||
/// In this context, a combination is an unordered subset of `K` elements. | ||
/// The number of combinations depend on how `K` relates to the number of entities matching the [`Query`] (called `N`): | ||
/// - if `K = N`, only one combination exists, | ||
/// - if `K < N`, there are <sub>N</sub>C<sub>K</sub> combinations (see the [performance section] of `Query`), | ||
/// - if `K > N`, there are no combinations. | ||
Comment on lines
+217
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very technically precise but might be a bit abstract or unapproachable for new users. Is there any value in changing the wording here to be more approachable, or is this not the place to do that? I think I'm leaning towards the latter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk, I just moved the documentation here from the methods, with minimal changes. Anyway, I think it's not too difficult to understand. You just need to have a basic understanding of combinatorics. |
||
/// | ||
/// # Usage | ||
/// | ||
/// This type is returned by calling [`Query::iter_combinations`] or [`Query::iter_combinations_mut`]. | ||
/// | ||
/// It implements [`Iterator`] only if it iterates over read-only query items ([learn more]). | ||
/// | ||
/// In the case of mutable query items, it can be iterated by calling [`fetch_next`] in a `while let` loop. | ||
/// | ||
/// # Examples | ||
/// | ||
/// The following example shows how to traverse the iterator when the query items are read-only. | ||
/// | ||
/// ``` | ||
/// # use bevy_ecs::prelude::*; | ||
/// # #[derive(Component)] | ||
/// # struct ComponentA; | ||
/// # | ||
/// fn some_system(query: Query<&ComponentA>) { | ||
/// for [a1, a2] in query.iter_combinations() { | ||
/// // ... | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// The following example shows how `fetch_next` should be called with a `while let` loop to traverse the iterator when the query items are mutable. | ||
/// | ||
/// ``` | ||
/// # use bevy_ecs::prelude::*; | ||
/// # #[derive(Component)] | ||
/// # struct ComponentA; | ||
/// # | ||
/// fn some_system(mut query: Query<&mut ComponentA>) { | ||
/// let mut combinations = query.iter_combinations_mut(); | ||
/// while let Some([a1, a2]) = combinations.fetch_next() { | ||
/// // ... | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// [`fetch_next`]: Self::fetch_next | ||
/// [learn more]: Self#impl-Iterator | ||
/// [performance section]: crate::system::Query#performance | ||
/// [`Query`]: crate::system::Query | ||
/// [`Query::iter_combinations`]: crate::system::Query::iter_combinations | ||
/// [`Query::iter_combinations_mut`]: crate::system::Query::iter_combinations_mut | ||
pub struct QueryCombinationIter<'w, 's, Q: WorldQuery, F: WorldQuery, const K: usize> { | ||
tables: &'w Tables, | ||
archetypes: &'w Archetypes, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a screenshot of how this looks in the docs? Having
<sub>
first looks wrong to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should render the same as here: NCK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this notation. What does it mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a common notation of the binomial coefficient. You can also see the rendered docs by checking out the branch and doing the cargo doc thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, if it's common enough I guess it's fine. Otherwise I think it would be good to switch to another notation or to describe it textually. I guess the problem is that we are constrained by the Markdown formatting so we can't use the "classical" notation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still better than to write a fraction with factorials in it.