#unc

bresenham

A fast, iterator-based integer-only implementation of Bresenham's line algorithm

2 releases

Uses old Rust 2015

0.1.1 Aug 14, 2016
0.1.0 Aug 14, 2016

#17 in Rendering engine

Download history 342/week @ 2023-02-13 422/week @ 2023-02-20 207/week @ 2023-02-27 427/week @ 2023-03-06 393/week @ 2023-03-13 380/week @ 2023-03-20 946/week @ 2023-03-27 471/week @ 2023-04-03 331/week @ 2023-04-10 388/week @ 2023-04-17 433/week @ 2023-04-24 244/week @ 2023-05-01 277/week @ 2023-05-08 173/week @ 2023-05-15 167/week @ 2023-05-22 323/week @ 2023-05-29

970 downloads per month
Used in 4 crates

MIT license

6KB
131 lines

bresenham-rs

Implements Bresenham's line drawing algorithm in Rust using an iterator over all points in the line. Most, if not all overhead should evaporate when inlined by the compiler.

Example use:

for (x, y) in Bresenham::new((0, 1), (6, 4)) {
    println!("{}, {}", x, y);
}

Will print:

(0, 1)
(1, 1)
(2, 2)
(3, 2)
(4, 3)
(5, 3)

lib.rs:

Iterator-based Bresenham's line drawing algorithm

[Bresenham's line drawing algorithm] (https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm) is fast algorithm to draw a line between two points. This crate implements the fast integer variant, using an iterator-based appraoch for flexibility. It calculates coordinates without knowing anything about drawing methods or surfaces.

Example:

extern crate bresenham;
use bresenham::Bresenham;

fn main() {
    for (x, y) in Bresenham::new((0, 1), (6, 4)) {
        println!("{}, {}", x, y);
    }
}

Will print:

(0, 1)
(1, 1)
(2, 2)
(3, 2)
(4, 3)
(5, 3)

No runtime deps