#iterator #2d #distance

spiral

Iterate over a 2D structure in a spiral pattern

11 releases

0.2.0 Oct 9, 2022
0.1.9 Mar 14, 2018
0.1.8 Jan 6, 2018
0.1.5 Dec 29, 2017

#1571 in Algorithms

Download history 40/week @ 2023-08-12 20/week @ 2023-08-19 58/week @ 2023-08-26 35/week @ 2023-09-02 43/week @ 2023-09-09 43/week @ 2023-09-16 22/week @ 2023-09-23 32/week @ 2023-09-30 32/week @ 2023-10-07 40/week @ 2023-10-14 109/week @ 2023-10-21 53/week @ 2023-10-28 36/week @ 2023-11-04 60/week @ 2023-11-11 45/week @ 2023-11-18 50/week @ 2023-11-25

201 downloads per month
Used in 3 crates (2 directly)

GPL-3.0 license

18KB
272 lines

spiral

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

CI Version Rust Documentation License

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 
}

Dependencies

~155KB