Selaa lähdekoodia

Clean up math/functions.h header.

wip/core-clipp
Sam Hocevar 4 vuotta sitten
vanhempi
commit
68adfe975f
6 muutettua tiedostoa jossa 20 lisäystä ja 42 poistoa
  1. +0
    -1
      TODO.md
  2. +1
    -1
      include/lol/image/color.h
  3. +16
    -37
      include/lol/math/functions.h
  4. +1
    -0
      include/lol/math/private/perlin.h
  5. +1
    -1
      include/lol/types/half.h
  6. +1
    -2
      legacy/lol/math/geometry.h

+ 0
- 1
TODO.md Näytä tiedosto

@@ -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


+ 1
- 1
include/lol/image/color.h Näytä tiedosto

@@ -18,7 +18,7 @@
// Provides various color conversion routines.
//

#include <../legacy/lol/math/functions.h> // FIXME: try to remove this
#include <lol/math/functions.h> // FIXME: try to remove this
#include <lol/math/vector.h> // vec_t
#include <lol/math/transform.h> // mat_t



legacy/lol/math/functions.h → include/lol/math/functions.h Näytä tiedosto

@@ -14,11 +14,10 @@

//
// Various maths functions
// -----------------------
// ———————————————————————
//

#include <lol/math/constants.h>
#include <../legacy/lol/base/types.h> // ldouble

#include <cmath>
#include <cstdio>
@@ -27,13 +26,16 @@

#include <stdint.h>

#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<std::is_arithmetic<T>::value, T>::type
#define LOL_T_SIGNED typename std::enable_if<std::is_signed<T>::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<typename T, typename T2 = LOL_T_FLOATING_POINT>
[[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<typename T, typename T2 = LOL_T_FLOATING_POINT>
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<typename T, typename T2 = LOL_T_FLOATING_POINT>
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<typename T, typename T2 = LOL_T_FLOATING_POINT>
[[nodiscard]] static inline T2 mix(T a, T b, T x)
{
@@ -182,5 +157,9 @@ template<typename T, typename T2 = LOL_T_SIGNED>
template<typename T, typename T2 = T, typename DUMMY = LOL_T_UNSIGNED>
[[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

+ 1
- 0
include/lol/math/private/perlin.h Näytä tiedosto

@@ -14,6 +14,7 @@

#pragma once

#include <lol/math/functions.h> // for clamp()
#include "gradient.h"

#include <cmath> // std::sqrt


+ 1
- 1
include/lol/types/half.h Näytä tiedosto

@@ -22,7 +22,7 @@
#include <stdint.h> // uint32_t etc.

// FIXME: get rid of this
#include <../legacy/lol/math/functions.h>
#include <lol/math/functions.h>

namespace lol
{


+ 1
- 2
legacy/lol/math/geometry.h Näytä tiedosto

@@ -19,14 +19,13 @@
//

#include <lol/base/enum.h>
#include <lol/math/functions.h> // distance, clamp…
#include <lol/math/vector.h> // vec_t
#include <lol/math/transform.h> // mat_t
#include <../legacy/lol/math/functions.h> // distance, clamp…

#include <algorithm>
#include <map>
#include <cmath> // std::fabs
#include <cstdio>
#include <stdint.h>

namespace lol


Ladataan…
Peruuta
Tallenna