跳转到主要内容

纯Python Quadtree实现。

项目描述

quads

Documentation Status CI

纯Python Quadtree实现。

Quadtrees 是一种适用于数据稀疏且位置重要的情况的有用数据结构。它们特别适合于空间索引和图像处理。

实际的 quads.QuadTree 可视化

quadtree_viz

用法

完整文档请见 https://quads.readthedocs.io/en/latest/

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

安装

$ pip install quads

需求

  • Python 3.7+(在旧版本上未经测试,但可能可行)

运行测试

$ 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

许可证

New BSD

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分布

quads-1.1.0.tar.gz (9.6 kB 查看哈希值)

上传于 源代码

构建分发

quads-1.1.0-py3-none-any.whl (9.4 kB 查看哈希值)

上传于 Python 3

由以下支持