Refactor: Add math.h include and DEG2RAD to BLI_math_constants

So it can be used in C code while other BLI code is converted to C++, and so
DNA headers can include it without pulling in full BLI_math_rotation.h.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
This commit is contained in:
Brecht Van Lommel
2025-02-09 19:05:01 +01:00
parent a0e492be8b
commit 28c3476b3b
3 changed files with 29 additions and 10 deletions

View File

@@ -45,17 +45,10 @@
* - R = result matrix
*/
#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
# define _USE_MATH_DEFINES
#endif
#include "BLI_assert.h"
#include "BLI_math_inline.h" // IWYU pragma: export
#include "BLI_sys_types.h"
#include <math.h> // IWYU pragma: export
#include "BLI_math_constants.h" // IWYU pragma: export
#include "BLI_math_inline.h" // IWYU pragma: export
#include "BLI_sys_types.h"
#if defined(__GNUC__)
# define NAN_FLT __builtin_nanf("")

View File

@@ -8,6 +8,15 @@
* \ingroup bli
*/
/* On Windows we have to include math.h before defining our own constants, to
* avoid warnings about redefinition. This can likely be simplified later when
* code is fully converted to C++, not defining our own constants at all. */
#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
# define _USE_MATH_DEFINES
#endif
#include <math.h> /* IWYU pragma: export */
#ifndef M_PI
# define M_PI 3.14159265358979323846 /* `pi` */
#endif
@@ -47,3 +56,19 @@
#ifndef M_LN10
# define M_LN10 2.30258509299404568402 /* `log_e 10` */
#endif
#if defined(_MSC_VER) && !defined(_MATH_DEFINES_DEFINED)
# define _MATH_DEFINES_DEFINED
#endif
/* -------------------------------------------------------------------- */
/** \name Conversion Defines
* \{ */
#define RAD2DEG(_rad) ((_rad) * (180.0 / M_PI))
#define DEG2RAD(_deg) ((_deg) * (M_PI / 180.0))
#define RAD2DEGF(_rad) ((_rad) * (float)(180.0 / M_PI))
#define DEG2RADF(_deg) ((_deg) * (float)(M_PI / 180.0))
/** \} */

View File

@@ -8,7 +8,8 @@
* \ingroup bli
*/
#include "BLI_math_base.h" // IWYU pragma: keep
#include "BLI_math_base.h" // IWYU pragma: keep
#include "BLI_math_constants.h" // IWYU pragma: keep
#include "BLI_utildefines.h"
#include "DNA_vec_types.h"