Manage multi-resolution hexagonal grids
mainThe Hex type supports multi-resolution coordinates, allowing you to treat groups of hexagons as single units (chunks). This is useful for large maps or infinite grids with varying zoom levels.
- Lowering resolution: Use
to_lower_res(radius)to find the parent coordinate (the chunk) containing a specific coordinate. - Increasing resolution: Use
to_higher_res(radius)to find the center child coordinate of a chunk.
By using these methods, you can divide a large grid into smaller chunks and perform local operations within those chunks.
```rust
use hexx::*;
const CHUNK_RADIUS: u32 = 10;
const MAP_RADIUS: u32 = 20;
let chunks = Hex::ZERO.range(MAP_RADIUS);
for chunk in chunks {
// We can retrieve the center of that chunk by increasing the resolution
let center = chunk.to_higher_res(CHUNK_RADIUS);
// And retrieve the other coordinates in the chunk
let children = center.range(CHUNK_RADIUS);
// We can retrieve the chunk coordinates from any coordinate..
for coord in children {
// .. by reducing the resolution
assert_eq!(coord.to_lower_res(CHUNK_RADIUS), chunk);
}
}