| #pragma once |
| |
| #ifndef TUTIL_INCLUDED |
| #define TUTIL_INCLUDED |
| |
| #include "tcommon.h" |
| #include <math.h> |
| |
| #ifdef _WIN32 |
| #include <windows.h> |
| #include <winbase.h> |
| #endif |
| |
| |
| typedef std::pair<double, double> DoublePair; |
| |
| |
| typedef std::pair<int, int> IntPair; |
| |
| |
| |
| |
| |
| template <class T> |
| inline T sq(T x) { |
| return x * x; |
| } |
| |
| |
| |
| |
| |
| |
| |
| inline int tfloor(double x) { return ((int)(x) > (x) ? (int)(x)-1 : (int)(x)); } |
| |
| |
| |
| |
| |
| |
| |
| inline int tceil(double x) { |
| return ((int)(x) < (x) ? (int)(x) + 1 : (int)(x)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| inline bool isInt(double x) { return (int)(x) == (x); } |
| |
| inline int tfloor(int x, int step) { |
| return step * (x >= 0 ? (x / step) : -((-1 - x + step) / step)); |
| } |
| |
| inline int tceil(int x, int step) { |
| return step * (x >= 0 ? ((x + step - 1) / step) : -((-x) / step)); |
| } |
| |
| inline int intLE(double x) { return tfloor(x); } |
| |
| inline int intGT(double x) { return tfloor(x) + 1; } |
| |
| inline int intLT(double x) { return tceil(x) - 1; } |
| |
| inline int intGE(double x) { return tceil(x); } |
| |
| |
| |
| |
| |
| |
| |
| inline double rad2degree(double rad) { return rad * M_180_PI; } |
| |
| |
| |
| |
| |
| |
| |
| inline double degree2rad(double degree) { return degree * M_PI_180; } |
| |
| |
| |
| |
| |
| |
| |
| template <class T> |
| inline int tsign(T arg) { |
| return arg < 0 ? -1 : arg > 0 ? 1 : 0; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| inline bool areAlmostEqual(double a, double b, double err = TConsts::epsilon) { |
| return fabs(a - b) < err; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <class T> |
| inline bool areAlmostEqual(const T &a, const T &b, |
| double err = TConsts::epsilon) { |
| return tdistance(a, b) < err; |
| } |
| |
| struct TDeleteObjectFunctor { |
| template <typename T> |
| void operator()(T *ptr) { |
| delete ptr; |
| } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| template <class T> |
| inline void clearPointerContainer(T &c) throw() { |
| T tmp; |
| std::for_each(c.begin(), c.end(), TDeleteObjectFunctor()); |
| c.swap(tmp); |
| } |
| |
| #endif |