Skip to content

Commit 7bb7e5e

Browse files
committed
feat: automatically convert bounds list to tuple in constructor
1 parent aa90c97 commit 7bb7e5e

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastquadtree"
3-
version = "1.4.0"
3+
version = "1.4.1"
44
edition = "2021"
55

66
[lib]

pysrc/fastquadtree/_base_quadtree.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,20 @@ def __init__(
9191
track_objects: bool = False,
9292
dtype: str = "f32",
9393
):
94+
# Handle some bounds validation and list --> tuple conversion
95+
if type(bounds) is not tuple:
96+
bounds = tuple(bounds) # pyright: ignore[reportAssignmentType]
97+
if len(bounds) != 4:
98+
raise ValueError(
99+
"bounds must be a tuple of four numeric values (x min, y min, x max, y max)"
100+
)
101+
94102
self._bounds = bounds
103+
95104
self._max_depth = max_depth
96105
self._capacity = capacity
97106
self._dtype = dtype
98-
self._native = self._new_native(bounds, capacity, max_depth)
107+
self._native = self._new_native(self._bounds, self._capacity, self._max_depth)
99108

100109
self._track_objects = bool(track_objects)
101110
self._store: ObjStore[ItemType] | None = ObjStore() if track_objects else None

tests/test_wrapper_edges.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,17 @@ def test_insert_many_exception_for_out_of_bounds():
163163

164164
with pytest.raises(ValueError):
165165
qt.insert_many(points)
166+
167+
168+
def test_construct_quadtree_with_list_bounds():
169+
bounds_list = [0.0, 0.0, 500.0, 500.0]
170+
qt = QuadTree(bounds_list, capacity=4) # pyright: ignore[reportArgumentType]
171+
assert qt._bounds == (0.0, 0.0, 500.0, 500.0)
172+
173+
174+
def test_construct_quadtree_with_invalid_bounds_length():
175+
bounds_invalid = (0.0, 0.0, 500.0) # Only three values instead of four
176+
with pytest.raises(
177+
ValueError, match="bounds must be a tuple of four numeric values"
178+
):
179+
QuadTree(bounds_invalid, capacity=4) # pyright: ignore[reportArgumentType]

0 commit comments

Comments
 (0)