some rename

This commit is contained in:
blueloveTH 2024-11-25 12:05:45 +08:00
parent 9165ca228a
commit b053fe32a8
3 changed files with 8 additions and 8 deletions

View File

@ -76,8 +76,8 @@ class array2d(Generic[T]):
def count_neighbors(self, value: T, neighborhood: Neighborhood) -> array2d[int]:
"""Counts the number of neighbors with the given value for each cell."""
def find_bounding_rect(self, value: T) -> tuple[int, int, int, int]:
"""Finds the bounding rectangle of the given value.
def get_bounding_rect(self, value: T) -> tuple[int, int, int, int]:
"""Gets the bounding rectangle of the given value.
Returns a tuple `(x, y, width, height)` or raise `ValueError` if the value is not found.
"""

View File

@ -433,8 +433,8 @@ static bool array2d_count(int argc, py_Ref argv) {
return true;
}
// find_bounding_rect(self, value: T) -> tuple[int, int, int, int]
static bool array2d_find_bounding_rect(int argc, py_Ref argv) {
// get_bounding_rect(self, value: T) -> tuple[int, int, int, int]
static bool array2d_get_bounding_rect(int argc, py_Ref argv) {
PY_CHECK_ARGC(2);
c11_array2d* self = py_touserdata(argv);
py_Ref value = py_arg(1);
@ -761,7 +761,7 @@ void pk__add_module_array2d() {
py_bindmethod(array2d, "tolist", array2d_tolist);
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, "convolve", array2d_convolve);
}

View File

@ -140,11 +140,11 @@ assert (a[1:4, 1:3] == b).all()
"""
assert a.count(1) == 3*2
assert a.find_bounding_rect(1) == (1, 1, 3, 2)
assert a.find_bounding_rect(0) == (0, 0, 5, 5)
assert a.get_bounding_rect(1) == (1, 1, 3, 2)
assert a.get_bounding_rect(0) == (0, 0, 5, 5)
try:
a.find_bounding_rect(2)
a.get_bounding_rect(2)
exit(1)
except ValueError:
pass