Find points that make a 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.
As a script:
rowfind <row_size> <steps> x1,y1 x2,y2 x3,y3 ...
As a module:
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 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.2.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file rowfind-0.1.2.tar.gz
.
File metadata
- Download URL: rowfind-0.1.2.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cab1a5ba136066feb98e7dd7a5c441369981ca2ba874084d6ebcfe75579105c |
|
MD5 | 7e04c559cead4afde3a18b194c897f85 |
|
BLAKE2b-256 | 7240ded457b54e1128a2184220ed4febe9a11e2fcc7659ab5311224d0147c07c |
File details
Details for the file rowfind-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: rowfind-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.9 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 | 5aeb1418a086fdd806db2b9ee2ddcd1cf4e263004514a7bb03b7bd35a2560832 |
|
MD5 | c59283c8660626dbb506c65223d897d5 |
|
BLAKE2b-256 | 4c498422126174c7ed50c526111b84d88dd678510081e319d865d8daafc0b42b |