Skip to content

Commit e187c66

Browse files
committed
same thing for mask
1 parent 5dd9193 commit e187c66

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

docs/reST/ref/mask.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ to store which parts collide.
7171
:param color: color used to check if the surface's pixels are within the
7272
given ``threshold`` range, this parameter is ignored if the optional
7373
``othersurface`` parameter is supplied
74-
:type color: Color or int or tuple(int, int, int, [int]) or list[int, int, int, [int]]
74+
:type color: :data:`pygame.typing.ColorLike`
7575
:param threshold: (optional) the threshold range used to check the difference
7676
between two colors (default is ``(0, 0, 0, 255)``)
77-
:type threshold: Color or int or tuple(int, int, int, [int]) or list[int, int, int, [int]]
77+
:type threshold: :data:`pygame.typing.ColorLike`
7878
:param Surface othersurface: (optional) used to check whether the pixels of
7979
the first surface are within the given ``threshold`` range of the pixels
8080
from this surface (default is ``None``)

src_c/mask.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,13 @@ mask_from_threshold(PyObject *self, PyObject *args, PyObject *kwargs)
11301130
}
11311131

11321132
if (!pg_MappedColorFromObj(rgba_obj_color, surf, &color,
1133-
PG_COLOR_HANDLE_INT)) {
1133+
PG_COLOR_HANDLE_ALL)) {
11341134
return NULL;
11351135
}
11361136

11371137
if (rgba_obj_threshold) {
11381138
if (!pg_MappedColorFromObj(rgba_obj_threshold, surf, &color_threshold,
1139-
PG_COLOR_HANDLE_INT)) {
1139+
PG_COLOR_HANDLE_ALL)) {
11401140
return NULL;
11411141
}
11421142
}

test/mask_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6325,21 +6325,19 @@ def alternate(func, set_value, unset_value, width, height):
63256325
def test_from_threshold(self):
63266326
"""Does mask.from_threshold() work correctly?"""
63276327

6328-
a = [16, 24, 32]
6328+
bpp = [16, 24, 32]
63296329

6330-
for i in a:
6330+
for i in bpp:
63316331
surf = pygame.surface.Surface((70, 70), 0, i)
63326332
surf.fill((100, 50, 200), (20, 20, 20, 20))
63336333
mask = pygame.mask.from_threshold(
63346334
surf, (100, 50, 200, 255), (10, 10, 10, 255)
63356335
)
63366336

6337-
rects = mask.get_bounding_rects()
6338-
63396337
self.assertEqual(mask.count(), 400)
63406338
self.assertEqual(mask.get_bounding_rects(), [pygame.Rect((20, 20, 20, 20))])
63416339

6342-
for i in a:
6340+
for i in bpp:
63436341
surf = pygame.surface.Surface((70, 70), 0, i)
63446342
surf2 = pygame.surface.Surface((70, 70), 0, i)
63456343
surf.fill((100, 100, 100))
@@ -6356,6 +6354,10 @@ def test_from_threshold(self):
63566354
self.assertEqual(mask.count(), 100)
63576355
self.assertEqual(mask.get_bounding_rects(), [pygame.Rect((40, 40, 10, 10))])
63586356

6357+
for color in [(20, 20, 20), 10, "green", pygame.Color("blue")]:
6358+
surf = pygame.surface.Surface((10, 10))
6359+
pygame.mask.from_threshold(surf, color, color)
6360+
63596361
def test_zero_size_from_surface(self):
63606362
"""Ensures from_surface can create masks from zero sized surfaces."""
63616363
for size in ((100, 0), (0, 100), (0, 0)):

0 commit comments

Comments
 (0)