| Crates.io | garray2d |
| lib.rs | garray2d |
| version | 0.4.0 |
| created_at | 2025-07-05 16:13:31.532977+00 |
| updated_at | 2025-07-09 19:49:12.578968+00 |
| description | Game development focused 2d array with signed index and offset support. |
| homepage | |
| repository | https://github.com/mintlu8/garray2d |
| max_upload_size | |
| id | 1739297 |
| size | 90,307 |
Game development focused 2d array with signed index and offset support.
Array2d represents a rectangular region in a tile map,
with non-represented regions considered Default::default.
This allows us to implement functions like resize that are geometric
instead of reinterpreting the underlying bytes.
Array2d is row major, which makes it useful when working with gpu textures.
There is currently no direct support for column major arrays.
Array2d is analogous to a Vec and can be created either via a function initializer
similar to array::from_fn or from a Vec and a dimension.
Array2dRef and Array2dMut can be created either by slicing an existing 2d array
using get or slice or by reinterpreting a slice as a 2d array.
To combine multiple arrays, use zip if dimension is the same, paint if you
do not care about overflows and merge if you do.
We use a few traits to make your life easier when using this crate, here are the common implementors of these types.
IntoBoundaryIntoBoundary means convertible to a 2d rectangle, types that implement it are
| type | example(s) | note |
|---|---|---|
Boundary |
Boundary::min_max([0, 0], [5, 8]) |
|
[u32; 2] |
[5, 8] |
Represents [0, 0]..[5, 8] |
impl RangeBounds<Into<Vector2<i32>>> |
[-1, -1]..[1, 1] |
Only for std types |
(impl RangeBounds<i32>, impl RangeBounds<i32>) |
(-1..=1, -1..1) |
Into<Vector2<i32>>The core mint trait that's implemented by [i32; 2] and types like glam's IVec2 or nalgebra's Vector2<i32>.
Array2dIndexingFor the get function, types that implement it are
| type | example(s) | note |
|---|---|---|
impl Into<Vector2<i32>> |
[-1, -1] |
Returns a point. |
impl IntoBoundary |
Boundary::min_max([0, 0], [1024, 768]) |
Returns a slice. |
This crate uses mint to interop with math crates like glam or nalgebra.
In glam or bevy_math for example, you might want enable the mint feature.
The core trait Into<Vector2<i32>> is implemented by types like glam's IVec2.
Additionally, [i32; 2] always implements this trait and should be the easiest way to
create a quick constant.
array.get([1, 2])
License under either of
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contributions are welcome!
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.