-
Notifications
You must be signed in to change notification settings - Fork 33
RectMap #227
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
base: main
Are you sure you want to change the base?
RectMap #227
Conversation
ManevilleF
left a comment
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.
Thanks a lot for this PR, this is a useful feature and I appreciate the amount of tests and documentation, especially a fully fledged bevy example !
I did a first review, as I wish for some API changes, I did not test the code or the example yet
src/storage/rect.rs
Outdated
| impl<T> std::ops::Deref for RectMap<T> { | ||
| type Target = RectMetadata; | ||
| fn deref(&self) -> &Self::Target { | ||
| &self.meta | ||
| } | ||
| } |
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.
Why is this Deref needed ?
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.
this Deref expose function inside RectMetadata function that take reference &RectMetadata: len, is_empty, iter_hex, contains_hex, wrap_hex, while avoiding exposing builder pattern function that take ownership RectMetadata, making a getter ->RectMetadata will expose builder pattern function, and getter -> &RectMetadata is just a more verbose version of this Deref
Co-authored-by: Félix Lescaudey de Maneville <felix.maneville@gmail.com>
Co-authored-by: Félix Lescaudey de Maneville <felix.maneville@gmail.com>
Upstream
ManevilleF
left a comment
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.
Thanks for all the improvements made,
I can see there is a bunch of tests, but they test the index logic without constructing a map
Could you add tests that check that:
RectMap::iter().count() == RectMap::len()RectMap::new(.., |h| h)can be constructed and queried properly and the value is the correct one ?- Test that querying out of bounds does return
Noneif no wrapping is set
| /// builder patter, set half size | ||
| /// | ||
| /// # Param | ||
| /// * `half_size`: the half span of the map | ||
| /// | ||
| /// the resulting map will have: | ||
| /// - columns: `-half_size[0]..(half_size[0] - 1)`, and | ||
| /// - rows: `-half_size[1]..(half_size[1] - 1)`, and | ||
| #[must_use] | ||
| pub fn with_half_size(mut self, half_size: IVec2) -> Self { | ||
| // self.half_size = half_size.abs(); | ||
| self.start = -half_size.abs(); | ||
| self.dim = (2 * half_size.abs()).as_uvec2(); | ||
| self | ||
| } | ||
| /// builder patter, set start and end | ||
| /// | ||
| /// # Param | ||
| /// * `start`: the element wise minimum offset coordinate in the map | ||
| /// * `end`: the element wise maximum offset coordinate in the map | ||
| /// | ||
| /// the resulting map will have: | ||
| /// - columns: `start[0]..max(start[0], end[0])` | ||
| /// - rows: `start[1]..max(start[1], end[1])` | ||
| #[must_use] | ||
| pub fn with_start_end(mut self, start: IVec2, end: IVec2) -> Self { | ||
| // self.half_size = half_size.abs(); | ||
| self.start = start; | ||
| self.dim = (end.max(start) - start).as_uvec2(); | ||
| self | ||
| } | ||
| /// builder pattern, set start and dimension | ||
| /// | ||
| /// # Param | ||
| /// * `start`: the element wise minimum offset coordinate in the map | ||
| /// * `dim`: the dimension of the map | ||
| /// | ||
| /// the resulting map will have: | ||
| /// - columns: `start[0]..(start[0] + dim[0])` | ||
| /// - rows: `start[1]..(start[1] + dim[1])` | ||
| #[must_use] | ||
| pub const fn with_start_dim(mut self, start: IVec2, dim: UVec2) -> Self { | ||
| self.start = start; | ||
| self.dim = dim; | ||
| self | ||
| } |
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.
Are those methods needed ? The only usage I can think of would be to overwrite a cloned metadata with a different size
| wrap_strategies: [WrapStrategy::Cycle, WrapStrategy::Clamp], | ||
| } | ||
| } | ||
| /// builder patter, set half size |
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.
| /// builder patter, set half size | |
| /// builder pattern, set half size |
| self.dim = (2 * half_size.abs()).as_uvec2(); | ||
| self | ||
| } | ||
| /// builder patter, set start and end |
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.
| /// builder patter, set start and end | |
| /// builder pattern, set start and end |


Development Workflow
cargo clippycargo buildcargo fmtcargo rustdoccargo testAdded
examples/rect_map.rsAn example of using
RectMap.cargo run --example rect_map --features "bevy"src/storage/rect.rsA hex storage map that internally use an 1D Vec, and index by converting to offset coordinate.
The meta data for
RectMap, but also act as the builder.Wrapping Strategy when trying to wrap hex coordinate to ensure it contain inside the map.
Example
feature
bevy_ecsAdded feature to derive
ResourceandComponentforhexx's types.