pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
939 stars 155 forks source link

Add ability to normalize a Vector of length zero #3157

Open Doublestuf opened 1 month ago

Doublestuf commented 1 month ago

In issue #2269, it's been decided that pygame-ce should follow game engines such as Unity and Godot in allowing users to normalize zero-vectors for convenience.

Update the function in math_test.c, tests in math_test.py, and documentation in math.rst accordingly.

Doublestuf commented 1 month ago

Good point -- this adds the possibility of example_vector.normalize().is_normalized() returning False, which could complicate things and essentially defeat the point of this change. I think this idea of making a new function called xnormalize while leaving the current normalize function would be more intuitive.

bilhox commented 1 month ago

I'm not sure that it was actually determined for sure that this needs to be implemented in pygame-ce. I'm still partially against it because there are several nonintuitive things that could break if you expect normalizing to return a vector of magnitude 1

@oddbookworm Could you provide an example ? If we merge this, it will not break any code as the following structure :

if vector:
  vector.normalize_ip()

Would still work. (which is what people are currently doing / supposed to do)

bilhox commented 1 month ago

@Doublestuf So the test can pass, you'll have to update the test for normalize, because it's currently expecting an error.