Skip to content

Allow for clamping the zero vector when possible #2598

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

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

oddbookworm
Copy link
Member

I was playing around with clamp_magnitude and I noticed that pygame.Vector2().clamp_magnitude(1) would always result in a ValueError being raised, even though a length of 0 is a perfectly fine output here. I've just modified it to follow these examples:

pygame.Vector2().clamp_magnitude(5) # should be allowed
pygame.Vector2().clamp_magnitude(0, 5) # should be allowed
pygame.Vector2().clamp_magnitude(0.1, 5) # should not be allowed

The first two should be fine to return the zero vector, the last one is impossible to do because it's ambiguous in what direction it should go in (just like normalizing the zero vector is impossible)

@oddbookworm oddbookworm requested a review from a team as a code owner December 11, 2023 01:09
Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable change of behaviour, thanks for the PR 🎉

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@MyreMylar MyreMylar merged commit c291e9e into pygame-community:main Dec 11, 2023
@itzpr3d4t0r itzpr3d4t0r added this to the 2.4.0 milestone Dec 11, 2023
@oddbookworm oddbookworm deleted the clamp_zero_vector branch December 21, 2023 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants