source: proiecte/pmake3d/segment/misc.h @ 77

Last change on this file since 77 was 77, checked in by (none), 14 years ago

Added parallelized code

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1/*
2Copyright (C) 2006 Pedro Felzenszwalb
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17*/
18
19/* random stuff */
20
21#ifndef MISC_H
22#define MISC_H
23
24#include <cmath>
25
26#ifndef M_PI
27#define M_PI 3.141592653589793
28#endif
29
30typedef unsigned char uchar;
31
32typedef struct { uchar r, g, b; } rgb;
33
34inline bool operator==(const rgb &a, const rgb &b) {
35  return ((a.r == b.r) && (a.g == b.g) && (a.b == b.b));
36}
37
38template <class T>
39inline T abs(const T &x) { return (x > 0 ? x : -x); };
40
41template <class T>
42inline int sign(const T &x) { return (x >= 0 ? 1 : -1); };
43
44template <class T>
45inline T square(const T &x) { return x*x; };
46
47template <class T>
48inline T bound(const T &x, const T &min, const T &max) {
49  return (x < min ? min : (x > max ? max : x));
50}
51
52template <class T>
53inline bool check_bound(const T &x, const T&min, const T &max) {
54  return ((x < min) || (x > max));
55}
56
57inline int vlib_round(float x) { return (int)(x + 0.5F); }
58
59inline int vlib_round(double x) { return (int)(x + 0.5); }
60
61inline double gaussian(double val, double sigma) {
62  return exp(-square(val/sigma)/2)/(sqrt(2*M_PI)*sigma);
63}
64
65#endif
Note: See TracBrowser for help on using the repository browser.