Crate spiral

Source
Expand description

Iterators to iterate 2D structures in spiral patterns

§Usage

This crate is on crates.io and can be used by adding spiral to the dependencies in your project’s Cargo.toml.

[dependencies]
spiral = "0.2"

§Examples

use spiral::ChebyshevIterator;

let center_x = 3;
let center_y = 3;
let radius = 4;
let iterator = ChebyshevIterator::new(center_x, center_y, radius);
for (x, y) in iterator {
    // Iterates over a 7x7 2D array with `x` & `y`.
}
use spiral::ManhattanIterator;

let center_x = 3;
let center_y = 3;
let radius = 4;
for (x, y) in ManhattanIterator::new(center_x, center_y, radius) {
    // Iterates over a 7x7 2D array with `x` & `y`.
}

Structs§

ChebyshevIterator
An iterator iterating in a spiral fashion with the Chebyshev distance function.
ManhattanIterator
An iterator iterating in a spiral fashion with the Manhattan distance function.

Traits§

Int
Simple trait so we don’t have to wrap write all the num signatures that we want every time.