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

Pygame support for python "complex" type (2993) #1515

Closed
GalacticEmperor1 opened this issue Feb 12, 2023 · 1 comment
Closed

Pygame support for python "complex" type (2993) #1515

GalacticEmperor1 opened this issue Feb 12, 2023 · 1 comment
Labels

Comments

@GalacticEmperor1
Copy link
Collaborator

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:

>>> 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

Expected result:

>>> pygame.Vector2(1j+1)
<Vector2(1, 1)>

# # 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.

  1. 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
  2. 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.
  3. 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 :)


# # 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

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.


# # 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.

@MyreMylar
Copy link
Member

Closing this as 'not accepted' as the PR was eventually rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants