Skip to main content

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.

Metadata

Release files for rowfind 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rowfind 0.2.0
File Size Uploaded
rowfind-0.2.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rowfind 0.2.0
File Interpreter ABI Platform
rowfind-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / rowfind-0.2.0.tar.gz

Download URL rowfind-0.2.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
91e2f99fbe44158f28a357a3992a9b95f16b11c45528cdfb5d516a4fd121b37e
BLAKE2b-256 checksum
How to use checksums
20530dafbcd07f37eff21613a8ae41524235de0ce856aba5485506f503a1c4ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / rowfind-0.2.0-py3-none-any.whl

Download URL rowfind-0.2.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
546442628628eb1472c63ce3f18429a7f72288beeb7628fe53531242c8abcbd3
BLAKE2b-256 checksum
How to use checksums
3c967b0e07b1ff327318dd14ad0ec63c3cc8d2c424d71504b8afe24dcc2eb8d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page