-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Core: Integrate math constants in structs directly #107723
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
base: master
Are you sure you want to change the base?
Conversation
static const AABB ZERO; | ||
static const AABB ONE; | ||
static const AABB INF; | ||
static const AABB NaN; |
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.
Note: In order to make these constants constexpr
, they had to first be declared in the structs as const
. Attempting to define them as constexpr
at this stage raises an incomplete-type error
#undef MIN | ||
#undef MAX |
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.
These #undef
s were necessary to get compilation working on Apple devices, because somewhere along the line there's an include which defines MIN
/MAX
macros that didn't get removed by typedefs.h
.
@@ -78,19 +90,19 @@ struct [[nodiscard]] Vector2i { | |||
} | |||
|
|||
Vector2i min(const Vector2i &p_vector2i) const { | |||
return Vector2i(MIN(x, p_vector2i.x), MIN(y, p_vector2i.y)); | |||
return Vector2i(::MIN(x, p_vector2i.x), ::MIN(y, p_vector2i.y)); |
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.
The global namespace needed to be explicitly called, as this would otherwise conflict with the new constants
While this and the #undef
s were effective solutions, they're still workarounds for the bigger issue of having these pseudo-macros on the global namespace. Once those functions migrate to Math
, no further workarounds will be necessary.
Extends our defined math constants to the mathmatical structs directly. This has the benefit of reducing redundancy across the codebase with a singular variable, as well as making developer intent much clearer on whether an arbitrary struct value is a magic number or referencing one of our constants. For usability, this implements the constants
ZERO
/ONE
for all structs,INF
/NAN
for float structs, andMAX
/MIN
for integral structs; no additional bindings were made.