fastquadtree 0.6.1__cp38-abi3-win_amd64.whl → 0.7.0__cp38-abi3-win_amd64.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 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__ = ("_bounds", "_count", "_items", "_native", "_next_id")
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(bounds, capacity)
71
+ self._native = _RustQuadTree(self._bounds, self._capacity)
61
72
  else:
62
- self._native = _RustQuadTree(bounds, capacity, max_depth=max_depth)
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
@@ -36,6 +36,7 @@ class QuadTree:
36
36
  # Deletions
37
37
  def delete(self, id_: int, xy: Point) -> bool: ...
38
38
  def delete_by_object(self, obj: Any) -> bool: ...
39
+ def clear(self, *, reset_ids: bool = False) -> None: ...
39
40
 
40
41
  # Queries
41
42
  @overload
fastquadtree/_native.pyd CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastquadtree
3
- Version: 0.6.1
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
+ [![Docs](https://img.shields.io/badge/docs-online-brightgreen)](https://elan456.github.io/fastquadtree/)
33
41
  [![PyPI version](https://img.shields.io/pypi/v/fastquadtree.svg)](https://pypi.org/project/fastquadtree/)
34
42
  [![Python versions](https://img.shields.io/pypi/pyversions/fastquadtree.svg)](https://pypi.org/project/fastquadtree/)
35
43
  [![Wheels](https://img.shields.io/pypi/wheel/fastquadtree.svg)](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 keeps Python overhead low: raw tuple results by default, `Item` wrappers only when requested.
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
- Check the CLI arguments for the cross-library benchmark in `benchmarks/quadtree_bench/main.py`.
286
+ ### Pygame Ball Pit Demo
287
+
288
+ ![Ballpit_Demo_Screenshot](https://raw.githubusercontent.com/Elan456/fastquadtree/main/assets/ballpit.png)
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=19O4oecQfX8PIgl0uy9SpM9vc3clkiHWYHyaKYJ8UEM,11867
2
+ fastquadtree-0.7.0.dist-info/WHEEL,sha256=CG8OzNtm0LMpJ2zhrjswlO8N-965OeMLklsQAG-nMvQ,94
3
+ fastquadtree-0.7.0.dist-info/licenses/LICENSE,sha256=46IVFhoCIwMo-ocq4olyEB1eBvvtaKic5yGLeKXnDuc,1092
4
+ fastquadtree/__init__.py,sha256=ACXdXobZxuh1tNM2HfXyl_bLS5s8zXgD29AUiVvba44,13471
5
+ fastquadtree/__init__.pyi,sha256=ngFGDYWTB7AdR0k9ujstsGPnQh9wU0H0_GPiNm7HDhY,2124
6
+ fastquadtree/_bimap.py,sha256=SPFFw9hWAVRKZVXyDGYFFNw4MLV8qUlOq8gDbLcTqkg,3402
7
+ fastquadtree/_item.py,sha256=p-ymnE9S-c8Lc00KhNKN9Pt4bd05nZ6g-DB8q8D9zYk,533
8
+ fastquadtree/_native.pyd,sha256=k7Wlr44ED8FZY-rCRp7SzrThf6BooXWxMvkxBTfrDA4,254464
9
+ fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ fastquadtree-0.7.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.9.5)
2
+ Generator: maturin (1.9.6)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp38-abi3-win_amd64
@@ -1,10 +0,0 @@
1
- fastquadtree-0.6.1.dist-info/METADATA,sha256=H8lkeuXlgH2BCxZSzEvFAKnLANM4H52NG78hT7AObUk,10746
2
- fastquadtree-0.6.1.dist-info/WHEEL,sha256=F7HFsRl56IeLjGhxiHeG3IpurHNaGNHQJeIy7gdwTO4,94
3
- fastquadtree-0.6.1.dist-info/licenses/LICENSE,sha256=46IVFhoCIwMo-ocq4olyEB1eBvvtaKic5yGLeKXnDuc,1092
4
- fastquadtree/__init__.py,sha256=o7zH6lOu2lTxMafl9FNVZiecM0KVxqhC3FNSRbpaaqY,12435
5
- fastquadtree/__init__.pyi,sha256=_HGJ9lpIZ9-JTSfMKSn8aif_tu60m2vgOXR4d0uXnRY,2062
6
- fastquadtree/_bimap.py,sha256=SPFFw9hWAVRKZVXyDGYFFNw4MLV8qUlOq8gDbLcTqkg,3402
7
- fastquadtree/_item.py,sha256=p-ymnE9S-c8Lc00KhNKN9Pt4bd05nZ6g-DB8q8D9zYk,533
8
- fastquadtree/_native.pyd,sha256=OHlc3FG-kZbjt2YW2QM9I809C1FRQlV6RQXcPcQLNhM,254464
9
- fastquadtree/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- fastquadtree-0.6.1.dist-info/RECORD,,