#ifndef MTH_H__ #define MTH_H__ #include #include #include namespace Mth { constexpr float PI = 3.1415926535897932384626433832795028841971f; // exactly! constexpr float TWO_PI = 2.0f * PI; // exactly! constexpr float DEGRAD = PI / 180.0f; const float RADDEG = 180.0f / PI; void initMth(); float sqrt(float x); float invSqrt(float x); int floor(float x); float sin(float x); float cos(float x); float atan(float x); float atan2(float dy, float dx); float random(); int random(int n); float abs(float a); float Min(float a, float b); float Max(float a, float b); int abs(int a); int Min(int a, int b); int Max(int a, int b); int clamp(int v, int low, int high); float clamp(float v, float low, float high); float lerp(float src, float dst, float alpha); int lerp(int src, int dst, float alpha); ///@param value The original signed value ///@param with The (possibly signed) value to "abs-decrease" with ///@param min The minimum value float absDecrease(float value, float with, float min); //float absIncrease(float value, float with, float max); float absMax(float a, float b); float absMaxSigned(float a, float b); int intFloorDiv(int a, int b); }; namespace Util { template int removeAll(std::vector& superset, const std::vector& toRemove) { int subSize = (int)toRemove.size(); int removed = 0; for (int i = 0; i < subSize; ++i) { T elem = toRemove[i]; int size = (int)superset.size(); for (int j = 0; j < size; ++j) { if (elem == superset[j]) { superset.erase( superset.begin() + j, superset.begin() + j + 1); ++removed; break; } } } return removed; } template bool remove(std::vector& list, const T& instance) { typename std::vector::iterator it = std::find(list.begin(), list.end(), instance); if (it == list.end()) return false; list.erase(it); return true; } // Could perhaps do a template