You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue №2993 opened by gresm at 2022-01-19 09:45:42
Description
Add support for complex objects to be convertible to pygame Vector2 and vice versa.
This would allow to use "cmath" build-in python library for mathematical operations on complex numbers.
>>> pygame.Vector2(1j+1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Vector2 must be set with 2 real numbers, a sequence of 2 real numbers, or another Vector2 instance
Hi!
This is an interesting proposal for sure, but I personally don't think it should be added to pygame.
This seems like a pretty rare usecase. I've never come across any games having to use complex numbers to represent vectors or do vector math, unless the app is something like a graphing calculator of sorts
Even if you are in need of having to do something like this, you can always pass (z.real, z.imag) as an argument to Vector (where z is the complex number). IMHO this is more elegant, because the function call is more clear and readable, and one immediately knows that z.real corresponds to x axis and z.imag corresponds to y axis. If we are passing a complex number directly, do we always assume that people want to follow this convention? What if people want to flip the axes? By explicitly making a tuple with the components of a complex number, users also have freedom to easily flip axes.
This is not really scalable to Vector3
I'm not super against the proposal, it would be fine to see this get added if many people think it's a good idea :)
I don't say that someone should do it, I am doing it now.
Will it be accepted? - I don't know, but worth to try.
I can't assign myself to this issue, because I created it.
I don't say that someone should do it, I am doing it now.
Say that in the issue then!
I can't assign myself to this issue, because I created it.
You can't assign yourself because you don't have member rights on the repo.
I would rather not have this as another supported input type for Vector2s, for the same reasons as Ankith.
i.e.
it's an uncommon use
it's already possible with not much additional work
only vector2
However, here's a suggestion.
Cozyfractal on discord has brought up how Vector subclassing could be improved. If you do an operation on a Rect subclass, it returns the subclass. However, if you do an operation on a Vector subclass, it returns Vector instead.
Fixing this would allow you the convenience of using complex numbers in an easy Vector2 subclass.
Issue №2993 opened by gresm at 2022-01-19 09:45:42
Description
Add support for complex objects to be convertible to pygame Vector2 and vice versa.
This would allow to use "cmath" build-in python library for mathematical operations on complex numbers.
Comments
# # gresm commented at 2022-01-19 09:48:43
Current result:
Expected result:
# # ankith26 commented at 2022-01-19 11:38:37
Hi!
This is an interesting proposal for sure, but I personally don't think it should be added to pygame.
(z.real, z.imag)
as an argument toVector
(wherez
is the complex number). IMHO this is more elegant, because the function call is more clear and readable, and one immediately knows thatz.real
corresponds to x axis andz.imag
corresponds to y axis. If we are passing a complex number directly, do we always assume that people want to follow this convention? What if people want to flip the axes? By explicitly making a tuple with the components of a complex number, users also have freedom to easily flip axes.Vector3
I'm not super against the proposal, it would be fine to see this get added if many people think it's a good idea :)
# # gresm commented at 2022-01-19 12:26:54
I don't say that someone should do it, I am doing it now.
Will it be accepted? - I don't know, but worth to try.
I can't assign myself to this issue, because I created it.
# # Starbuck5 commented at 2022-01-20 01:05:55
Say that in the issue then!
You can't assign yourself because you don't have member rights on the repo.
I would rather not have this as another supported input type for Vector2s, for the same reasons as Ankith.
i.e.
However, here's a suggestion.
Cozyfractal on discord has brought up how Vector subclassing could be improved. If you do an operation on a Rect subclass, it returns the subclass. However, if you do an operation on a Vector subclass, it returns Vector instead.
Fixing this would allow you the convenience of using complex numbers in an easy Vector2 subclass.
# # Starbuck5 commented at 2022-01-20 01:18:45
Opened # 2996
# # gresm commented at 2022-01-20 10:48:35
Added # 2997 pull request.
# # robertpfeiffer commented at 2022-01-20 18:00:19
Seems mathematically wonky.
If anything, I'd assume a vector should be able to take two or three complex numbers.
# # gresm commented at 2022-01-20 21:08:12
Vectors in pygame are implemented using double type, so I can't see two complex numbers would be converted into two real numbers.
The text was updated successfully, but these errors were encountered: