Crates.io | morton-index |
lib.rs | morton-index |
version | 0.3.0 |
source | src |
created_at | 2022-03-21 13:33:47.545104 |
updated_at | 2024-06-20 07:43:23.450193 |
description | Types and functions for efficiently and easily work with Morton indices |
homepage | |
repository | |
max_upload_size | |
id | 554096 |
size | 289,481 |
morton-index
- A Rust library for working with Morton indicesThis library enables working with Morton indices in your Rust code. Morton indices provide a one-dimensional mapping for the nodes of an n-ary tree (quadtree in 2D, octree in 3D, and so on). Here are the key features of this library in a nutshell:
Quadrant
in 2D, or Octant
in 3D)StaticStorage
flavor!// Create a Morton index with 8 bits of fixed-depth storage, so a fixed depth of 4
let mut fixed_index = FixedDepthMortonIndex2D8::try_from([
Quadrant::Zero,
Quadrant::One,
Quadrant::Two,
Quadrant::Three,
])?;
assert_eq!(4, fixed_index.depth());
// Access cells by their level
assert_eq!(Quadrant::One, fixed_index.get_cell_at_level(1));
// Or get an iterator over all cells, starting at the root of the quadtree
assert_eq!(Some(Quadrant::Three), fixed_index.cells().last());
// You can also create a Morton index from an index in a regular grid
assert_eq!(
fixed_index,
FixedDepthMortonIndex2D8::from_grid_index(Vector2::new(5, 3), QuadrantOrdering::XY),
);
For more examples, check out the examples folder.