From 68adfe975f1fab10b13498f464d7cb0c16b991c9 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 6 Mar 2020 13:57:24 +0100 Subject: [PATCH] Clean up math/functions.h header. --- TODO.md | 1 - include/lol/image/color.h | 2 +- {legacy => include}/lol/math/functions.h | 53 +++++++----------------- include/lol/math/private/perlin.h | 1 + include/lol/types/half.h | 2 +- legacy/lol/math/geometry.h | 3 +- 6 files changed, 20 insertions(+), 42 deletions(-) rename {legacy => include}/lol/math/functions.h (70%) diff --git a/TODO.md b/TODO.md index e397c0a1..8dee035c 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ src/lol/base/types.h (vec_t shortcuts eg. vec2, ivec2, u8vec3 etc.) src/lol/math/constants.h - src/lol/math/functions.h ## headers we could clean up and keep diff --git a/include/lol/image/color.h b/include/lol/image/color.h index 30d0691b..de35ac0c 100644 --- a/include/lol/image/color.h +++ b/include/lol/image/color.h @@ -18,7 +18,7 @@ // Provides various color conversion routines. // -#include <../legacy/lol/math/functions.h> // FIXME: try to remove this +#include // FIXME: try to remove this #include // vec_t #include // mat_t diff --git a/legacy/lol/math/functions.h b/include/lol/math/functions.h similarity index 70% rename from legacy/lol/math/functions.h rename to include/lol/math/functions.h index 3f0240f0..1b6cfeff 100644 --- a/legacy/lol/math/functions.h +++ b/include/lol/math/functions.h @@ -14,11 +14,10 @@ // // Various maths functions -// ----------------------- +// ——————————————————————— // #include -#include <../legacy/lol/base/types.h> // ldouble #include #include @@ -27,13 +26,16 @@ #include +#if _MSC_VER +# pragma push_macro("min") +# pragma push_macro("max") +# undef min +# undef max +#endif + namespace lol { -// This is OUR namespace. Don't let Windows headers mess with it. -#undef min -#undef max - // Macros for type traits #define LOL_T_ARITHMETIC typename std::enable_if::value, T>::type #define LOL_T_SIGNED typename std::enable_if::value, T>::type @@ -77,14 +79,6 @@ LOL_FORWARD_FP_1_ARG(floor) LOL_FORWARD_FP_1_ARG(ceil) LOL_FORWARD_FP_1_ARG(round) -// Our extensions -template -[[nodiscard]] static inline T2 sincos(T x, T *s, T *c) -{ - *s = std::sin(x); - *c = std::cos(x); -} - // Inherited from GLSL [[nodiscard]] static inline float degrees(float radians) { @@ -96,7 +90,7 @@ template return radians * (180.0 / D_PI); } -[[nodiscard]] static inline ldouble degrees(ldouble radians) +[[nodiscard]] static inline long double degrees(long double radians) { return radians * (180.0L / LD_PI); } @@ -111,31 +105,12 @@ template return degrees * (D_PI / 180.0); } -[[nodiscard]] static inline ldouble radians(ldouble degrees) +[[nodiscard]] static inline long double radians(long double degrees) { return degrees * (LD_PI / 180.0L); } -// The integer versions return floating point values. This avoids nasty -// surprises when calling radians(180) instead of radians(180.0). -[[nodiscard]] static inline float degrees(int8_t x) { return degrees(float(x)); } -[[nodiscard]] static inline float degrees(uint8_t x) { return degrees(float(x)); } -[[nodiscard]] static inline float degrees(int16_t x) { return degrees(float(x)); } -[[nodiscard]] static inline float degrees(uint16_t x) { return degrees(float(x)); } -[[nodiscard]] static inline double degrees(int32_t x) { return degrees(double(x)); } -[[nodiscard]] static inline double degrees(uint32_t x) { return degrees(double(x)); } -[[nodiscard]] static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } -[[nodiscard]] static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } - -[[nodiscard]] static inline float radians(int8_t x) { return radians(float(x)); } -[[nodiscard]] static inline float radians(uint8_t x) { return radians(float(x)); } -[[nodiscard]] static inline float radians(int16_t x) { return radians(float(x)); } -[[nodiscard]] static inline float radians(uint16_t x) { return radians(float(x)); } -[[nodiscard]] static inline double radians(int32_t x) { return radians(double(x)); } -[[nodiscard]] static inline double radians(uint32_t x) { return radians(double(x)); } -[[nodiscard]] static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } -[[nodiscard]] static inline ldouble radians(uint64_t x) { return radians(ldouble(x)); } - +// Interpolation template [[nodiscard]] static inline T2 mix(T a, T b, T x) { @@ -182,5 +157,9 @@ template template [[nodiscard]] static inline T2 sign(T x) { return (T)((T)0 < x); } -} /* namespace lol */ +} // namespace lol +#if _MSC_VER +# pragma pop_macro("min") +# pragma pop_macro("max") +#endif diff --git a/include/lol/math/private/perlin.h b/include/lol/math/private/perlin.h index ffebd987..af3889a7 100644 --- a/include/lol/math/private/perlin.h +++ b/include/lol/math/private/perlin.h @@ -14,6 +14,7 @@ #pragma once +#include // for clamp() #include "gradient.h" #include // std::sqrt diff --git a/include/lol/types/half.h b/include/lol/types/half.h index 27165bdf..ab98f592 100644 --- a/include/lol/types/half.h +++ b/include/lol/types/half.h @@ -22,7 +22,7 @@ #include // uint32_t etc. // FIXME: get rid of this -#include <../legacy/lol/math/functions.h> +#include namespace lol { diff --git a/legacy/lol/math/geometry.h b/legacy/lol/math/geometry.h index b0475274..f1de22b1 100644 --- a/legacy/lol/math/geometry.h +++ b/legacy/lol/math/geometry.h @@ -19,14 +19,13 @@ // #include +#include // distance, clamp… #include // vec_t #include // mat_t -#include <../legacy/lol/math/functions.h> // distance, clamp… #include #include #include // std::fabs -#include #include namespace lol