Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef RTCBASE_MISC_H_
00021 #define RTCBASE_MISC_H_
00022
00023 #include <cmath>
00024
00025 namespace rtc {
00026
00027 #define EPSILON 0.00001
00028
00029
00030 template <class T> inline bool fZero(T x) {return ( (x < EPSILON) && (x > -EPSILON) );}
00031
00032
00033 template <class T> inline int rInt(const T x) {return (x > 0 ? int(x+.5) : int(x-.5));}
00034
00035
00036
00037 template <class T> inline T roundTo(const T x, const T b) {return b*T(floor(x/b+0.5));}
00038
00039 template <class T>
00040 class rect {
00041 public:
00042 rect() {}
00043 rect(T x_, T y_, T width_, T height_) : x(x_), y(y_), width(width_), height(height_) {}
00044 virtual ~rect() {}
00045
00046 T x, y;
00047 T width, height;
00048 };
00049
00050 typedef rect<unsigned int> rectui;
00051 typedef rect<float> rectf;
00052 typedef rect<double> rectd;
00053
00054 template <class T>
00055 class size {
00056 public:
00057 size() {}
00058 size(T width_, T height_) : width(width_), height(height_) {}
00059 virtual ~size() {}
00060
00061 T width, height;
00062 };
00063
00064 typedef size<unsigned int> sizeui;
00065 typedef size<float> sizef;
00066 typedef size<double> sized;
00067
00068
00069 template<class T, void*(T::*mem_fn)(void*)>
00070 void* threadCBWrapper(void* ptr)
00071 {
00072 return (static_cast<T*>(ptr)->*mem_fn)(NULL);
00073 }
00074
00075 #ifdef __DARWIN__
00076 inline void pthread_yield() {pthread_yield_np();}
00077 #endif
00078
00079 }
00080
00081 #endif // RTCBASE_MISC_H_