00001
00002
00003 #ifndef MISC_H
00004 #define MISC_H
00005
00006 #include <cmath>
00007
00008 #ifndef M_PI
00009 #define M_PI 3.141592653589793
00010 #endif
00011
00012 typedef unsigned char uchar;
00013
00014 typedef struct { uchar r, g, b; } rgb;
00015
00016 inline bool operator==(const rgb &a, const rgb &b) {
00017 return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
00018 }
00019
00020 template <class T>
00021 inline T abs(const T &x) { return (x > 0 ? x : -x); };
00022
00023 template <class T>
00024 inline int sign(const T &x) { return (x >= 0 ? 1 : -1); };
00025
00026 template <class T>
00027 inline T square(const T &x) { return x*x; };
00028
00029 template <class T>
00030 inline T bound(const T &x, const T &min, const T &max) {
00031 return (x < min ? min : (x > max ? max : x));
00032 }
00033
00034 template <class T>
00035 inline bool check_bound(const T &x, const T&min, const T &max) {
00036 return ((x < min) || (x > max));
00037 }
00038
00039 inline int vlib_round(float x) { return (int)(x + 0.5F); }
00040
00041 inline int vlib_round(double x) { return (int)(x + 0.5); }
00042
00043 inline double gaussian(double val, double sigma) {
00044 return exp(-square(val/sigma)/2)/(sqrt(2*M_PI)*sigma);
00045 }
00046
00047 #endif