Function line_drawing::walk_grid [] [src]

pub fn walk_grid(
    start: (isize, isize),
    end: (isize, isize)
) -> Vec<(isize, isize)>

Walk along a grid, taking only orthagonal steps.

See this section of the article for an interactive demonstration.

Note that this algorithm isn't symetrical; if you swap start and end, the reversed line might not be the same. See sorted_walk_grid for a version that sorts the points so that the line will be the same.

Example:

extern crate line_drawing;
use line_drawing::walk_grid;

fn main() {
    for (x, y) in walk_grid((0, 0), (5, 3)) {
        print!("({}, {}), ", x, y);
    }
}
(0, 0), (1, 0), (1, 1), (2, 1), (2, 2), (3, 2), (4, 2), (4, 3), (5, 3),