TORCS  1.3.9
The Open Racing Car Simulator
Basic.h
Go to the documentation of this file.
1 /*
2  3D - C++ Class Library for 3D Transformations
3  Copyright (C) 1996-1998 Gino van den Bergen
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19  Please send remarks, questions and bug reports to gino@win.tue.nl,
20  or write to:
21  Gino van den Bergen
22  Department of Mathematics and Computing Science
23  Eindhoven University of Technology
24  P.O. Box 513, 5600 MB Eindhoven, The Netherlands
25 */
26 
27 #ifndef _BASIC_H_
28 #define _BASIC_H_
29 
30 #include <math.h>
31 #include <stdlib.h>
32 
33 /* typedef double Scalar; */
34 #define Scalar double
35 
36 const Scalar DEGS_PER_RAD = 57.29577951308232286465;
37 const Scalar RADS_PER_DEG = 0.01745329251994329547;
38 const Scalar TWO_PI = 6.28318530717958623200;
39 const Scalar EPSILON = 1.0e-10;
40 const Scalar EPSILON2 = 1.0e-20;
41 const Scalar INFINITY_ = 1.0e50;
42 
43 
44 /* inline Scalar abs(Scalar x) { return x < 0 ? -x : x; } */
45 inline Scalar rnd() { return (Scalar(rand()) + 0.5) / (Scalar(RAND_MAX) + 1); }
46 inline int sgn(Scalar x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }
47 inline bool eqz(Scalar x) { return fabs(x) <= EPSILON; }
48 
49 inline Scalar min(Scalar x, Scalar y) { return x > y ? y : x; }
50 inline Scalar max(Scalar x, Scalar y) { return x < y ? y : x; }
51 
52 inline void set_min(Scalar& x, Scalar y) { if (x > y) x = y; }
53 inline void set_max(Scalar& x, Scalar y) { if (x < y) x = y; }
54 
55 inline Scalar rads(Scalar x) { return x * RADS_PER_DEG; }
56 inline Scalar degs(Scalar x) { return x * DEGS_PER_RAD; }
57 
58 enum { X = 0, Y = 1, Z = 2, W = 3 };
59 
60 #endif
Definition: Basic.h:58
void set_min(Scalar &x, Scalar y)
Definition: Basic.h:52
Scalar max(Scalar x, Scalar y)
Definition: Basic.h:50
const Scalar DEGS_PER_RAD
Definition: Basic.h:36
const Scalar INFINITY_
Definition: Basic.h:41
Scalar rnd()
Definition: Basic.h:45
Definition: Basic.h:58
Definition: Basic.h:58
Scalar degs(Scalar x)
Definition: Basic.h:56
Definition: Basic.h:58
const Scalar EPSILON2
Definition: Basic.h:40
void set_max(Scalar &x, Scalar y)
Definition: Basic.h:53
Scalar rads(Scalar x)
Definition: Basic.h:55
Scalar min(Scalar x, Scalar y)
Definition: Basic.h:49
static Vector y[4]
Definition: Convex.cpp:56
const Scalar TWO_PI
Definition: Basic.h:38
#define Scalar
Definition: Basic.h:34
const Scalar RADS_PER_DEG
Definition: Basic.h:37
bool eqz(Scalar x)
Definition: Basic.h:47
int sgn(Scalar x)
Definition: Basic.h:46
const Scalar EPSILON
Definition: Basic.h:39