2014-04-25 14:58:14 +02:00
|
|
|
/***************************************************************************************************
|
|
|
|
**
|
2015-02-27 11:21:09 +01:00
|
|
|
** Copyright (C) 2013 Ingo Berg
|
2014-04-25 14:58:14 +02:00
|
|
|
**
|
|
|
|
** Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
** software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
** without restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
** permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
**
|
|
|
|
** The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
** substantial portions of the Software.
|
|
|
|
**
|
|
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
**
|
|
|
|
******************************************************************************************************/
|
|
|
|
|
|
|
|
#include "qmuparser.h"
|
2014-06-08 20:10:57 +02:00
|
|
|
|
2015-10-12 14:25:44 +02:00
|
|
|
#include <QCoreApplication>
|
2017-11-13 09:53:27 +01:00
|
|
|
#include <QLineF>
|
2024-01-23 14:57:23 +01:00
|
|
|
#include <QtDebug>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QtGlobal>
|
2024-01-23 14:57:23 +01:00
|
|
|
#include <QtMath>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2017-11-13 11:59:25 +01:00
|
|
|
#include "../vmisc/defglobal.h"
|
2022-08-17 09:01:51 +02:00
|
|
|
#include "qmudef.h"
|
2024-01-23 14:57:23 +01:00
|
|
|
#include "qmuparsererror.h"
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Implementation of the standard floating point QmuParser.
|
|
|
|
*/
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2017-11-13 09:53:27 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CSR calcs special modeling case.
|
2017-11-13 10:50:09 +01:00
|
|
|
* According to case we cut a piece with @p length, split up on distance @p split and rotate splited piece on
|
|
|
|
* angle that will create arc with length @p arcLength.
|
2017-11-13 09:53:27 +01:00
|
|
|
* @param length length of cut line
|
|
|
|
* @param split distance between two pieces
|
|
|
|
* @param arcLength length of arc that create two pieces after rotation
|
|
|
|
* @return an angle the second piece should be rotated
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto CSR(qreal length, qreal split, qreal arcLength) -> qreal
|
2017-11-13 09:53:27 +01:00
|
|
|
{
|
|
|
|
length = qAbs(length);
|
|
|
|
arcLength = qAbs(arcLength);
|
|
|
|
|
|
|
|
if (qFuzzyIsNull(length) || qFuzzyIsNull(split) || qFuzzyIsNull(arcLength))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const qreal sign = std::copysign(1.0, split);
|
|
|
|
|
|
|
|
const QLineF line(QPointF(0, 0), QPointF(0, length));
|
|
|
|
|
|
|
|
QLineF tmp = line;
|
2024-01-23 14:57:23 +01:00
|
|
|
tmp.setAngle(tmp.angle() + 90.0 * sign);
|
2017-11-13 09:53:27 +01:00
|
|
|
tmp.setLength(split);
|
|
|
|
|
2024-02-19 17:09:56 +01:00
|
|
|
QPointF const p1 = tmp.p2();
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
tmp = QLineF(QPointF(0, length), QPointF(0, 0));
|
2024-01-23 14:57:23 +01:00
|
|
|
tmp.setAngle(tmp.angle() - 90.0 * sign);
|
2017-11-13 09:53:27 +01:00
|
|
|
tmp.setLength(split);
|
|
|
|
|
2024-02-19 17:09:56 +01:00
|
|
|
QPointF const p2 = tmp.p2();
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
const QLineF line2(p1, p2);
|
|
|
|
|
|
|
|
qreal angle = 180;
|
|
|
|
qreal arcL = INT_MAX;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (arcL > arcLength)
|
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
angle = angle - angle / 2.0;
|
2017-11-13 09:53:27 +01:00
|
|
|
}
|
|
|
|
else if (arcL < arcLength)
|
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
angle = angle + angle / 2.0;
|
2017-11-13 09:53:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:03:37 +01:00
|
|
|
if (angle < 0.00001 || angle >= 360)
|
2017-11-13 09:53:27 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = line2;
|
2024-01-23 14:57:23 +01:00
|
|
|
tmp.setAngle(tmp.angle() + angle * sign);
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
QPointF crosPoint;
|
2020-01-06 17:34:35 +01:00
|
|
|
const auto type = line.intersects(tmp, &crosPoint);
|
2017-11-13 09:53:27 +01:00
|
|
|
if (type == QLineF::NoIntersection)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-19 17:09:56 +01:00
|
|
|
QLineF const radius(crosPoint, tmp.p2());
|
2024-01-23 14:57:23 +01:00
|
|
|
const qreal arcAngle = sign > 0 ? line.angleTo(radius) : radius.angleTo(line);
|
|
|
|
arcL = (M_PI * radius.length()) / 180.0 * arcAngle;
|
|
|
|
} while (qAbs(arcL - arcLength) > (0.5 /*mm*/ / 25.4) * PrintDPI);
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
} // namespace
|
2017-11-13 09:53:27 +01:00
|
|
|
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Namespace for mathematical applications.
|
|
|
|
*/
|
2014-04-25 14:58:14 +02:00
|
|
|
namespace qmu
|
|
|
|
{
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
// Trigonometric function
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::DegreeToRadian(qreal deg) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
return qDegreesToRadians(deg);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::RadianToDegree(qreal rad) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
return qRadiansToDegrees(rad);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Sinh(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
return sinh(v);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ASinh(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
return log(v + qSqrt(v * v + 1));
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Cosh(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return cosh(v);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ACosh(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return log(v + qSqrt(v * v - 1));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Tanh(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return tanh(v);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ATanh(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return (0.5 * log((1 + v) / (1 - v)));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::SinD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return qSin(qDegreesToRadians(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ASinD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2019-09-09 17:47:16 +02:00
|
|
|
return qRadiansToDegrees(qAsin(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::CosD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return qCos(qDegreesToRadians(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ACosD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2019-09-09 17:47:16 +02:00
|
|
|
return qRadiansToDegrees(qAcos(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::TanD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2017-04-14 17:42:49 +02:00
|
|
|
return qTan(qDegreesToRadians(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::ATanD(qreal v) -> qreal
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
{
|
2019-09-09 17:47:16 +02:00
|
|
|
return qRadiansToDegrees(qAtan(v));
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
// Logarithm functions
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
// Logarithm base 2
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Log2(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
|
|
|
#ifdef MUP_MATH_EXCEPTIONS
|
2024-01-23 14:57:23 +01:00
|
|
|
if (v <= 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
throw QmuParserError(ecDOMAIN_ERROR, "Log2");
|
|
|
|
}
|
2014-04-30 07:32:29 +02:00
|
|
|
#endif
|
2024-01-23 14:57:23 +01:00
|
|
|
return log(v) / log(2.0);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
// Logarithm base 10
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Log10(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
|
|
|
#ifdef MUP_MATH_EXCEPTIONS
|
2024-01-23 14:57:23 +01:00
|
|
|
if (v <= 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
throw QmuParserError(ecDOMAIN_ERROR, "Log10");
|
|
|
|
}
|
2014-04-30 07:32:29 +02:00
|
|
|
#endif
|
2014-05-01 13:33:40 +02:00
|
|
|
return log10(v);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
// misc
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Abs(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
return qAbs(v);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Rint(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
return qFloor(v + 0.5);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 16:47:11 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::R2CM(qreal v) -> qreal
|
2017-09-29 16:47:11 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
return Rint(v * 10.0) / 10.0;
|
2017-09-29 16:47:11 +02:00
|
|
|
}
|
|
|
|
|
2017-11-13 09:53:27 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::CSRCm(qreal length, qreal split, qreal arcLength) -> qreal
|
2017-11-13 09:53:27 +01:00
|
|
|
{
|
2018-09-27 13:52:21 +02:00
|
|
|
length = ((length * 10.0) / 25.4) * PrintDPI;
|
|
|
|
split = ((split * 10.0) / 25.4) * PrintDPI;
|
|
|
|
arcLength = ((arcLength * 10.0) / 25.4) * PrintDPI;
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
return CSR(length, split, arcLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::CSRInch(qreal length, qreal split, qreal arcLength) -> qreal
|
2017-11-13 09:53:27 +01:00
|
|
|
{
|
2018-09-27 13:52:21 +02:00
|
|
|
length = length * PrintDPI;
|
|
|
|
split = split * PrintDPI;
|
|
|
|
arcLength = arcLength * PrintDPI;
|
2017-11-13 09:53:27 +01:00
|
|
|
|
|
|
|
return CSR(length, split, arcLength);
|
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Sign(qreal v) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
return ((v < 0) ? -1 : (v > 0) ? 1 : 0);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 18:19:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::FMod(qreal number, qreal denom) -> qreal
|
2015-05-14 18:19:23 +02:00
|
|
|
{
|
|
|
|
return fmod(number, denom);
|
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for adding multiple values.
|
|
|
|
* @param [in] a_afArg Vector with the function arguments
|
|
|
|
* @param [in] a_iArgc The size of a_afArg
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Sum(const qreal *a_afArg, qmusizetype a_iArgc) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2015-10-12 13:52:48 +02:00
|
|
|
if (a_iArgc == 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
throw QmuParserError(
|
|
|
|
QCoreApplication::translate("QmuParser", "too few arguments for function sum.", "parser error message"));
|
2014-05-01 13:33:40 +02:00
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
qreal fRes = 0;
|
|
|
|
for (int i = 0; i < a_iArgc; ++i)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
fRes += a_afArg[i];
|
|
|
|
}
|
|
|
|
return fRes;
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for averaging multiple values.
|
|
|
|
* @param [in] a_afArg Vector with the function arguments
|
|
|
|
* @param [in] a_iArgc The size of a_afArg
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Avg(const qreal *a_afArg, qmusizetype a_iArgc) -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2015-10-12 13:52:48 +02:00
|
|
|
if (a_iArgc == 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
throw QmuParserError(
|
|
|
|
QCoreApplication::translate("QmuParser", "too few arguments for function sum.", "parser error message"));
|
2014-05-01 13:33:40 +02:00
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
qreal fRes = 0;
|
|
|
|
for (int i = 0; i < a_iArgc; ++i)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
fRes += a_afArg[i];
|
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
return fRes / static_cast<qreal>(a_iArgc);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for determining the minimum value out of a vector.
|
|
|
|
* @param [in] a_afArg Vector with the function arguments
|
|
|
|
* @param [in] a_iArgc The size of a_afArg
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Min(const qreal *a_afArg, qmusizetype a_iArgc) -> qreal
|
2014-04-26 09:23:50 +02:00
|
|
|
{
|
2015-10-12 13:52:48 +02:00
|
|
|
if (a_iArgc == 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
throw QmuParserError(
|
|
|
|
QCoreApplication::translate("QmuParser", "too few arguments for function min.", "parser error message"));
|
2014-05-01 13:33:40 +02:00
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
qreal fRes = a_afArg[0];
|
|
|
|
for (int i = 0; i < a_iArgc; ++i)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
fRes = qMin(fRes, a_afArg[i]);
|
|
|
|
}
|
|
|
|
return fRes;
|
2014-04-26 09:23:50 +02:00
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for determining the maximum value out of a vector.
|
|
|
|
* @param [in] a_afArg Vector with the function arguments
|
|
|
|
* @param [in] a_iArgc The size of a_afArg
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Max(const qreal *a_afArg, qmusizetype a_iArgc) -> qreal
|
2014-04-26 09:23:50 +02:00
|
|
|
{
|
2015-10-12 13:52:48 +02:00
|
|
|
if (a_iArgc == 0)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
throw QmuParserError(
|
|
|
|
QCoreApplication::translate("QmuParser", "too few arguments for function min.", "parser error message"));
|
2014-05-01 13:33:40 +02:00
|
|
|
}
|
2024-01-23 14:57:23 +01:00
|
|
|
qreal fRes = a_afArg[0];
|
|
|
|
for (int i = 0; i < a_iArgc; ++i)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
fRes = qMax(fRes, a_afArg[i]);
|
|
|
|
}
|
|
|
|
return fRes;
|
2014-04-26 09:23:50 +02:00
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
2024-01-23 14:57:23 +01:00
|
|
|
* @brief Default value recognition callback.
|
|
|
|
* @param [in] a_szExpr Pointer to the expression
|
|
|
|
* @param [in, out] a_iPos Pointer to an index storing the current position within the expression
|
|
|
|
* @param [out] a_fVal Pointer where the value should be stored in case one is found.
|
|
|
|
* @return 1 if a value was found 0 otherwise.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::IsVal(const QString &a_szExpr, qmusizetype *a_iPos, qreal *a_fVal, const QLocale &locale, bool cNumbers,
|
|
|
|
const QChar &decimal, const QChar &thousand) -> int
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
qreal fVal(0);
|
|
|
|
|
2024-02-19 17:09:56 +01:00
|
|
|
qmusizetype const pos =
|
2024-01-23 14:57:23 +01:00
|
|
|
ReadVal(a_szExpr, fVal, locale != QLocale::c() && cNumbers ? QLocale::c() : locale, decimal, thousand);
|
2014-05-01 13:33:40 +02:00
|
|
|
|
2017-01-03 10:14:32 +01:00
|
|
|
if (pos == -1)
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:14:32 +01:00
|
|
|
*a_iPos += pos;
|
2014-05-01 13:33:40 +02:00
|
|
|
*a_fVal = fVal;
|
|
|
|
return 1;
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Constructor.
|
|
|
|
*
|
|
|
|
* Call QmuParserBase class constructor and trigger Function, Operator and Constant initialization.
|
|
|
|
*/
|
2024-01-23 14:57:23 +01:00
|
|
|
QmuParser::QmuParser()
|
|
|
|
: QmuParserBase()
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2014-05-01 13:33:40 +02:00
|
|
|
AddValIdent(IsVal);
|
2014-04-30 07:32:29 +02:00
|
|
|
|
2020-11-20 12:18:38 +01:00
|
|
|
Init();
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Define the character sets.
|
|
|
|
* @sa DefineNameChars, DefineOprtChars, DefineInfixOprtChars
|
|
|
|
*
|
|
|
|
* This function is used for initializing the default character sets that define
|
|
|
|
* the characters to be useable in function and variable names and operators.
|
|
|
|
*/
|
|
|
|
void QmuParser::InitCharSets()
|
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineNameChars(QStringLiteral("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
|
|
|
DefineOprtChars(QStringLiteral("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*^/?<>=#!$%&|~'_{}"));
|
|
|
|
DefineInfixOprtChars(QStringLiteral("/+-*^?<>=#!$%&|~'_"));
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Initialize the default functions.
|
|
|
|
*/
|
2014-04-26 09:23:50 +02:00
|
|
|
void QmuParser::InitFun()
|
|
|
|
{
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
// trigonometric helper functions
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("degTorad"), DegreeToRadian);
|
|
|
|
DefineFun(QStringLiteral("radTodeg"), RadianToDegree);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
|
2023-02-09 16:01:18 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
2024-01-23 14:57:23 +01:00
|
|
|
#define QSIN_FUN qSin<qreal>
|
|
|
|
#define QCOS_FUN qCos<qreal>
|
|
|
|
#define QTAN_FUN qTan<qreal>
|
|
|
|
#define QASIN_FUN qAsin<qreal>
|
|
|
|
#define QACOS_FUN qAcos<qreal>
|
|
|
|
#define QATAN_FUN qAtan<qreal>
|
|
|
|
#define QATAN2_FUN qAtan2<qreal, qreal>
|
|
|
|
#define QLN_FUN qLn<qreal>
|
|
|
|
#define QEXP_FUN qExp<qreal>
|
|
|
|
#define QSQRT_FUN qSqrt<qreal>
|
2023-02-09 16:01:18 +01:00
|
|
|
#else
|
2024-01-23 14:57:23 +01:00
|
|
|
#define QSIN_FUN qSin
|
|
|
|
#define QCOS_FUN qCos
|
|
|
|
#define QTAN_FUN qTan
|
|
|
|
#define QASIN_FUN qAsin
|
|
|
|
#define QACOS_FUN qAcos
|
|
|
|
#define QATAN_FUN qAtan
|
|
|
|
#define QATAN2_FUN qAtan2
|
|
|
|
#define QLN_FUN qLn
|
|
|
|
#define QEXP_FUN qExp
|
|
|
|
#define QSQRT_FUN qSqrt
|
2023-02-09 16:01:18 +01:00
|
|
|
#endif
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
// trigonometric functions
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("sin"), QSIN_FUN);
|
|
|
|
DefineFun(QStringLiteral("cos"), QCOS_FUN);
|
|
|
|
DefineFun(QStringLiteral("tan"), QTAN_FUN);
|
2023-02-09 16:01:18 +01:00
|
|
|
DefineFun(QStringLiteral("sinD"), SinD);
|
|
|
|
DefineFun(QStringLiteral("cosD"), CosD);
|
|
|
|
DefineFun(QStringLiteral("tanD"), TanD);
|
2014-05-01 13:33:40 +02:00
|
|
|
// arcus functions
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("asin"), QASIN_FUN);
|
|
|
|
DefineFun(QStringLiteral("acos"), QACOS_FUN);
|
|
|
|
DefineFun(QStringLiteral("atan"), QATAN_FUN);
|
2023-02-09 16:01:18 +01:00
|
|
|
DefineFun(QStringLiteral("atan2"), QATAN2_FUN);
|
|
|
|
DefineFun(QStringLiteral("asinD"), ASinD);
|
|
|
|
DefineFun(QStringLiteral("acosD"), ACosD);
|
|
|
|
DefineFun(QStringLiteral("atanD"), ATanD);
|
2014-05-01 13:33:40 +02:00
|
|
|
// hyperbolic functions
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("sinh"), Sinh);
|
|
|
|
DefineFun(QStringLiteral("cosh"), Cosh);
|
|
|
|
DefineFun(QStringLiteral("tanh"), Tanh);
|
2014-05-01 13:33:40 +02:00
|
|
|
// arcus hyperbolic functions
|
2018-04-22 17:32:55 +02:00
|
|
|
DefineFun(QStringLiteral("asinh"), ASinh);
|
|
|
|
DefineFun(QStringLiteral("acosh"), ACosh);
|
|
|
|
DefineFun(QStringLiteral("atanh"), ATanh);
|
2014-05-01 13:33:40 +02:00
|
|
|
// Logarithm functions
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("log2"), Log2);
|
2018-04-22 17:32:55 +02:00
|
|
|
DefineFun(QStringLiteral("log10"), Log10);
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("log"), Log10);
|
|
|
|
DefineFun(QStringLiteral("ln"), QLN_FUN);
|
2014-05-01 13:33:40 +02:00
|
|
|
// misc
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("exp"), QEXP_FUN);
|
|
|
|
DefineFun(QStringLiteral("sqrt"), QSQRT_FUN);
|
|
|
|
DefineFun(QStringLiteral("sign"), Sign);
|
|
|
|
DefineFun(QStringLiteral("rint"), Rint);
|
|
|
|
DefineFun(QStringLiteral("r2cm"), R2CM);
|
2018-04-22 17:32:55 +02:00
|
|
|
DefineFun(QStringLiteral("csrCm"), CSRCm);
|
|
|
|
DefineFun(QStringLiteral("csrInch"), CSRInch);
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("abs"), Abs);
|
|
|
|
DefineFun(QStringLiteral("fmod"), FMod);
|
2014-05-01 13:33:40 +02:00
|
|
|
// Functions with variable number of arguments
|
2024-01-23 14:57:23 +01:00
|
|
|
DefineFun(QStringLiteral("sum"), Sum);
|
|
|
|
DefineFun(QStringLiteral("avg"), Avg);
|
|
|
|
DefineFun(QStringLiteral("min"), Min);
|
|
|
|
DefineFun(QStringLiteral("max"), Max);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Initialize constants.
|
|
|
|
*
|
|
|
|
* By default the QmuParser recognizes two constants. Pi ("pi") and the eulerian
|
|
|
|
* number ("_e").
|
|
|
|
*/
|
|
|
|
void QmuParser::InitConst()
|
|
|
|
{
|
2019-10-30 10:34:01 +01:00
|
|
|
DefineConst(QStringLiteral("_pi"), static_cast<qreal>(M_PI));
|
|
|
|
DefineConst(QStringLiteral("_e"), static_cast<qreal>(M_E));
|
2014-04-26 09:23:50 +02:00
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Initialize operators.
|
|
|
|
*
|
|
|
|
* By default only the unary minus operator is added.
|
|
|
|
*/
|
|
|
|
void QmuParser::InitOprt()
|
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
DefineInfixOprt(LocaleNegativeSign(m_locale), UnaryMinus);
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
void QmuParser::OnDetectVar(const QString &pExpr, qmusizetype &nStart, qmusizetype &nEnd)
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(pExpr)
|
|
|
|
Q_UNUSED(nStart)
|
|
|
|
Q_UNUSED(nEnd)
|
2014-05-01 13:33:40 +02:00
|
|
|
// this is just sample code to illustrate modifying variable names on the fly.
|
|
|
|
// I'm not sure anyone really needs such a feature...
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
string sVar(pExpr->begin()+nStart, pExpr->begin()+nEnd);
|
|
|
|
string sRepl = std::string("_") + sVar + "_";
|
|
|
|
|
|
|
|
int nOrigVarEnd = nEnd;
|
|
|
|
cout << "variable detected!\n";
|
|
|
|
cout << " Expr: " << *pExpr << "\n";
|
|
|
|
cout << " Start: " << nStart << "\n";
|
|
|
|
cout << " End: " << nEnd << "\n";
|
|
|
|
cout << " Var: \"" << sVar << "\"\n";
|
|
|
|
cout << " Repl: \"" << sRepl << "\"\n";
|
|
|
|
nEnd = nStart + sRepl.length();
|
|
|
|
cout << " End: " << nEnd << "\n";
|
|
|
|
pExpr->replace(pExpr->begin()+nStart, pExpr->begin()+nOrigVarEnd, sRepl);
|
|
|
|
cout << " New expr: " << *pExpr << "\n";
|
|
|
|
*/
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 13:33:40 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Numerically differentiate with regard to a variable.
|
|
|
|
* @param [in] a_Var Pointer to the differentiation variable.
|
|
|
|
* @param [in] a_fPos Position at which the differentiation should take place.
|
|
|
|
* @param [in] a_fEpsilon Epsilon used for the numerical differentiation.
|
|
|
|
*
|
|
|
|
* Numerical differentiation uses a 5 point operator yielding a 4th order
|
|
|
|
* formula. The default value for epsilon is 0.00074 which is
|
|
|
|
* numeric_limits<double>::epsilon() ^ (1/5) as suggested in the muQmuParser
|
|
|
|
* forum:
|
|
|
|
*
|
|
|
|
* http://sourceforge.net/forum/forum.php?thread_id=1994611&forum_id=462843
|
|
|
|
*/
|
2014-05-02 10:09:10 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2023-05-03 13:07:02 +02:00
|
|
|
auto QmuParser::Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon) const -> qreal
|
2014-04-30 07:32:29 +02:00
|
|
|
{
|
2024-01-23 14:57:23 +01:00
|
|
|
qreal fRes(0), fBuf(*a_Var), f[4] = {0, 0, 0, 0}, fEpsilon(a_fEpsilon);
|
2014-05-01 13:33:40 +02:00
|
|
|
|
|
|
|
// Backwards compatible calculation of epsilon inc case the user doesnt provide
|
|
|
|
// his own epsilon
|
2016-03-23 15:09:30 +01:00
|
|
|
if (qFuzzyIsNull(fEpsilon))
|
2014-05-01 13:33:40 +02:00
|
|
|
{
|
2016-03-23 15:09:30 +01:00
|
|
|
fEpsilon = qFuzzyIsNull(a_fPos) ? static_cast<qreal>(1e-10) : static_cast<qreal>(1e-7) * a_fPos;
|
2014-05-01 13:33:40 +02:00
|
|
|
}
|
|
|
|
|
2024-01-23 14:57:23 +01:00
|
|
|
*a_Var = a_fPos + 2 * fEpsilon;
|
|
|
|
f[0] = Eval();
|
|
|
|
*a_Var = a_fPos + 1 * fEpsilon;
|
|
|
|
f[1] = Eval();
|
|
|
|
*a_Var = a_fPos - 1 * fEpsilon;
|
|
|
|
f[2] = Eval();
|
|
|
|
*a_Var = a_fPos - 2 * fEpsilon;
|
|
|
|
f[3] = Eval();
|
2014-05-01 13:33:40 +02:00
|
|
|
*a_Var = fBuf; // restore variable
|
|
|
|
|
2024-01-23 14:57:23 +01:00
|
|
|
fRes = (-f[0] + 8 * f[1] - 8 * f[2] + f[3]) / (12 * fEpsilon);
|
2014-05-01 13:33:40 +02:00
|
|
|
return fRes;
|
2014-04-30 07:32:29 +02:00
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
} // namespace qmu
|