A pure Python Quadtree implementation.
Project description
quads
A pure Python Quadtree implementation.
Quadtrees are a useful data structure for sparse datasets where the location/position of the data is important. They're especially good for spatial indexing & image processing.
An actual visualization of a quads.QuadTree
:
Usage
>>> import quads
>>> tree = quads.QuadTree(
... (0, 0), # The center point
... 10, # The width
... 10, # The height
... )
# You can choose to simply represent points that exist.
>>> tree.insert((1, 2))
True
# ...or include extra data at those points.
>>> tree.insert(quads.Point(4, -3, data="Samus"))
True
# You can search for a given point. It returns the point if found...
>>> tree.find((1, 2))
Point(1, 2)
# Or `None` if there's no match.
>>> tree.find((4, -4))
None
# You can also find all the points within a given region.
>>> bb = quads.BoundingBox(min_x=-1, min_y=-2, max_x=2, max_y=2)
>>> tree.within_bb(bb)
[Point(1, 2)]
# You can also search to find the nearest neighbors of a point, even
# if that point doesn't have data within the quadtree.
>>> tree.nearest_neighbors((0, 1), count=2)
[
Point(1, 2),
Point(4, -4),
]
# And if you have `matplotlib` installed (not required!), you can visualize
# the tree.
>>> quads.visualize(tree)
Installation
$ pip install quads
Requirements
- Python 3.7+ (untested on older versions but may work)
Running Tests
$ git clone https://github.com/toastdriven/quads.git
$ cd quads
$ poetry install
$ poetry shell
# Just the tests.
$ pytest .
# With coverage.
$ pytest -s --cov=quads .
# And with pretty reports.
$ pytest -s --cov=quads . && coverage html
License
New BSD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
quads-1.0.1.tar.gz
(9.2 kB
view details)
Built Distribution
quads-1.0.1-py3-none-any.whl
(9.1 kB
view details)
File details
Details for the file quads-1.0.1.tar.gz
.
File metadata
- Download URL: quads-1.0.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.4 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3263f56fb66071e13737dd134def41e259425feb1b9d197455332168e18c9528 |
|
MD5 | 2a4f75b294c10f311e31336a3e7d0a1d |
|
BLAKE2b-256 | 52ee47fbb1eeb1f2cc4fc28a880f0b6ca2b61cfd133558381f7be1eae408f384 |
File details
Details for the file quads-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: quads-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.4 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1c2aa1753dd04380f6a963090c6304a032cf7769464fb6d38fd3e2e45723ae8 |
|
MD5 | 714c5d9ccfada0bc26a8ae4b3a297806 |
|
BLAKE2b-256 | be274bc8c654284e3319c4f246bdaacea053bb5995309be2c4da86d6b9b42e31 |