-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
A-MathFundamental domain-agnostic mathematical operationsFundamental domain-agnostic mathematical operationsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon
Description
What problem does this solve or what need does it fill?
Grids often have x,y positions. I'll use IVec2 here as an example.
When trying to access neighbor cells, a pattern I use is the IVec2 constants:
A "cross" set of neighbors then, is:
const cross: [IVec2;4] = [IVec2::X, IVec2::Y, IVec2::NEG_X, IVEC2::NEG_Y];but you can imagine similar for diagonals and 3x3 neighbors including both cross and diagonals.
getting say, the entities from some grid that have valid positions (ie: aren't outside of a grid) can be done with a filter_map.
let valid_positions = cross.iter().filter_map(|offset| {
grid.get(current_position + offset)
}.collect()What solution would you like?
A collection of additional constants for these sets of neighbors (feel free to bikeshed names or suggest additional common patterns).
- CROSS (or CARDINALS, or NSEW, etc)
- DIAGONALS
- ALL_NEIGHBORS (ie: not the current position in a 3x3 grid around the current tile)
AXES is an example of a combination that already exists.
What alternative(s) have you considered?
- Just do it manually, which is what I've been doing. But this means every Grid API tends to recreate these access patterns.
torsteingrindvik, jakobhellermann and alice-i-cecile
Metadata
Metadata
Assignees
Labels
A-MathFundamental domain-agnostic mathematical operationsFundamental domain-agnostic mathematical operationsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-UncontroversialThis work is generally agreed uponThis work is generally agreed upon