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

Vector2::ZERO.normalized() returns Vector2(NaN, NaN) #1080

Open
Shou opened this issue Aug 7, 2024 · 5 comments
Open

Vector2::ZERO.normalized() returns Vector2(NaN, NaN) #1080

Shou opened this issue Aug 7, 2024 · 5 comments
Labels

Comments

@Shou
Copy link
Contributor

Shou commented Aug 7, 2024

In Godot, Vector2.ZERO.normalized() returns Vector2.ZERO but the Rust equivalent uses glam which seems to be the cause for returning NaN (but I haven't verified). If that's the case, we should probably use normalize_or and return zero as the fallback instead.

This affects any function that uses normalized() as well, like direction_to().

@Shou Shou added the bug label Aug 7, 2024
@Bromeon
Copy link
Member

Bromeon commented Aug 7, 2024

gdnative is currently in maintenance mode (if at all), meaning we're quite hesitant to apply any changes that can be potentially breaking. This behavior has existed for a long time, and it's possible that some code relies on it. It's also documented as such (even if not explicitly, but that expression is NaN as well):

Vector2 normalized

May I ask in which context you encountered this?

@Bromeon
Copy link
Member

Bromeon commented Aug 7, 2024

Note that in gdext (Godot 4 bindings), we indeed have multiple overloads with very explicit docs:

image

@Shou
Copy link
Contributor Author

Shou commented Aug 7, 2024

May I ask in which context you encountered this?

I have methods for pulling/pushing bodies towards/away from a specified position, and when that position is equal direction_to() ends up making the vector NaN. I wouldn't mind making a PR, but if it's unlikely to be accepted I'm fine either way. I mostly wanted to document this behavior as I tried searching for it here first.

@Bromeon
Copy link
Member

Bromeon commented Aug 8, 2024

We could maybe add a normalized_or_zero method just like in gdext, but I'd rather not change the semantics of the existing one right now 🙂

Documenting would be a good idea, too.

@Bromeon
Copy link
Member

Bromeon commented Aug 13, 2024

@Shou are you interested in a PR that adds normalized_or_zero?

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