Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 sized masks are now possible #493

Merged
merged 4 commits into from Aug 20, 2018
Merged

0 sized masks are now possible #493

merged 4 commits into from Aug 20, 2018

Conversation

augusto2112
Copy link

Issue: #491

@illume
Copy link
Member

illume commented Aug 18, 2018

Looks like a few builds are failing. You can see them by clicking the "Details" link next to Appveyor and TravisCI.

Here's one issue on a 32bit python: https://ci.appveyor.com/project/pygame/pygame/build/1.0.584/job/wi2o2m3smiuim2wq

======================================================================
ERROR: test_zero_size_from_surface (pygame.tests.mask_test.MaskModuleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pygame\tests\mask_test.py", line 460, in test_zero_size_from_surface
    zero_w_mask = pygame.mask.from_surface(pygame.Surface((0, 100)))
ValueError: Cannot create mask with negative size

src_c/mask.c Outdated
@@ -467,6 +470,11 @@ static PyObject* mask_from_surface(PyObject* self, PyObject* args)
return NULL;
}

if (surf->w < 0 || surf->h < 0) {

This comment was marked as off-topic.

size_t size;

size = offsetof(bitmask_t,bits);
if (w && h) {

This comment was marked as off-topic.

@illume
Copy link
Member

illume commented Aug 18, 2018

@augusto2112 I think it's good. Thanks :)

However, we don't have tests for the different methods operating on zero sized masks. If you want to add tests for those I can leave it open? Otherwise I'll merge it in?

@augusto2112
Copy link
Author

@illume I'll add the tests 😄

@augusto2112
Copy link
Author

@illume I'll do it tomorrow though because today I won't have enough time. Or you prefer, you can accept it and tomorrow I submit a new PR with the tests.

@augusto2112
Copy link
Author

@illume I added a bunch of tests. I'm not sure what should happen when trying to scale a (0, 100) mask by (0, 2) for example. Currently it stays (0, 100).


for size in sizes:
mask = pygame.mask.Mask(size)
mask.scale((2, 3))

This comment was marked as off-topic.

@illume illume merged commit 516d6c4 into pygame:master Aug 20, 2018
@illume illume mentioned this pull request Oct 16, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants