aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Math/je_math.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/libjin/Math/je_math.h
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/libjin/Math/je_math.h')
-rw-r--r--src/libjin/Math/je_math.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/libjin/Math/je_math.h b/src/libjin/Math/je_math.h
new file mode 100644
index 0000000..1f8e0b3
--- /dev/null
+++ b/src/libjin/Math/je_math.h
@@ -0,0 +1,77 @@
+#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<typename T>
+ inline T min(T a, T b)
+ {
+ return a < b ? a : b;
+ }
+
+ template<typename T>
+ inline T max(T a, T b)
+ {
+ return a > b ? a : b;
+ }
+
+ template<typename T>
+ inline T clamp(T a, T mi, T ma)
+ {
+ return min<T>(max<T>(a, mi), ma);
+ }
+
+ template<typename T>
+ inline bool within(T a, T mi, T ma)
+ {
+ return a >= mi && a <= ma;
+ }
+
+ template<typename T>
+ inline bool without(T a, T mi, T ma)
+ {
+ return a < mi || a > ma;
+ }
+
+ template<typename T>
+ inline T abs(T a)
+ {
+ return a > 0 ? a : -a;
+ }
+
+ template<typename T>
+ inline T lowerBound(T a, T lower)
+ {
+ return a < lower ? lower : a;
+ }
+
+ template<typename T>
+ inline T upperBound(T a, T upper)
+ {
+ return a > upper ? upper : a;
+ }
+
+ template<typename T>
+ inline T lerp(T a, T b, float t)
+ {
+ return a + t * (b - a);
+ }
+
+ } // namespace Math
+} // namespace JinEngine
+
+#endif // __JE_UTILS_MATH_H \ No newline at end of file