-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Rect() and FRect() initialization with no arguments #2655
Conversation
The code looks fine, but is there any use case for this? |
There are some, i think. Maybe you want to create a rectangle and assign it's values later, just like you'd do with a |
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, thanks for the PR 🎉
I agree with the reasoning to add this API, might not be a huge deal, but does no harm so why not.
I also see that __new__
inits the fields to 0 already, so there's no issue of uninitialised memory at any point
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, and the API makes sense. 👍
I've added 3 lines of code to the C src to allow
Rect
andFRect
to be made by passing no arguments to them, which will result in a zero rect (x, y, w, h = 0).The check is so little it should not impact performance at all.
Why did i do this?
pygame.Rect()
rather thanpygame.Rect(0, 0, 0, 0)
pygame.Vector2()
and i can't dopygame.Rect()
? Well, now you doOther than the C code i modified:
_GenericRect
class in therect.pyi
stub to include parameterless__init__
rect_test.py
to verify the correct initialization of the rect