Find points that make an equally spaced row on a 2D plane
Project description
Find points that make an equally spaced row on a 2D plane.
Fast and simple, works by walking in 4 directions (1,0 0,1 1,1 1,-1) to n steps from a point and checking if the next point exists, until the required row size is reached.
Example usage:
import rowfind
coords = [
(0, 0), (1, 1), (2, 2), (3, 3), (3, 4),
(3, 5), (12, 3), (12, 4), (11, 3), (11, 2),
(11, 1), (10, 3), (5, 3), (6, 2), (7, 1),
(7, 0), (8, 1), (8, 5), (9, 5)
]
row_size = 3
steps = 1
rows = rowfind.find_rows(coords, row_size, steps)
# Where `coords` is a tuple/list of (x, y) coordinates,
# `row_size` is the length of rows to find and `steps`
# is the number of steps to walk before checking a point.
#
# The `steps` parameter can be a single integer, a
# tuple/list of integers or None. If None, it tries all
# possible steps that fit into the plane's bounds.
#
# The return value is a tuple of tuples, where each
# tuple is a group of points that form a row.
# To visualize the results:
print("\n".join(str(row) for row in rows))
graph = rowfind.draw_graph(coords, rows)
print(graph)
Output:
((5, 3), (6, 2), (7, 1))
((11, 1), (11, 2), (11, 3))
((3, 3), (3, 4), (3, 5))
((0, 0), (1, 1), (2, 2))
((1, 1), (2, 2), (3, 3))
((10, 3), (11, 3), (12, 3))
. . . X . . . . O O . . .
. . . X . . . . . . . . O
. . . X . X . . . . X X X
. . X . . . X . . . . X .
. X . . . . . X O . . X .
X . . . . . . O . . . . .
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rowfind-0.1.4.tar.gz
(2.9 kB
view details)
Built Distribution
File details
Details for the file rowfind-0.1.4.tar.gz
.
File metadata
- Download URL: rowfind-0.1.4.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b7322128761569ff7f5e7c4f2329c3752696a22fd33e8babc74a75d1f0a6cfb |
|
MD5 | c6be4df1580e50a75c10e83453f6531b |
|
BLAKE2b-256 | 77c0721f4d2f7a51edf4e23fb349b71e044fd5beffec31d6598e4a4d3d44dd42 |
File details
Details for the file rowfind-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: rowfind-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e52776c8105b8be7dd17152bde75d35c667e66270b3d4d188172cb2e49785e |
|
MD5 | 9be1a8d37ce6ab7f42a1c9210d0ce376 |
|
BLAKE2b-256 | 548e188004f432a2f8690938d19f34878f68b898b67885351ac20a7d8fb6632f |