-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.h
45 lines (31 loc) · 990 Bytes
/
misc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef MISC_H
#define MISC_H
#include <cmath>
#ifndef M_PI
#define M_PI 3.141592653589793
#endif
typedef unsigned char uchar;
typedef struct { uchar r, g, b; } rgb;
inline bool operator==(const rgb &a, const rgb &b) {
return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
}
template <class T>
inline T abs(const T &x) { return (x > 0 ? x : -x); };
template <class T>
inline int sign(const T &x) { return (x >= 0 ? 1 : -1); };
template <class T>
inline T square(const T &x) { return x*x; };
template <class T>
inline T bound(const T &x, const T &min, const T &max) {
return (x < min ? min : (x > max ? max : x));
}
template <class T>
inline bool check_bound(const T &x, const T&min, const T &max) {
return ((x < min) || (x > max));
}
inline int vlib_round(float x) { return (int)(x + 0.5F); }
inline int vlib_round(double x) { return (int)(x + 0.5); }
inline double gaussian(double val, double sigma) {
return exp(-square(val/sigma)/2)/(sqrt(2*M_PI)*sigma);
}
#endif