mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-08 20:50:16 +00:00
Compare commits
No commits in common. "ad1b278a9b20e2caaba4bb12f986cbf4f011f805" and "7d6b911a306f842a4f0b10bb1dc05dc77ab323b9" have entirely different histories.
ad1b278a9b
...
7d6b911a30
@ -102,8 +102,8 @@ class array2d[T](array2d_like[T]):
|
|||||||
|
|
||||||
|
|
||||||
class chunked_array2d[T, TContext]:
|
class chunked_array2d[T, TContext]:
|
||||||
def __new__(
|
def __init__(
|
||||||
cls,
|
self,
|
||||||
chunk_size: int,
|
chunk_size: int,
|
||||||
default: T = None,
|
default: T = None,
|
||||||
context_builder: Callable[[vec2i], TContext] | None = None,
|
context_builder: Callable[[vec2i], TContext] | None = None,
|
||||||
@ -116,7 +116,6 @@ class chunked_array2d[T, TContext]:
|
|||||||
def __setitem__(self, index: vec2i, value: T): ...
|
def __setitem__(self, index: vec2i, value: T): ...
|
||||||
def __delitem__(self, index: vec2i): ...
|
def __delitem__(self, index: vec2i): ...
|
||||||
def __iter__(self) -> Iterator[tuple[vec2i, TContext]]: ...
|
def __iter__(self) -> Iterator[tuple[vec2i, TContext]]: ...
|
||||||
def __len__(self) -> int: ...
|
|
||||||
|
|
||||||
def clear(self) -> None: ...
|
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) {
|
static bool chunked_array2d__world_to_chunk(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(2);
|
PY_CHECK_ARGC(2);
|
||||||
PY_CHECK_ARG_TYPE(1, tp_vec2i);
|
PY_CHECK_ARG_TYPE(1, tp_vec2);
|
||||||
c11_chunked_array2d* self = py_touserdata(argv);
|
c11_chunked_array2d* self = py_touserdata(argv);
|
||||||
c11_vec2i pos = py_tovec2i(&argv[1]);
|
c11_vec2i pos = py_tovec2i(&argv[1]);
|
||||||
c11_vec2i chunk_pos, local_pos;
|
c11_vec2i chunk_pos, local_pos;
|
||||||
|
|||||||
@ -1,43 +1,13 @@
|
|||||||
import array2d
|
from array2d import chunked_array2d
|
||||||
from linalg import vec2i
|
from linalg import vec2i
|
||||||
|
|
||||||
|
a = chunked_array2d(4, default=0)
|
||||||
|
|
||||||
def on_builder(a:vec2i):
|
print(iter(a))
|
||||||
return str(a)
|
print(list(a))
|
||||||
pass
|
|
||||||
|
|
||||||
default = 0
|
a[vec2i.ONE] = 1
|
||||||
a = array2d.chunked_array2d(16, default,on_builder)
|
|
||||||
assert a.chunk_size == 16
|
|
||||||
|
|
||||||
a[vec2i(16, 16)] = 16
|
print(a.view().render())
|
||||||
a[vec2i(15, 16)] = 15
|
print(list(a))
|
||||||
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