Returning Nan from normalize is bad #362
Replies: 5 comments
-
I'd recommend using https://docs.rs/glam/latest/glam/f32/struct.Vec3.html#method.try_normalize or enabling the The design philosophy of |
Beta Was this translation helpful? Give feedback.
-
this is just not good for beginners like me. i am good now after harsh learning, i will use normalize_zero for most of my cases. but for begginers they will likely use .normalize and that will create undefined behaviour in their apps |
Beta Was this translation helpful? Give feedback.
-
if one is sure that the length is always big enough, then you can normalize().unwrap() everytime |
Beta Was this translation helpful? Give feedback.
-
in games, when i want a direction from one object to another, i am not thinking of checking at all the both positions are overlapping, because we are thinking of two separate objects. but it can happen, and it's super hard to track down when it does. For example, player spawning in the same location as an enemy, ad the enemy wants to chase the player with normalized direction. |
Beta Was this translation helpful? Give feedback.
-
To be fair, Perhaps turning back the clock I could have made As I mentioned there are other options if you need to check the result, these are mentioned in the documentation for the I'm going to move this to discussions, as I don't intended to change the signature of |
Beta Was this translation helpful? Give feedback.
-
we should probably return a Result from it. or the worst case, panic.
because normalize is used a lot in (distance.1 - distance.2).normalize()
and there is a small chance that they are exactly the same,
and like me for hours, trying to hunt for a bug and not able to replicate it.
Beta Was this translation helpful? Give feedback.
All reactions