mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some rename
This commit is contained in:
parent
9165ca228a
commit
b053fe32a8
@ -76,8 +76,8 @@ class array2d(Generic[T]):
|
|||||||
def count_neighbors(self, value: T, neighborhood: Neighborhood) -> array2d[int]:
|
def count_neighbors(self, value: T, neighborhood: Neighborhood) -> array2d[int]:
|
||||||
"""Counts the number of neighbors with the given value for each cell."""
|
"""Counts the number of neighbors with the given value for each cell."""
|
||||||
|
|
||||||
def find_bounding_rect(self, value: T) -> tuple[int, int, int, int]:
|
def get_bounding_rect(self, value: T) -> tuple[int, int, int, int]:
|
||||||
"""Finds the bounding rectangle of the given value.
|
"""Gets the bounding rectangle of the given value.
|
||||||
|
|
||||||
Returns a tuple `(x, y, width, height)` or raise `ValueError` if the value is not found.
|
Returns a tuple `(x, y, width, height)` or raise `ValueError` if the value is not found.
|
||||||
"""
|
"""
|
||||||
|
@ -433,8 +433,8 @@ static bool array2d_count(int argc, py_Ref argv) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// find_bounding_rect(self, value: T) -> tuple[int, int, int, int]
|
// get_bounding_rect(self, value: T) -> tuple[int, int, int, int]
|
||||||
static bool array2d_find_bounding_rect(int argc, py_Ref argv) {
|
static bool array2d_get_bounding_rect(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(2);
|
PY_CHECK_ARGC(2);
|
||||||
c11_array2d* self = py_touserdata(argv);
|
c11_array2d* self = py_touserdata(argv);
|
||||||
py_Ref value = py_arg(1);
|
py_Ref value = py_arg(1);
|
||||||
@ -761,7 +761,7 @@ void pk__add_module_array2d() {
|
|||||||
py_bindmethod(array2d, "tolist", array2d_tolist);
|
py_bindmethod(array2d, "tolist", array2d_tolist);
|
||||||
|
|
||||||
py_bindmethod(array2d, "count", array2d_count);
|
py_bindmethod(array2d, "count", array2d_count);
|
||||||
py_bindmethod(array2d, "find_bounding_rect", array2d_find_bounding_rect);
|
py_bindmethod(array2d, "get_bounding_rect", array2d_get_bounding_rect);
|
||||||
py_bindmethod(array2d, "count_neighbors", array2d_count_neighbors);
|
py_bindmethod(array2d, "count_neighbors", array2d_count_neighbors);
|
||||||
py_bindmethod(array2d, "convolve", array2d_convolve);
|
py_bindmethod(array2d, "convolve", array2d_convolve);
|
||||||
}
|
}
|
||||||
|
@ -140,11 +140,11 @@ assert (a[1:4, 1:3] == b).all()
|
|||||||
"""
|
"""
|
||||||
assert a.count(1) == 3*2
|
assert a.count(1) == 3*2
|
||||||
|
|
||||||
assert a.find_bounding_rect(1) == (1, 1, 3, 2)
|
assert a.get_bounding_rect(1) == (1, 1, 3, 2)
|
||||||
assert a.find_bounding_rect(0) == (0, 0, 5, 5)
|
assert a.get_bounding_rect(0) == (0, 0, 5, 5)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
a.find_bounding_rect(2)
|
a.get_bounding_rect(2)
|
||||||
exit(1)
|
exit(1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user