wrapping_coords2d

Rust crate to translate 2D coordinates into a 1D index with wrapping.

Crate Downloads Documentation License

Use WrappingCoords2d to store data from a 2D grid into a 1D container such as std::vec::Vec. Both x and y coordinates wrap around the limits of the grid. WrappingCoords2d is not a container; it is just a tool to manipulate indices. For a 2D container, see array2d. For coordinate translation without wrapping, see ameda.

WrappingCoords2d is useful to design cellular automata, agent-based models, and game worlds in 2D and 3D. You can use WrappingCoords2d as part of an Entity-Component-System (ECS) software architecture for high-performing models and flexible games. See my ABM project for an example.

See more examples in the documentation for the wrapping_coords2d crate.

FAQ

Why not create iterators to the neighbors of a cell?

In an ECS design, indices make more sense than iterators: if a game world or a model landscape has several components, such as color, depth, and fertility, it makes sense to keep each component in its own vector. The simplest approach is to use indices on them. However, I am open to a pull request contributing code for iterators into neighbors.