]> Shamusworld >> Repos - architektonas/blob - src/base/rs_math.h
b225d691ab8e381ba7f8d507073e43e50dabcd08
[architektonas] / src / base / rs_math.h
1 #ifndef RS_MATH_H
2 #define RS_MATH_H
3
4 // no idea why, but doesn't link without that under win32 / bcc55:
5 //who cares if it doesn't
6 //#ifndef _MT
7 //#define _MT
8 //#endif
9
10 #include <math.h>
11 #include <errno.h>
12 #include <QtCore>
13
14 #ifndef RS_NO_FPARSER
15 #include "fparser.h"
16 #endif
17
18 #include "rs.h"
19
20 #define ARAD                            57.29577951308232
21 #define RS_TOLERANCE            1.0e-10
22 #define RS_TOLERANCE_ANGLE      1.0e-8
23
24 //typedef unsigned int uint;
25
26 /**
27  * Math functions.
28  */
29 class RS_Math
30 {
31 public:
32         static int round(double v);
33         static double pow(double x, double y);
34
35         //static double abs(double v);
36         //static int abs(int v);
37         static double rad2deg(double a);
38         static double deg2rad(double a);
39         static double rad2gra(double a);
40         static int findGCD(int a, int b);
41         static bool isAngleBetween(double a, double a1, double a2, bool reversed);
42         static double correctAngle(double a);
43         static double getAngleDifference(double a1, double a2);
44         static double makeAngleReadable(double angle, bool readable = true, bool * corrected = NULL);
45         static bool isAngleReadable(double angle);
46         static bool isSameDirection(double dir1, double dir2, double tol);
47         static double eval(const QString & expr, double def = 0.0);
48         static bool cmpDouble(double v1, double v2, double tol = 0.001);
49
50         // Keep that in the header file for dynamic inclusion/exclusion.
51         // (JLH: What kind of boneheaded crappy justification is that??!!??!!?)
52         static double eval(const QString & expr, bool * ok);
53
54         static QString doubleToString(double value, double prec);
55         static QString doubleToString(double value, int prec);
56
57         static void test();
58 };
59
60 #endif