godot
godot copied to clipboard
[Core] Add `is_same` to types that have float components
Compares NaN as equal.
Added to:
AABBBasisColorQuaternionPlaneProjectionRect2Transform2D/3DVector2Vector3Vector4
And a helper method in Math
Based on the code in Variant::hash_compare
Replaces the code in HashMapComparatorDefault and Variant::hash_compare
Can expose these as well as I think they are useful for script
Depends on (see for context):
- https://github.com/godotengine/godot/pull/97550
The name is entirely up for debate, picked it based on the naming in hash_compare but makes sense IMO
Will move the (a == b) || (Math::is_nan(a) && Math::is_nan(b)) to Math to avoid the duplication here
Why is nan comparison equal? Curious.
For the special uses, otherwise you can't remove Vector2(NAN, NAN) from a HashMap for example, hence the hash_compare and the default comparisons
We already technically have this for float in is_same, so could use that naming instead, it uses Variant::identity_compare which calles hash_compare for these types
Similar to #97550, it's probably worth adding these to the other Variant math structs for consistency. There's a fair bit of inconsistency in implementation across those scripts (structurally & functionally) that should be ironed out at some point, but that's not an immediate concern.
Will add the remaining cases and rebase on top of an updated https://github.com/godotengine/godot/pull/97550
Will leave any exposing of these to the future and will change to is_same unless there's any opposition to that, more clear IMO
Can you briefly explain what benefit this PR provides? Is there a bug this fixes or something that this improves?
This is to unify uses of nan-handling equality checks used in hash comparisons, code that's duplicated between Variant and HashMapComparatorDefault, and possibly exposing these in the future (helping with the confusing cases with the == and != operators) to avoid hard to handle cases there
The primary reason is the noisy code added in https://github.com/godotengine/godot/pull/97550 to cover all relevant cases there
Thanks!
Thank you!