mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-07 20:20:17 +00:00
Compare commits
4 Commits
7d6b911a30
...
ad1b278a9b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad1b278a9b | ||
|
|
b3f41afe34 | ||
|
|
33ee388e4d | ||
|
|
9d19485bc5 |
@ -102,8 +102,8 @@ class array2d[T](array2d_like[T]):
|
||||
|
||||
|
||||
class chunked_array2d[T, TContext]:
|
||||
def __init__(
|
||||
self,
|
||||
def __new__(
|
||||
cls,
|
||||
chunk_size: int,
|
||||
default: T = None,
|
||||
context_builder: Callable[[vec2i], TContext] | None = None,
|
||||
@ -116,6 +116,7 @@ class chunked_array2d[T, TContext]:
|
||||
def __setitem__(self, index: vec2i, value: T): ...
|
||||
def __delitem__(self, index: vec2i): ...
|
||||
def __iter__(self) -> Iterator[tuple[vec2i, TContext]]: ...
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
def clear(self) -> None: ...
|
||||
|
||||
|
||||
@ -1017,7 +1017,7 @@ static bool chunked_array2d__clear(int argc, py_Ref argv) {
|
||||
|
||||
static bool chunked_array2d__world_to_chunk(int argc, py_Ref argv) {
|
||||
PY_CHECK_ARGC(2);
|
||||
PY_CHECK_ARG_TYPE(1, tp_vec2);
|
||||
PY_CHECK_ARG_TYPE(1, tp_vec2i);
|
||||
c11_chunked_array2d* self = py_touserdata(argv);
|
||||
c11_vec2i pos = py_tovec2i(&argv[1]);
|
||||
c11_vec2i chunk_pos, local_pos;
|
||||
|
||||
@ -1,13 +1,43 @@
|
||||
from array2d import chunked_array2d
|
||||
import array2d
|
||||
from linalg import vec2i
|
||||
|
||||
a = chunked_array2d(4, default=0)
|
||||
|
||||
print(iter(a))
|
||||
print(list(a))
|
||||
def on_builder(a:vec2i):
|
||||
return str(a)
|
||||
pass
|
||||
|
||||
a[vec2i.ONE] = 1
|
||||
default = 0
|
||||
a = array2d.chunked_array2d(16, default,on_builder)
|
||||
assert a.chunk_size == 16
|
||||
|
||||
print(a.view().render())
|
||||
print(list(a))
|
||||
a[vec2i(16, 16)] = 16
|
||||
a[vec2i(15, 16)] = 15
|
||||
assert a[vec2i(16, 16)] == 16
|
||||
assert a[vec2i(15, 16)] == 15
|
||||
assert a[vec2i(16, 15)] == default
|
||||
|
||||
a1,a2=a.world_to_chunk(vec2i(15,16))
|
||||
|
||||
assert a.remove_chunk(a1)== True
|
||||
assert a[vec2i(15, 16)] == default
|
||||
|
||||
assert a.get_context(vec2i(1,1))==on_builder(vec2i(1,1))
|
||||
|
||||
assert a.view().tolist()==[
|
||||
[16 if i==0 and j==0 else 0 for j in range(16)] for i in range(16)
|
||||
]
|
||||
assert a.view_rect(vec2i(15,15),4,4).tolist()==[
|
||||
[0,0,0,0],
|
||||
[0,16,0,0],
|
||||
[0,0,0,0],
|
||||
[0,0,0,0]
|
||||
]
|
||||
a[vec2i(15, 16)] = 15
|
||||
assert a.view_chunk(a1).tolist()==[
|
||||
[15 if i==0 and j==15 else 0 for j in range(16)] for i in range(16)
|
||||
]
|
||||
a.clear()
|
||||
|
||||
assert a[vec2i(16, 16)] == default
|
||||
assert a[vec2i(15, 16)] == default
|
||||
assert a[vec2i(16, 15)] == default
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user