-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Add support for complex()
using __complex__
#3185
Conversation
src_c/math.c
Outdated
PyComplex_FromDoubles(self->coords[0], self->coords[1]); | ||
|
||
if (complex == NULL) { | ||
RAISE(PyExc_ValueError, "Couldn't build complex number from Vector2"); |
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.
This should be return RAISE
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.
This whole function can just be return PyComplex_FromDoubles(self->coords[0], self->coords[1]);
because the function already sets the python exception on error, we don't need to set an error ourselves
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 don't see the point of adding API for something that can be done in user code by typing just one more character than what this PR makes possible.
a = pygame.Vector2(1, 2)
complex(*a)
Bonus of complex(*a)
is that it actually works on any 2-sized sequence like a tuple of list of numbers, which is also something some people use to represent coordinates instead of Vector2
src_c/math.c
Outdated
PyComplex_FromDoubles(self->coords[0], self->coords[1]); | ||
|
||
if (complex == NULL) { | ||
RAISE(PyExc_ValueError, "Couldn't build complex number from Vector2"); |
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.
This whole function can just be return PyComplex_FromDoubles(self->coords[0], self->coords[1]);
because the function already sets the python exception on error, we don't need to set an error ourselves
It's one character less than what you proposed, which is still better. And also I think the tools |
Also, we have had debates about it in the past and back then we had consensus that it was not needed, atleast among the active reviewers at the time: #1515 |
With a lot of denial, I'm closing this PR. |
This PR overloads the method
__complex__
so you can convert a vector2 to a complex number usingcomplex()
.The usage ? Math only, definitely.
I'm supporting this PR as I know a lot of people using pygame for a non gamedev usage.