Crate bresenham_zip
source · [−]Expand description
To use Bresenham.Zip you need to build a Bresenham object of the axis you want to travel. You must specify the three points of the triangle. This rasterization algorithm only works using triangles were two of its points have the same X, Y or Z.
To build the object use the constructor passing first the point out of the horizontal line and then the other two points. If the last two points doesn’t belong to the same axis, an error will be returned instead of the iterator.
Once the iterator is ready you can use it like any other iterator and it will provide two points each iteration, each one belonging to one of the two lines being calculated. Both of them will have the same X or Y, defining an axis parallel line.
Example
You can create the any of the two zips with builders and iterate through them to get the pairs.
for (left, right) in Builder::new().axis(bresenham_zip::Axis::Y).start_point((50, 50))
.first_ending_point((0, 100)).second_ending_point((250, 100)).build()? {
assert_eq!(left.1, right.1);
assert!((0..=50).contains(&left.0));
assert!((50..=250).contains(&right.0));
}
Or you can build them with the helper macro.
for (a, b) in build_zip!(3D:Z - (50, 50, 50) -> (0, 10, 200), (100, 250, 200))? {
println!("{:?} - {:?}", a, b);
assert_eq!(a.2, b.2);
assert!((0..=50).contains(&a.0));
assert!((10..=50).contains(&a.1));
assert!((50..=100).contains(&b.0));
assert!((50..=250).contains(&b.1));
}
build_zip! macro
This macro allows you to build a whole zip to iterate with a single line. You need to specify the dimension of the space, the axis to navigate and three points following the next schema:
{2D|3D}:{X|Y|Z} - {starting_point} -> {first_ending_point}, {second_ending_point} Ignore { and } when writting it
let zip_2d_y = build_zip!(2D:Y - (50, 50) -> (0, 100), (0, 100))?;
let zip_3d_z = build_zip!(3D:Z - (50, 50, 50) -> (0, 0, 200), (100, 250, 200))?;
Modules
Package with the logic of the two-dimensional BresenhamZip
Package with the logic of the three-dimensional BresenhamZip
Macros
Convenience tool to build a whole zip of any dimension and axis with a single line call. The schema call goes like this:
Enums
An enumeration of the axes that can be used building a new zip
Traits
Trait to represent any valid number to use with the BresenhamZip. Extension of line_drawing::SignedNum to allow the use of std::fmt::Debug.