From f0f340dec7821cee103ab9267ef941a917ef4dc4 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 18 Nov 2018 23:31:17 +0800 Subject: =?UTF-8?q?*=E7=9B=AE=E5=BD=95=E6=94=B9=E4=B8=BA=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/math/je_math.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/libjin/math/je_math.h (limited to 'src/libjin/math/je_math.h') diff --git a/src/libjin/math/je_math.h b/src/libjin/math/je_math.h new file mode 100644 index 0000000..de57e36 --- /dev/null +++ b/src/libjin/math/je_math.h @@ -0,0 +1,83 @@ +#ifndef __JE_UTILS_MATH_H__ +#define __JE_UTILS_MATH_H__ + +#include "je_constant.h" +#include "je_matrix.h" +#include "je_quad.h" + +namespace JinEngine +{ + namespace Math + { + + #ifdef min + #undef min + #endif // min + #ifdef max + #undef max + #endif // max + + template + inline T min(T a, T b) + { + return a < b ? a : b; + } + + template + inline T max(T a, T b) + { + return a > b ? a : b; + } + + template + inline T clamp(T a, T mi, T ma) + { + return min(max(a, mi), ma); + } + + template + inline bool within(T a, T mi, T ma) + { + return a >= mi && a <= ma; + } + + template + inline bool without(T a, T mi, T ma) + { + return a < mi || a > ma; + } + + template + inline T abs(T a) + { + return a > 0 ? a : -a; + } + + template + inline T lowerBound(T a, T lower) + { + return a < lower ? lower : a; + } + + template + inline T upperBound(T a, T upper) + { + return a > upper ? upper : a; + } + + template + inline T lerp(T a, T b, float t) + { + return a + t * (b - a); + } + + inline float lerp(float a, float b, float f) + { + f = clamp(f, 0, 1); + return a + f * (b - a); + } + + } // namespace Math +} // namespace JinEngine + +#endif // __JE_UTILS_MATH_H__ -- cgit v1.1-26-g67d0