纯Python Quadtree实现。
项目描述
quads
纯Python Quadtree实现。
Quadtrees 是一种适用于数据稀疏且位置重要的情况的有用数据结构。它们特别适合于空间索引和图像处理。
实际的 quads.QuadTree
可视化
用法
完整文档请见 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 查看哈希值)
关闭
quads-1.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 59c1d86e551a734ea83c61c185c84873cf604b54bbacdfdbce831067715ecc7e |
|
MD5 | a4b4379fadbddd3e8bcaae1688e79528 |
|
BLAKE2b-256 | 74c7257b7c30a7483e7cc699d0faf1695a04d3251f955789339a8d8f50c74008 |
关闭
quads-1.1.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4f2a05381f07fdf6d61352b0893819b2c52ae2286211c74bd9639a28d6424540 |
|
MD5 | 808d7c3c9d1c350fa04f2cf981b28a2a |
|
BLAKE2b-256 | 0a18053514fdacc17ac4439496e44ccc99547e1672afce1536a2a8e84aacf5c2 |