Skip to content

Commit d349297

Browse files
authored
Merge pull request #2 from Elan456/feat/insert-rectangles
Feat/insert rectangles
2 parents 7e3dade + 9cf3a8d commit d349297

29 files changed

+1361
-576
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Allowed. For k-nearest, duplicates are de-duplicated by id. For range queries yo
134134
Yes! Use `delete(id, xy)` to remove specific items. You must provide both the ID and exact location for precise deletion. This handles cases where multiple items exist at the same location. If you're using `track_objects=True`, you can also use `delete_by_object(obj)` for convenient object-based deletion with O(1) lookup. The tree automatically merges nodes when item counts drop below capacity.
135135

136136
**Can I store rectangles or circles?**
137-
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.
137+
Yes, you can store rectangles using the `RectQuadTree` class. Circles can be approximated with bounding boxes. See the [RectQuadTree docs](https://elan456.github.io/fastquadtree/api/rect_quadtree/) for details.
138138

139139
## License
140140

benchmarks/quadtree_bench/engines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _create_fastquadtree_engine(
104104

105105
def build(points):
106106
qt = RustQuadTree(bounds, max_points, max_depth=max_depth)
107-
qt.insert_many_points(points)
107+
qt.insert_many(points)
108108
return qt
109109

110110
def query(qt, queries):

docs/api/item.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/api/point_item.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# fastquadtree.PointItem
2+
::: fastquadtree.PointItem
3+
options:
4+
inherited_members: true

docs/api/quadtree.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# fastquadtree.QuadTree
22
::: fastquadtree.QuadTree
3+
options:
4+
inherited_members: true

docs/api/rect_item.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# fastquadtree.RectItem
2+
::: fastquadtree.RectItem
3+
options:
4+
inherited_members: true

docs/api/rect_quadtree.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# fastquadtree.RectQuadTree
2+
::: fastquadtree.RectQuadTree
3+
options:
4+
inherited_members: true

docs/quickstart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pts = [(random.random()*1000, random.random()*1000) for _ in range(N)]
116116
qt = QuadTree((0, 0, 1000, 1000), capacity=32)
117117

118118
t0 = time.perf_counter()
119-
qt.insert_many_points(pts)
119+
qt.insert_many(pts)
120120
t1 = time.perf_counter()
121121

122122
hits = qt.query((250, 250, 750, 750))
@@ -132,4 +132,4 @@ print(f"Build: {(t1-t0):.3f}s Query: {(t2-t1):.3f}s Hits: {len(hits)}")
132132
* **Use `capacity` 8 to 64** for most workloads
133133
If data is highly skewed, set a `max_depth` to avoid very deep trees.
134134
* **Use `clear()` to reset** when most points are moving rather than deleting and reinserting.
135-
* **Use `insert_many_points()`** to bulk load a large batch of points at once.
135+
* **Use `insert_many()`** to bulk load a large batch of points at once.

docs/runnables.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ python interactive/interactive_v2.py
1212

1313
![Interactive_V2_Screenshot](https://raw.githubusercontent.com/Elan456/fastquadtree/main/assets/interactive_v2_screenshot.png)
1414

15+
## 1.5 Interactive Demo with Rectangles
16+
- Similar to the above demo, but uses rectangles instead of points
17+
- If the rectangles intersect at all with the query area, they will be highlighted in red
18+
19+
```bash
20+
pip install -r interactive/requirements.txt
21+
python interactive/interactive_v2_rect.py
22+
```
1523

1624
## 2. Ball Pit
1725
- Spawn balls in a pit with physics-based collisions

interactive/interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def draw_quadtree(tree: QuadTree):
19-
bboxs = tree.get_all_rectangles()
19+
bboxs = tree.get_all_node_boundaries()
2020
for bbox in bboxs:
2121
rect = (
2222
bbox[0] - camera_x,

0 commit comments

Comments
 (0)