Skip to main content

A pure Python Quadtree implementation.

Reason this release was yanked:

This was a beta version of the package, but lacks that in the version.

Project description

quads

A pure Python Quadtree implementation.

Quadtrees are a useful data structure for sparse datasets where the position of the data is important. They're especially for spatial indexing & image processing.

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)]

Setup

$ 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

$ pytest .

License

New BSD

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

quads-1.0.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

quads-1.0.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page