#line #drawing #points #iterator-based #algorithm #integer-only

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

#73 in Rendering engine

Download history 174/week @ 2024-01-14 160/week @ 2024-01-21 134/week @ 2024-01-28 147/week @ 2024-02-04 228/week @ 2024-02-11 248/week @ 2024-02-18 188/week @ 2024-02-25 193/week @ 2024-03-03 205/week @ 2024-03-10 184/week @ 2024-03-17 299/week @ 2024-03-24 351/week @ 2024-03-31 278/week @ 2024-04-07 321/week @ 2024-04-14 245/week @ 2024-04-21 199/week @ 2024-04-28

1,095 downloads per month
Used in 6 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