godot icon indicating copy to clipboard operation
godot copied to clipboard

Core: Convert `Math` class to namespace

Open Repiteo opened this issue 1 year ago • 2 comments

This adopts the formatting seen in godot-cpp which opts for Math as a namespace rather than a class. Given the class already shouldn't be instanced, nor did it really utilize any class-specific functionality, functioning as a namespace feels more apt. Beyond the conversion, the only adjustments were:

  • core/math/random_pcg.h include migrated to math_funcs.cpp; explicitly included in the handful of files utilizing RandomPCG directly.
  • default_rand, the one private field in the entire class, migrated to math_funcs.cpp as a static variable.
  • RANDOM_32BIT_MAX replaced by existing, equivalent define: UINT32_MAX.
  • static declaration removed from all functions.
  • absd, absf, is_equal_approx, and is_zero_approx moved up—a consequence of needing to be declared before use in a namespace context.
  • math_funcs.{h|cpp} functions that weren't using p_* argument syntax now do.
  • Math:: prefix removed in header where redundant.
  • double sorted before float equivalent where applicable.

Repiteo avatar Jul 16 '24 16:07 Repiteo

I assume this change qualifies as codestyle too? Or perhaps I'm missing something.

Mickeon avatar Jul 26 '24 20:07 Mickeon

Now that you mention it, yeah; this would technically qualify as that. Given that's already the case, might as well fixup stuff like argument name syntax

Repiteo avatar Jul 27 '24 14:07 Repiteo

Thanks! Congrants on your first Godot contribution!

Mickeon avatar Mar 24 '25 10:03 Mickeon