X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Fmathextra.cpp;h=9ea9dee7848b1c22ed8b6b99bd9cd857bb9d4e94;hb=e1d1cacbb43055988d0d9db632fdf05c0bea9543;hp=7646bf0291aedb1cf74beb63f3bd5396eb73c70b;hpb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;p=architektonas diff --git a/src/base/mathextra.cpp b/src/base/mathextra.cpp index 7646bf0..9ea9dee 100644 --- a/src/base/mathextra.cpp +++ b/src/base/mathextra.cpp @@ -19,13 +19,13 @@ #include // For test() #include #include -#include "fparser.h" +#include "fparser.hh" #include "debug.h" /** * Rounds the given double to the next int. */ -int RS_Math::round(double v) +int Math::round(double v) { return (v - floor(v) < 0.5 ? (int)floor(v) : (int)ceil(v)); } @@ -33,19 +33,19 @@ int RS_Math::round(double v) /** * Save pow function */ -double RS_Math::pow(double x, double y) +double Math::pow(double x, double y) { errno = 0; double ret = ::pow(x, y); if (errno == EDOM) { - RS_DEBUG->print(RS_Debug::D_ERROR, "RS_Math::pow: EDOM in pow"); + DEBUG->print(Debug::D_ERROR, "Math::pow: EDOM in pow"); ret = 0.0; } else if (errno == ERANGE) { - RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Math::pow: ERANGE in pow"); + DEBUG->print(Debug::D_WARNING, "Math::pow: ERANGE in pow"); ret = 0.0; } @@ -55,7 +55,7 @@ double RS_Math::pow(double x, double y) /** * Converts radians to degrees. */ -double RS_Math::rad2deg(double a) +double Math::rad2deg(double a) { return (a / (2.0 * M_PI) * 360.0); } @@ -63,7 +63,7 @@ double RS_Math::rad2deg(double a) /** * Converts degrees to radians. */ -double RS_Math::deg2rad(double a) +double Math::deg2rad(double a) { return ((a / 360.0) * (2.0 * M_PI)); } @@ -71,7 +71,7 @@ double RS_Math::deg2rad(double a) /** * Converts radians to gradians. */ -double RS_Math::rad2gra(double a) +double Math::rad2gra(double a) { return (a / (2.0 * M_PI) * 400.0); } @@ -79,7 +79,7 @@ double RS_Math::rad2gra(double a) /** * Finds greatest common divider using Euclid's algorithm. */ -int RS_Math::findGCD(int a, int b) +int Math::findGCD(int a, int b) { while (b != 0) { @@ -99,7 +99,7 @@ int RS_Math::findGCD(int a, int b) * @param reversed true for clockwise testing. false for ccw testing. * @return true if the angle a is between a1 and a2. */ -bool RS_Math::isAngleBetween(double a, double a1, double a2, bool reversed) +bool Math::isAngleBetween(double a, double a1, double a2, bool reversed) { bool ret = false; @@ -121,7 +121,7 @@ bool RS_Math::isAngleBetween(double a, double a1, double a2, bool reversed) ret = true; } - //RS_DEBUG->print("angle %f is %sbetween %f and %f", + //DEBUG->print("angle %f is %sbetween %f and %f", // a, ret ? "" : "not ", a1, a2); return ret; } @@ -129,7 +129,7 @@ bool RS_Math::isAngleBetween(double a, double a1, double a2, bool reversed) /** * Corrects the given angle to the range of 0-2*Pi. */ -double RS_Math::correctAngle(double a) +double Math::correctAngle(double a) { while (a > 2 * M_PI) a -= 2 * M_PI; @@ -144,7 +144,7 @@ double RS_Math::correctAngle(double a) * @return The angle that needs to be added to a1 to reach a2. * Always positive and less than 2*pi. */ -double RS_Math::getAngleDifference(double a1, double a2) +double Math::getAngleDifference(double a1, double a2) { double ret; @@ -170,7 +170,7 @@ double RS_Math::getAngleDifference(double a1, double a2) * @return The given angle or the given angle+PI, depending which on * is readable from the bottom or right. */ -double RS_Math::makeAngleReadable(double angle, bool readable, bool * corrected) +double Math::makeAngleReadable(double angle, bool readable, bool * corrected) { double ret; bool cor = isAngleReadable(angle) ^ readable; @@ -192,7 +192,7 @@ double RS_Math::makeAngleReadable(double angle, bool readable, bool * corrected) * @return true: if the given angle is in a range that is readable * for texts created with that angle. */ -bool RS_Math::isAngleReadable(double angle) +bool Math::isAngleReadable(double angle) { if (angle > M_PI /2.0 * 3.0 + 0.001 || angle < M_PI / 2.0 + 0.001) return true; @@ -204,7 +204,7 @@ bool RS_Math::isAngleReadable(double angle) * @param tol Tolerance in rad. * @retval true The two angles point in the same direction. */ -bool RS_Math::isSameDirection(double dir1, double dir2, double tol) +bool Math::isSameDirection(double dir1, double dir2, double tol) { double diff = fabs(dir1 - dir2); @@ -217,7 +217,7 @@ bool RS_Math::isSameDirection(double dir1, double dir2, double tol) /** * Compares two double values with a tolerance. */ -bool RS_Math::cmpDouble(double v1, double v2, double tol) +bool Math::cmpDouble(double v1, double v2, double tol) { return (fabs(v2 - v1) < tol); } @@ -226,10 +226,10 @@ bool RS_Math::cmpDouble(double v1, double v2, double tol) * Evaluates a mathematical expression and returns the result. * If an error occured, the given default value 'def' will be returned. */ -double RS_Math::eval(const QString & expr, double def) +double Math::eval(const QString & expr, double def) { bool ok; - double res = RS_Math::eval(expr, &ok); + double res = Math::eval(expr, &ok); if (!ok) return def; @@ -241,7 +241,7 @@ double RS_Math::eval(const QString & expr, double def) * Evaluates a mathematical expression and returns the result. * If an error occured, ok will be set to false (if ok isn't NULL). */ -double RS_Math::eval(const QString & expr, bool * ok) +double Math::eval(const QString & expr, bool * ok) { if (expr.isEmpty()) { @@ -299,26 +299,26 @@ double RS_Math::eval(const QString & expr, bool * ok) * @param prec Precision e.g. a precision of 1 would mean that a * value of 2.12030 will be converted to "2.1". 2.000 is always just "2"). */ -QString RS_Math::doubleToString(double value, double prec) +QString Math::doubleToString(double value, double prec) { if (prec < 1.0e-12) { - std::cerr << "RS_Math::doubleToString: invalid precision\n"; + std::cerr << "Math::doubleToString: invalid precision\n"; return ""; } QString ret; - int num = RS_Math::round(value / prec); + int num = Math::round(value / prec); - QString exaStr = RS_Math::doubleToString(prec, 10); + QString exaStr = Math::doubleToString(prec, 10); int dotPos = exaStr.indexOf('.'); if (dotPos == -1) - ret.sprintf("%d", RS_Math::round(num * prec)); + ret.sprintf("%d", Math::round(num * prec)); else { int digits = exaStr.length() - dotPos - 1; - ret = RS_Math::doubleToString(num * prec, digits); + ret = Math::doubleToString(num * prec, digits); } return ret; @@ -330,7 +330,7 @@ QString RS_Math::doubleToString(double value, double prec) * @param value The double value * @param prec Precision */ -QString RS_Math::doubleToString(double value, int prec) +QString Math::doubleToString(double value, int prec) { QString valStr; @@ -352,35 +352,35 @@ QString RS_Math::doubleToString(double value, int prec) /** * Performs some testing for the math class. */ -void RS_Math::test() +void Math::test() { - std::cout << "RS_Math::test: doubleToString:\n"; + std::cout << "Math::test: doubleToString:\n"; double v = 0.1; - QString s = RS_Math::doubleToString(v, 0.1); + QString s = Math::doubleToString(v, 0.1); assert(s == "0.1"); - s = RS_Math::doubleToString(v, 0.01); + s = Math::doubleToString(v, 0.01); assert(s == "0.1"); - s = RS_Math::doubleToString(v, 0.0); + s = Math::doubleToString(v, 0.0); assert(s == "0"); v = 0.01; - s = RS_Math::doubleToString(v, 0.1); + s = Math::doubleToString(v, 0.1); assert(s == "0"); - s = RS_Math::doubleToString(v, 0.01); + s = Math::doubleToString(v, 0.01); assert(s == "0.01"); - s = RS_Math::doubleToString(v, 0.0); + s = Math::doubleToString(v, 0.0); assert(s == "0"); v = 0.001; - s = RS_Math::doubleToString(v, 0.1); + s = Math::doubleToString(v, 0.1); assert(s == "0"); - s = RS_Math::doubleToString(v, 0.01); + s = Math::doubleToString(v, 0.01); assert(s == "0"); - s = RS_Math::doubleToString(v, 0.001); + s = Math::doubleToString(v, 0.001); assert(s == "0.001"); - s = RS_Math::doubleToString(v, 0.0); + s = Math::doubleToString(v, 0.0); assert(s == "0"); - std::cout << "RS_Math::test: complete\n"; + std::cout << "Math::test: complete\n"; }