#iterator #2d #distance

spiral

Iterate over a 2D structure in a spiral pattern

10 releases

Uses old Rust 2015

0.1.9 Mar 14, 2018
0.1.8 Jan 6, 2018
0.1.5 Dec 29, 2017

#622 in Algorithms

Download history 26/week @ 2022-01-24 28/week @ 2022-01-31 14/week @ 2022-02-07 21/week @ 2022-02-14 22/week @ 2022-02-21 15/week @ 2022-02-28 16/week @ 2022-03-07 44/week @ 2022-03-14 47/week @ 2022-03-21 14/week @ 2022-03-28 17/week @ 2022-04-04 59/week @ 2022-04-11 47/week @ 2022-04-18 82/week @ 2022-04-25 98/week @ 2022-05-02 57/week @ 2022-05-09

323 downloads per month
Used in 2 crates (via distance-field)

GPL-3.0 license

16KB
237 lines

spiral

A Rust Library for iterating over 2D structures in spiral patterns

Build Status Cargo License: GPL-3.0 Downloads

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
spiral = "0.1"

And this to your crate root:

extern crate spiral;

Examples

let center_x = 3;
let center_y = 3;
let radius = 4;
for (x, y) in ManhattanIterator::new(center_x, center_y, radius) {
	// Iterates over 7x7 2D array with 'x' & 'y' following this pattern:
	//
	//  0   0   0  23   0   0   0 
	//  0   0  22  12  24   0   0 
	//  0  21  11   5  13  25   0 
	// 20  10   4   1   2   6  14 
	//  0  19   9   3   7  15   0 
	//  0   0  18   8  16   0   0 
	//  0   0   0  17   0   0   0 
}

No runtime deps