-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
vector2 support for Surface.get_at and set_at #2111
vector2 support for Surface.get_at and set_at #2111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should edit the typestub info in buildconfig/stubs/pgyame/surface.pyi so that linters don't throw a fit when using a Vector2
in these methods. Also, adding documentation for this new functionality would be a good idea IMO. Maybe make sure to mention that any floating point values will be truncated, not rounded
@oddbookworm has mentioned that linters would complain about introducing # this pr
import pygame
a = pygame.Surface((50,50))
a.set_at(pygame.Vector2(50,50.5), (25,25,25))
a.set_at((50,50.5), (25,25,25)) whereas before, this would've thrown an error # pygame-ce 2.2.1
import pygame
a = pygame.Surface((50,50))
a.set_at((50,50.5), (25,25,25))
If we favor introducing this, we can mention in the docs that we now support float values for |
I agree |
Many things in pygame support floats now, and didn't always. Transform.scale used to need integer dimensions, for example. I think it's perfectly fine to have integer things accept floats and just truncate them. But you're right, this can be documented and hinted as support for a 2-sequence of floats. |
Also I'm curious what kind of performance impact this has on get_at/set_at. |
I did some performance testing, and set_at with this PR is 1.5% faster now! (This is pretty low, it could be a fluke) I'm not sure whether pg_TwoIntFromObj or that PyArg_ParseTuple is more expensive, but METH_O is less expensive than METH_VARARGS so maybe that helps it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (After a quick merge conflict fix)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs, tests and stubs for get_at_mapped
aren't updated yet
This reverts commit 4fae8fc.
404b79b
to
6700d41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Thanks for working on this. Getting stuff supporting floats when appropriate is a good initiative throughout the pygame-ce API.
the ability to use vector2's to specify coordinates for surface set_ats and get_ats