pixel_map
Rust CrateA PixelMap
stores pixel data for an image in a quad tree structure.
A PixelMap
is an MX quadtree implementation, occupies a region of two-dimensional space at the
root node, and subdivides down to the pixel level. A type-generic pixel data value can be stored
for each pixel in the map, but the tree structure optimizes storage for regions of common values.
A pixel value must be Copy + PartialEq
.
Project status: alpha. Releases may contain breaking changes.
Add the crate to your Cargo.toml
:
bash
cargo add pixel_map
```rust use pixel_map::PixelMap;
// Example pixel data struct MyColor(u8, u8, u8);
let mut pixel_map = PixelMap
```
```rust // Set a pixel pixelmap.setpixel((11, 12), MyColor(255, 0, 0));
// Draw a line pixelmap.drawline(&ILine::new((500, 500), (600, 400)), MyColor(0, 255, 0));
// Draw a rectangle pixelmap.drawrect(&IRect::from_corners((200, 200), (300, 300)), MyColor(0, 0, 255));
// Draw a circle pixelmap.drawcircle(&ICircle::new((500, 500), 100), MyColor(0, 0, 255)); ```
```rust // Visit all leaf nodes pixel_map.visit(|node| { println!("region: {:?}, value: {:?}", node.region(), node.value()); });
// Visit all leaf nodes that have been modified pixelmap.visitdirty(|node| { println!("region: {:?}, value: {:?}", node.region(), node.value()); }); pixelmap.cleardirty(true /recurse/); ```
Licensed under MIT license (LICENSE
or https://opensource.org/licenses/MIT)