mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 03:50:16 +00:00
backup
This commit is contained in:
parent
a27e0e2210
commit
634648c1d4
@ -886,15 +886,15 @@ static py_TValue* c11_chunked_array2d__parse_col_row(c11_chunked_array2d* self,
|
|||||||
self->last_visited.key = *chunk_pos;
|
self->last_visited.key = *chunk_pos;
|
||||||
self->last_visited.value = data;
|
self->last_visited.value = data;
|
||||||
}
|
}
|
||||||
return data + 1; // skip context
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
py_Ref c11_chunked_array2d__get(c11_chunked_array2d* self, int col, int row) {
|
py_Ref c11_chunked_array2d__get(c11_chunked_array2d* self, int col, int row) {
|
||||||
c11_vec2i chunk_pos, local_pos;
|
c11_vec2i chunk_pos, local_pos;
|
||||||
py_TValue* data = c11_chunked_array2d__parse_col_row(self, col, row, &chunk_pos, &local_pos);
|
py_TValue* data = c11_chunked_array2d__parse_col_row(self, col, row, &chunk_pos, &local_pos);
|
||||||
if(data == NULL) return NULL;
|
if(data == NULL) return &self->default_T;
|
||||||
py_Ref retval = &data[local_pos.y * self->chunk_size + local_pos.x];
|
py_Ref retval = &data[1 + local_pos.y * self->chunk_size + local_pos.x];
|
||||||
if(py_isnil(retval)) return NULL;
|
if(py_isnil(retval)) return &self->default_T;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,14 +905,14 @@ bool c11_chunked_array2d__set(c11_chunked_array2d* self, int col, int row, py_Re
|
|||||||
data = c11_chunked_array2d__new_chunk(self, chunk_pos);
|
data = c11_chunked_array2d__new_chunk(self, chunk_pos);
|
||||||
if(data == NULL) return false;
|
if(data == NULL) return false;
|
||||||
}
|
}
|
||||||
data[local_pos.y * self->chunk_size + local_pos.x] = *value;
|
data[1 + local_pos.y * self->chunk_size + local_pos.x] = *value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void c11_chunked_array2d__del(c11_chunked_array2d* self, int col, int row) {
|
static void c11_chunked_array2d__del(c11_chunked_array2d* self, int col, int row) {
|
||||||
c11_vec2i chunk_pos, local_pos;
|
c11_vec2i chunk_pos, local_pos;
|
||||||
py_TValue* data = c11_chunked_array2d__parse_col_row(self, col, row, &chunk_pos, &local_pos);
|
py_TValue* data = c11_chunked_array2d__parse_col_row(self, col, row, &chunk_pos, &local_pos);
|
||||||
if(data != NULL) data[local_pos.y * self->chunk_size + local_pos.x] = *py_NIL();
|
if(data != NULL) data[1 + local_pos.y * self->chunk_size + local_pos.x] = *py_NIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool chunked_array2d__new__(int argc, py_Ref argv) {
|
static bool chunked_array2d__new__(int argc, py_Ref argv) {
|
||||||
@ -963,11 +963,7 @@ static bool chunked_array2d__getitem__(int argc, py_Ref argv) {
|
|||||||
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]);
|
||||||
py_Ref res = c11_chunked_array2d__get(self, pos.x, pos.y);
|
py_Ref res = c11_chunked_array2d__get(self, pos.x, pos.y);
|
||||||
if(res != NULL) {
|
py_assign(py_retval(), res);
|
||||||
py_assign(py_retval(), res);
|
|
||||||
} else {
|
|
||||||
py_assign(py_retval(), &self->default_T);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1113,7 +1109,7 @@ static bool chunked_array2d_view_rect(int argc, py_Ref argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool chunked_array2d_view_chunk(int argc, py_Ref argv) {
|
static bool chunked_array2d_view_chunk(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(2);
|
||||||
PY_CHECK_ARG_TYPE(1, tp_vec2i);
|
PY_CHECK_ARG_TYPE(1, tp_vec2i);
|
||||||
c11_chunked_array2d* self = py_touserdata(&argv[0]);
|
c11_chunked_array2d* self = py_touserdata(&argv[0]);
|
||||||
c11_vec2i chunk_pos = py_tovec2i(&argv[1]);
|
c11_vec2i chunk_pos = py_tovec2i(&argv[1]);
|
||||||
@ -1148,7 +1144,7 @@ static void register_chunked_array2d(py_Ref mod) {
|
|||||||
pk__tp_set_marker(type, c11_chunked_array2d__mark);
|
pk__tp_set_marker(type, c11_chunked_array2d__mark);
|
||||||
assert(type == tp_chunked_array2d);
|
assert(type == tp_chunked_array2d);
|
||||||
|
|
||||||
py_bindmagic(type, __new__, chunked_array2d__new__);
|
py_bind(py_tpobject(type), "__new__(cls, *args, **kwargs)", chunked_array2d__new__);
|
||||||
py_bind(py_tpobject(type),
|
py_bind(py_tpobject(type),
|
||||||
"__init__(self, chunk_size, default=None, context_builder=None)",
|
"__init__(self, chunk_size, default=None, context_builder=None)",
|
||||||
chunked_array2d__init__);
|
chunked_array2d__init__);
|
||||||
|
8
tests/90_chunked_array2d.py
Normal file
8
tests/90_chunked_array2d.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from array2d import chunked_array2d
|
||||||
|
from linalg import vec2i
|
||||||
|
|
||||||
|
a = chunked_array2d(4, default=0)
|
||||||
|
|
||||||
|
a[vec2i.ONE] = 1
|
||||||
|
|
||||||
|
print(a.view().render())
|
Loading…
x
Reference in New Issue
Block a user