Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Jun 19, 2025

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, and MAX/MIN for integral structs; no additional bindings were made.

@Repiteo Repiteo added this to the 4.x milestone Jun 19, 2025
@Repiteo Repiteo requested review from a team as code owners June 19, 2025 16:22
@Repiteo Repiteo requested review from a team as code owners June 19, 2025 16:22
@Repiteo Repiteo requested review from a team as code owners June 19, 2025 16:22
@Repiteo Repiteo removed request for a team June 19, 2025 16:22
Comment on lines +44 to +47
static const AABB ZERO;
static const AABB ONE;
static const AABB INF;
static const AABB NaN;
Copy link
Contributor Author

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

Comment on lines +39 to +40
#undef MIN
#undef MAX
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These #undefs 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));
Copy link
Contributor Author

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 #undefs 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant