fastquadtree 0.6.1__cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl → 0.7.0__cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastquadtree/__init__.py +40 -4
- fastquadtree/__init__.pyi +1 -0
- fastquadtree/_native.abi3.so +0 -0
- {fastquadtree-0.6.1.dist-info → fastquadtree-0.7.0.dist-info}/METADATA +31 -8
- fastquadtree-0.7.0.dist-info/RECORD +10 -0
- {fastquadtree-0.6.1.dist-info → fastquadtree-0.7.0.dist-info}/WHEEL +1 -1
- fastquadtree-0.6.1.dist-info/RECORD +0 -10
- {fastquadtree-0.6.1.dist-info → fastquadtree-0.7.0.dist-info}/licenses/LICENSE +0 -0
fastquadtree/__init__.py
CHANGED
@@ -45,7 +45,15 @@ class QuadTree:
|
|
45
45
|
ValueError: If parameters are invalid or inserts are out of bounds.
|
46
46
|
"""
|
47
47
|
|
48
|
-
__slots__ = (
|
48
|
+
__slots__ = (
|
49
|
+
"_bounds",
|
50
|
+
"_capacity",
|
51
|
+
"_count",
|
52
|
+
"_items",
|
53
|
+
"_max_depth",
|
54
|
+
"_native",
|
55
|
+
"_next_id",
|
56
|
+
)
|
49
57
|
|
50
58
|
def __init__(
|
51
59
|
self,
|
@@ -56,14 +64,18 @@ class QuadTree:
|
|
56
64
|
track_objects: bool = False,
|
57
65
|
start_id: int = 1,
|
58
66
|
):
|
67
|
+
self._bounds = bounds
|
68
|
+
self._max_depth = max_depth # store for clear()
|
69
|
+
self._capacity = capacity # store for clear()
|
59
70
|
if max_depth is None:
|
60
|
-
self._native = _RustQuadTree(
|
71
|
+
self._native = _RustQuadTree(self._bounds, self._capacity)
|
61
72
|
else:
|
62
|
-
self._native = _RustQuadTree(
|
73
|
+
self._native = _RustQuadTree(
|
74
|
+
self._bounds, self._capacity, max_depth=max_depth
|
75
|
+
)
|
63
76
|
self._items: BiMap | None = BiMap() if track_objects else None
|
64
77
|
self._next_id: int = int(start_id)
|
65
78
|
self._count: int = 0
|
66
|
-
self._bounds = bounds
|
67
79
|
|
68
80
|
# ---------- inserts ----------
|
69
81
|
|
@@ -148,6 +160,8 @@ class QuadTree:
|
|
148
160
|
raise KeyError(f"Id {id_} not found in quadtree")
|
149
161
|
self._items.add(Item(id_, item.x, item.y, obj))
|
150
162
|
|
163
|
+
# ---------- deletes ----------
|
164
|
+
|
151
165
|
def delete(self, id_: int, xy: Point) -> bool:
|
152
166
|
"""
|
153
167
|
Delete an item by id and exact coordinates.
|
@@ -193,6 +207,28 @@ class QuadTree:
|
|
193
207
|
|
194
208
|
return self.delete(item.id_, (item.x, item.y))
|
195
209
|
|
210
|
+
def clear(self, *, reset_ids: bool = False) -> None:
|
211
|
+
"""
|
212
|
+
Empty the tree in place, preserving bounds/capacity/max_depth.
|
213
|
+
|
214
|
+
Args:
|
215
|
+
reset_ids: If True, restart auto-assigned ids from 1.
|
216
|
+
"""
|
217
|
+
# swap in a fresh native instance
|
218
|
+
if self._max_depth is None:
|
219
|
+
self._native = _RustQuadTree(self._bounds, self._capacity)
|
220
|
+
else:
|
221
|
+
self._native = _RustQuadTree(
|
222
|
+
self._bounds, self._capacity, max_depth=self._max_depth
|
223
|
+
)
|
224
|
+
|
225
|
+
# reset Python-side trackers
|
226
|
+
self._count = 0
|
227
|
+
if self._items is not None:
|
228
|
+
self._items.clear()
|
229
|
+
if reset_ids:
|
230
|
+
self._next_id = 1
|
231
|
+
|
196
232
|
# ---------- queries ----------
|
197
233
|
|
198
234
|
@overload
|
fastquadtree/__init__.pyi
CHANGED
fastquadtree/_native.abi3.so
CHANGED
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fastquadtree
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Classifier: Programming Language :: Python :: 3
|
5
5
|
Classifier: Programming Language :: Python :: 3 :: Only
|
6
6
|
Classifier: Programming Language :: Rust
|
@@ -17,6 +17,12 @@ Requires-Dist: pytest-cov>=4.1 ; extra == 'dev'
|
|
17
17
|
Requires-Dist: coverage>=7.5 ; extra == 'dev'
|
18
18
|
Requires-Dist: mypy>=1.10 ; extra == 'dev'
|
19
19
|
Requires-Dist: build>=1.2.1 ; extra == 'dev'
|
20
|
+
Requires-Dist: mkdocs>=1.6 ; extra == 'dev'
|
21
|
+
Requires-Dist: mkdocs-material ; extra == 'dev'
|
22
|
+
Requires-Dist: mkdocstrings[python] ; extra == 'dev'
|
23
|
+
Requires-Dist: mkdocs-autorefs ; extra == 'dev'
|
24
|
+
Requires-Dist: mkdocs-git-revision-date-localized-plugin ; extra == 'dev'
|
25
|
+
Requires-Dist: mkdocs-minify-plugin ; extra == 'dev'
|
20
26
|
Provides-Extra: dev
|
21
27
|
License-File: LICENSE
|
22
28
|
Summary: Rust-accelerated quadtree for Python with fast inserts, range queries, and k-NN search.
|
@@ -26,10 +32,12 @@ Requires-Python: >=3.8
|
|
26
32
|
Description-Content-Type: text/markdown
|
27
33
|
Project-URL: Homepage, https://github.com/Elan456/fastquadtree
|
28
34
|
Project-URL: Repository, https://github.com/Elan456/fastquadtree
|
35
|
+
Project-URL: Documentation, https://elan456.github.io/fastquadtree/
|
29
36
|
Project-URL: Issues, https://github.com/Elan456/fastquadtree/issues
|
30
37
|
|
31
38
|
# fastquadtree
|
32
39
|
|
40
|
+
[](https://elan456.github.io/fastquadtree/)
|
33
41
|
[](https://pypi.org/project/fastquadtree/)
|
34
42
|
[](https://pypi.org/project/fastquadtree/)
|
35
43
|
[](https://pypi.org/project/fastquadtree/#files)
|
@@ -51,6 +59,8 @@ Project-URL: Issues, https://github.com/Elan456/fastquadtree/issues
|
|
51
59
|
|
52
60
|
Rust-optimized quadtree with a simple Python API.
|
53
61
|
|
62
|
+
👉 **Docs:** https://elan456.github.io/fastquadtree/
|
63
|
+
|
54
64
|
- Python package: **`fastquadtree`**
|
55
65
|
- Python ≥ 3.8
|
56
66
|
- Import path: `from fastquadtree import QuadTree`
|
@@ -171,6 +181,8 @@ qt.attach(123, my_object) # binds object to id 123
|
|
171
181
|
|
172
182
|
## API
|
173
183
|
|
184
|
+
[Full api for QuadTree](https://elan456.github.io/fastquadtree/api/quadtree/)
|
185
|
+
|
174
186
|
### `QuadTree(bounds, capacity, max_depth=None, track_objects=False, start_id=1)`
|
175
187
|
|
176
188
|
* `bounds` — tuple `(min_x, min_y, max_x, max_y)` defines the 2D area covered by the quadtree
|
@@ -181,8 +193,6 @@ qt.attach(123, my_object) # binds object to id 123
|
|
181
193
|
|
182
194
|
### Core Methods
|
183
195
|
|
184
|
-
Full docs are in the docstrings of the [Python Shim](pysrc/fastquadtree/__init__.py)
|
185
|
-
|
186
196
|
- `insert(xy, *, id=None, obj=None) -> int`
|
187
197
|
|
188
198
|
- `insert_many_points(points) -> int`
|
@@ -197,6 +207,8 @@ Full docs are in the docstrings of the [Python Shim](pysrc/fastquadtree/__init__
|
|
197
207
|
|
198
208
|
- `delete_by_object(obj) -> bool (requires track_objects=True)`
|
199
209
|
|
210
|
+
- `clear(*, reset_ids=False) -> None`
|
211
|
+
|
200
212
|
- `attach(id, obj) -> None (requires track_objects=True)`
|
201
213
|
|
202
214
|
- `count_items() -> int`
|
@@ -205,6 +217,8 @@ Full docs are in the docstrings of the [Python Shim](pysrc/fastquadtree/__init__
|
|
205
217
|
|
206
218
|
- `get_all_rectangles() -> list[tuple] (for visualization)`
|
207
219
|
|
220
|
+
- `get_all_objects() -> list[object] (requires track_objects=True)`
|
221
|
+
|
208
222
|
### `Item` (returned when `as_items=True`)
|
209
223
|
|
210
224
|
* Attributes: `id`, `x`, `y`, and a lazy `obj` property
|
@@ -222,7 +236,7 @@ Full docs are in the docstrings of the [Python Shim](pysrc/fastquadtree/__init__
|
|
222
236
|
* Choose `capacity` so that leaves keep a small batch of points. Typical values are 8 to 64.
|
223
237
|
* If your data is very skewed, set a `max_depth` to prevent long chains.
|
224
238
|
* For fastest local runs, use `maturin develop --release`.
|
225
|
-
* The wrapper
|
239
|
+
* The wrapper only maintains an ID -> Obj map only if the quadtree was constructed with `track_objects=True`. If you don't need it, leave it off for best performance. Look at the [Native vs Shim Benchmark](#native-vs-shim-benchmark) below for details.
|
226
240
|
|
227
241
|
|
228
242
|
### Native vs Shim Benchmark
|
@@ -259,6 +273,8 @@ python benchmarks/cross_library_bench.py
|
|
259
273
|
python benchmarks/benchmark_native_vs_shim.py
|
260
274
|
```
|
261
275
|
|
276
|
+
Check the CLI arguments for the cross-library benchmark in `benchmarks/quadtree_bench/main.py`.
|
277
|
+
|
262
278
|
## Run Visualizer
|
263
279
|
A visualizer is included to help you understand how the quadtree subdivides space.
|
264
280
|
|
@@ -267,7 +283,17 @@ pip install -r interactive/requirements.txt
|
|
267
283
|
python interactive/interactive_v2.py
|
268
284
|
```
|
269
285
|
|
270
|
-
|
286
|
+
### Pygame Ball Pit Demo
|
287
|
+
|
288
|
+

|
289
|
+
|
290
|
+
A simple demo of moving objects with collision detection using **fastquadtree**.
|
291
|
+
You can toggle between quadtree mode and brute-force mode to see the performance difference.
|
292
|
+
|
293
|
+
```bash
|
294
|
+
pip install -r interactive/requirements.txt
|
295
|
+
python interactive/ball_pit.py
|
296
|
+
```
|
271
297
|
|
272
298
|
## FAQ
|
273
299
|
|
@@ -280,9 +306,6 @@ Yes! Use `delete(id, xy)` to remove specific items. You must provide both the ID
|
|
280
306
|
**Can I store rectangles or circles?**
|
281
307
|
The core stores points. To index objects with extent, insert whatever representative point you choose. For rectangles you can insert centers or build an AABB tree separately.
|
282
308
|
|
283
|
-
**Threading**
|
284
|
-
Use one tree per thread if you need heavy parallel inserts from Python.
|
285
|
-
|
286
309
|
## License
|
287
310
|
|
288
311
|
MIT. See `LICENSE`.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
fastquadtree-0.7.0.dist-info/METADATA,sha256=gsT_uIc02P4JQGjr-IztNxfXrwWM1G2KWlAaFqDqqcw,11579
|
2
|
+
fastquadtree-0.7.0.dist-info/WHEEL,sha256=xBqaWU3Z-cfW-EFy0ENuEqxgXZXkIHUBkA1cT6FlqGM,127
|
3
|
+
fastquadtree-0.7.0.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
|
4
|
+
fastquadtree/__init__.py,sha256=FLmc7i4rs9D8D27x7fx4Xu4tt9PbEcXMRikpnM_PyTE,13054
|
5
|
+
fastquadtree/__init__.pyi,sha256=UXKcyhJix2f7AQSV70mDZLij-DHlPmXTMFT7JnmegIw,2053
|
6
|
+
fastquadtree/_bimap.py,sha256=pWY4O4BmOa78r4MnBMfpb-hYZ222U8mEMy4pnosgXLQ,3290
|
7
|
+
fastquadtree/_item.py,sha256=9Tk4wUZLFsjIhWALJ9xGW4bknvU_xfy2Na3ixWxh_xI,509
|
8
|
+
fastquadtree/_native.abi3.so,sha256=BQzAi1gBVv6A6yVlwu7eOrjWSseal2UWnkQm_yEnRco,442700
|
9
|
+
fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
fastquadtree-0.7.0.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
fastquadtree-0.6.1.dist-info/METADATA,sha256=ttnNs9M-mAPdUlOLj23Bq1Ewa_FwxB_pZDQevu3k1Ho,10474
|
2
|
-
fastquadtree-0.6.1.dist-info/WHEEL,sha256=2vnU-32JXJk0SYcmjtO3vqL3704xvTJTvVuuZZ_A2lA,127
|
3
|
-
fastquadtree-0.6.1.dist-info/licenses/LICENSE,sha256=pRuvcuqIMtEUBMgvP1Bc4fOHydzeuA61c6DQoQ1pb1w,1071
|
4
|
-
fastquadtree/__init__.py,sha256=1hCXNpz85X_UC4JqKj4AseFe0HNMM6yFWH3r8rNgX9U,12054
|
5
|
-
fastquadtree/__init__.pyi,sha256=NkLrhMy9HkcqdeEfmK6D9c01w-chiNope7DA4PyTeNQ,1992
|
6
|
-
fastquadtree/_bimap.py,sha256=pWY4O4BmOa78r4MnBMfpb-hYZ222U8mEMy4pnosgXLQ,3290
|
7
|
-
fastquadtree/_item.py,sha256=9Tk4wUZLFsjIhWALJ9xGW4bknvU_xfy2Na3ixWxh_xI,509
|
8
|
-
fastquadtree/_native.abi3.so,sha256=toVPA2B7hHGYGIxrAZZio_vM-B3SlqqckPBqhALWo7I,442716
|
9
|
-
fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
fastquadtree-0.6.1.dist-info/RECORD,,
|
File without changes
|