Skip to content

Commit 1244886

Browse files
authored
Fix missing last slice in tiled cubing (#47)
* change get_regular_chunks to treat min and max as both inclusive (fixes #42) * fix formatting
1 parent 1e145a4 commit 1244886

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ def test_get_regular_chunks():
1818
assert len(target) == 6
1919
assert list(target[0]) == list(range(0, 8))
2020
assert list(target[-1]) == list(range(40, 48))
21+
22+
23+
def test_get_regular_chunks_max_inclusive():
24+
target = list(get_regular_chunks(4, 44, 1))
25+
26+
assert len(target) == 41
27+
assert list(target[0]) == list(range(4, 5))
28+
# The last chunk should include 44
29+
assert list(target[-1]) == list(range(44, 45))

wkcuber/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ def get_chunks(arr, chunk_size):
6363
yield arr[i : i + chunk_size]
6464

6565

66+
# min_z and max_z are both inclusive
6667
def get_regular_chunks(min_z, max_z, chunk_size):
6768
i = floor(min_z / chunk_size) * chunk_size
68-
while i < ceil(max_z / chunk_size) * chunk_size:
69+
while i < ceil((max_z + 1) / chunk_size) * chunk_size:
6970
yield range(i, i + chunk_size)
7071
i += chunk_size
7172

0 commit comments

Comments
 (0)