Find points that make an equally spaced row on a 2D plane
Project description
rowfind
Find points that make an equally spaced row on a 2D plane.
Fast and simple, finds rows 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.
All possible rows
find_all
finds all rows that satisfy the given lengths and steps.
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), (4, 4)
]
lengths = 3
steps = 1
rows = rowfind.find_all(coords, lengths, steps)
# The return value is a tuple of tuples, where each
# tuple is a group of points that form a row.
print("\n".join(map(str, rows)))
print(rowfind.draw_graph(coords, rows))
"""
((5, 3), (6, 2), (7, 1))
((1, 1), (2, 2), (3, 3))
((11, 1), (11, 2), (11, 3))
((3, 3), (3, 4), (3, 5))
((0, 0), (1, 1), (2, 2))
((2, 2), (3, 3), (4, 4))
((4, 4), (5, 3), (6, 2))
((3, 5), (4, 4), (5, 3))
((10, 3), (11, 3), (12, 3))
. . . X . . . . O O . . .
. . . X X . . . . . . . O
. . . X . X . . . . X X X
. . X . . . X . . . . X .
. X . . . . . X O . . X .
X . . . . . . O . . . . .
"""
steps
dictates the gap between points in a row.
If steps
is set to 1, only immediate neighbors will be matched.
. x x x .
o . . x .
. . x . x
. x . . o
If it's set to 2, only gaps of 1 will be matched.
x . x . x
. . . . o
. . x . o
. o . . .
x . x . .
lengths
dictates the row lengths that will be matched.
Both steps
and lengths
can be an integer, a tuple/list of integers (multiple constraints) or None.
If they're set to None, all possible steps or lengths that fit into the plane's bounds will be matched. This can be slow if the min and max are far apart.
Unique rows
find_unique
finds all rows that satisfy the given steps and minimum length. Sub-rows will not be considered as distinct, so no overlaps.
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), (4, 4)
]
min_length = 3
steps = 1
rows = rowfind.find_unique(coords, min_length, steps)
print("\n".join(map(str, rows)))
print(rowfind.draw_graph(coords, rows))
"""
((11, 1), (11, 2), (11, 3))
((3, 5), (4, 4), (5, 3), (6, 2), (7, 1))
((3, 3), (3, 4), (3, 5))
((0, 0), (1, 1), (2, 2), (3, 3), (4, 4))
((10, 3), (11, 3), (12, 3))
. . . X . . . . O O . . .
. . . X X . . . . . . . O
. . . X . X . . . . X X X
. . X . . . X . . . . X .
. X . . . . . X O . . X .
X . . . . . . O . . . . .
"""
License
rowfind is licensed under the MIT License.
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
Built Distribution
File details
Details for the file rowfind-0.2.0.tar.gz
.
File metadata
- Download URL: rowfind-0.2.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91e2f99fbe44158f28a357a3992a9b95f16b11c45528cdfb5d516a4fd121b37e |
|
MD5 | 02a21940b0eae667ef2408b272ce47a6 |
|
BLAKE2b-256 | 20530dafbcd07f37eff21613a8ae41524235de0ce856aba5485506f503a1c4ba |
File details
Details for the file rowfind-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: rowfind-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 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 | 546442628628eb1472c63ce3f18429a7f72288beeb7628fe53531242c8abcbd3 |
|
MD5 | 893572118f3d7e4eb98ea0f2d6cc890a |
|
BLAKE2b-256 | 3c967b0e07b1ff327318dd14ad0ec63c3cc8d2c424d71504b8afe24dcc2eb8d4 |