Crate rotated_grid
source ·Expand description
Rotated grids for CMYK halftone dithering and more.
This crate provides the GridPositionIterator
type that creates
spaced grid positions along a rotated grid.
Order of generated coordinates
Do note that the generation order of the coordinates depends on the specific grid parameters
and may not be in the most efficient layout when used directly, depending on your use case.
For image processing you may want to prefer a top-down order, in which case you should collect
the coordinates into a vector and sort by y
coordinate first.
Example
use rotated_grid::{Angle, GridPoint, GridPositionIterator};
const WIDTH: usize = 16;
const HEIGHT: usize = 10;
let halftone_grids = [
("Cyan", 15.0),
("Magenta", 75.0),
("Yellow", 0.0),
("Black", 45.0),
];
for (name, angle) in halftone_grids {
println!("{name} at {angle}°");
let grid = GridPositionIterator::new(
WIDTH as _,
HEIGHT as _,
7.0,
7.0,
0.0,
0.0,
Angle::<f64>::from_degrees(angle),
);
let (_, expected_max) = grid.size_hint();
let mut count = 0;
for GridPoint { x, y } in grid {
println!("{x}, {y}");
count += 1;
}
assert!(count <= expected_max.unwrap())
}
Structs
- An angle expressed in radians.
- An iterator for positions on a rotated grid.