#bresenham #algorithm #bresenham-rs

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

#55 in Rendering engine

Download history 585/week @ 2024-12-07 600/week @ 2024-12-14 214/week @ 2024-12-21 124/week @ 2024-12-28 408/week @ 2025-01-04 792/week @ 2025-01-11 562/week @ 2025-01-18 414/week @ 2025-01-25 385/week @ 2025-02-01 468/week @ 2025-02-08 489/week @ 2025-02-15 537/week @ 2025-02-22 397/week @ 2025-03-01 504/week @ 2025-03-08 390/week @ 2025-03-15 306/week @ 2025-03-22

1,662 downloads per month
Used in 7 crates (6 directly)

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