summaryrefslogtreecommitdiff
path: root/src/utils/mathutils.h
diff options
context:
space:
mode:
authorJoseph Botosh <rumly111@gmail.com>2015-07-24 15:55:30 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-25 21:39:05 +0300
commit60906e87e854f6420804839db7b2afadb69662bb (patch)
treefee04d39cef15dc48ba6e55dcdeac74d4ee8fe59 /src/utils/mathutils.h
parentf5d2e707df5171146af3fe1366ecb8fa17b56eea (diff)
downloadplus-60906e87e854f6420804839db7b2afadb69662bb.tar.gz
plus-60906e87e854f6420804839db7b2afadb69662bb.tar.bz2
plus-60906e87e854f6420804839db7b2afadb69662bb.tar.xz
plus-60906e87e854f6420804839db7b2afadb69662bb.zip
healmd checks healing radius
Diffstat (limited to 'src/utils/mathutils.h')
-rw-r--r--src/utils/mathutils.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 69267186c..3fa7ad002 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -24,6 +24,7 @@
#define UTILS_MATHUTILS_H
#include <string>
+#include <cmath>
#include "localconsts.h"
@@ -63,6 +64,60 @@ static const uint16_t crc_table[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
+static const int square_roots[1000] =
+{
+ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
+ 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
+ 11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
+ 12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,
+ 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
+ 14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
+ 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31
+};
+
inline uint16_t getCrc16(const std::string &str) A_WARN_UNUSED;
inline float fastInvSqrt(float x) A_WARN_UNUSED;
inline float fastSqrt(const float x) A_WARN_UNUSED;
@@ -130,4 +185,11 @@ inline int powerOfTwo(const unsigned int input)
return value;
}
+inline int fastSqrtInt(const unsigned int n)
+{
+ if (n < 1000)
+ return square_roots[n];
+ return sqrt(n);
+}
+
#endif // UTILS_MATHUTILS_H