geometrid

Crates.iogeometrid
lib.rsgeometrid
version0.9.0
sourcesrc
created_at2023-04-22 20:45:00.362752
updated_at2024-07-16 11:28:08.58881
descriptionEverything you would ever need to work with constant sized square grids
homepage
repositoryhttps://github.com/wainwrightmark/geometrid
max_upload_size
id846156
size195,377
Mark Wainwright (wainwrightmark)

documentation

https://docs.rs/geometrid

README

geometrid

GITHUB Crates.io GitHub Workflow Status docs

2d grids, tiles, and vertices, focusing in particular on grids whose size is a compile time constant. Also contains features for Shapes and Polyominos and other common features of 2d grid based games.

This crate is currently very unstable. I will attempt to stabilize it properly if const traits are ever stabilized.

At the moment, the constant sized types are all internally backed by a u8, this means that the largest grid you can build is 16x16. If you want to use larger grids please file an issue and I'll create u16 and u32 versions.

Please also file an issue or PR if there are any other useful capabilities that I've missed.

The crate has the following optional features:

Name Description Default
std Required for some floating point functions false
serde Serialize and Deserialize for most types false
u256 Enables TileSet256 false
glam Enables HasCenter false

One of the hardest problems in creating 2d grids is deciding which way is up. This crate uses compass points to describe directions. Going North corresponds to decreasing the value of the y coordinate, Going East corresponds to increasing the value of the x coordinate.

A 2x2 grid of tiles looks like this

┌───────┬───────┐
│       │       │
│ (0,0) │ (1,0) │
│       │       │
├───────┼───────┤
│       │       │
│ (0,1) │ (1,1) │
│       │       │
└───────┴───────┘

The vertices of the same grid look like this

 (0,0)   (1,0)   (2,0)
┌───────┬───────┐
│       │       │
│       │       │
│       │       │
│(0,1)  │(1,1)  │(2,1)
├───────┼───────┤
│       │       │
│       │       │
│       │       │
│(0,2)  │(1,2)  │(2,2)
└───────┴───────┘

Getting started

use geometrid::*;

fn main() {

    let mut grid: TileMap<usize, 3, 3, 9> = TileMap::from_fn(|x| x.into());
    assert_eq!(grid.to_string(), "0|1|2\n3|4|5\n6|7|8");
    grid.flip(FlipAxes::Vertical);
    assert_eq!(grid.to_string(), "6|7|8\n3|4|5\n0|1|2");
}

Contributing

Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.

Check out the Contributing section in the docs for more info.

License

This project is proudly licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

geometrid can be distributed according to the MIT license. Contributions will be accepted under the same license.

Authors

Commit count: 110

cargo fmt