-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
[Core] Add is_same
to types that have float components
#97553
base: master
Are you sure you want to change the base?
Conversation
The name is entirely up for debate, picked it based on the naming in |
e5b12b7
to
5ddbdf5
Compare
Will move the |
21ec318
to
b294b14
Compare
Why is nan comparison equal? Curious. |
For the special uses, otherwise you can't remove We already technically have this for |
core/math/vector2.h
Outdated
bool is_equal_approx(const Vector2 &p_v) const; | ||
bool is_semantic_equal(const Vector2 &p_v) const; | ||
bool is_zero_approx() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the syntax of the surrounding functions (both here and elsewhere), maybe is_equal_semantic
would be more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering using is_same
as I'd say it's more clear, only drawback is that if we expose these the float
one in scripting won't be available, and you'd have to use is_same
which is a dynamic method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What float
method are you referring to? The only is_same
I'm aware of is the static method, which wouldn't overlap with this implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning the scripting method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine that GDScript would have a means of binding a function to float
; it'd be a bit unorthodox & probably more involved, but nothing outright inhibiting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't bing methods called on float
currently, but I think is_same
works using the generic version
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 #97550 Will leave any exposing of these to the future and will change to |
b294b14
to
86b9d73
Compare
is_semantic_equal
to types that have float componentsis_same
to types that have float components
#define hash_compare_quaternion(p_lhs, p_rhs) \ | ||
(p_lhs).is_same(p_rhs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is now completely redundant, can remove but left it for now
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 The primary reason is the noisy code added in #97550 to cover all relevant cases there |
86b9d73
to
5e468a3
Compare
5e468a3
to
a8a44a7
Compare
Compares `NaN` as equal. Added to: * `AABB` * `Basis` * `Color` * `Plane` * `Projection` * `Quaternion` * `Rect2` * `Transform2D` * `Transform3D` * `Vector2` * `Vector3` * `Vector4` And added as a method in `Math`
a8a44a7
to
e825085
Compare
Compares
NaN
as equal.Added to:
AABB
Basis
Color
Quaternion
Plane
Projection
Rect2
Transform2D/3D
Vector2
Vector3
Vector4
And a helper method in
Math
Based on the code in
Variant::hash_compare
Replaces the code in
HashMapComparatorDefault
andVariant::hash_compare
Can expose these as well as I think they are useful for script
Depends on (see for context):
HashMapComparatorDefault
cases #97550