MCPcopy Create free account
hub / github.com/KDE/labplot / tryEvaluateCartesian

Method tryEvaluateCartesian

src/backend/gsl/ExpressionParser.cpp:348–385  ·  view source on GitHub ↗

* Evaluate cartesian expression returning true on success and false if parsing fails * using given range */

Source from the content-addressed store, hash-verified

346 * using given range
347 */
348bool ExpressionParser::tryEvaluateCartesian(const QString& expr,
349 const Range<double> range,
350 int count,
351 QVector<double>* xVector,
352 QVector<double>* yVector,
353 const QStringList& paramNames,
354 const QVector<double>& paramValues) {
355 DEBUG(Q_FUNC_INFO << ", v0: range = " << range.toStdString())
356 const double step = range.stepSize(count);
357 DEBUG(Q_FUNC_INFO << ", range = " << range.toStdString() << ", step = " << step)
358
359 Parser parser(true);
360 ParserLastErrorMessage lock(parser, m_lastErrorMessage);
361
362 for (int i = 0; i < paramNames.size(); ++i)
363 parser.assign_symbol(qPrintable(paramNames.at(i)), paramValues.at(i));
364
365 const auto numberLocale = QLocale();
366 gsl_set_error_handler_off();
367 for (int i = 0; i < count; i++) {
368 const double x{range.start() + step * i};
369 parser.assign_symbol("x", x);
370
371 double y = parser.parse(qPrintable(expr), qPrintable(numberLocale.name()));
372 if (parser.parseErrors() > 0) // try default locale if failing
373 y = parser.parse(qPrintable(expr), "en_US");
374 if (parser.parseErrors() > 0)
375 return false;
376
377 if (std::isnan(y))
378 WARN(Q_FUNC_INFO << ", WARNING: expression " << STDSTRING(expr) << " evaluated @ " << x << " is NAN")
379
380 (*xVector)[i] = x;
381 (*yVector)[i] = y;
382 }
383
384 return true;
385}
386/*
387 * Evaluate cartesian expression returning true on success and false if parsing fails
388 * min and max are localized strings which are parsed to support expressions like "pi + 1.5"

Callers 15

updateFormulaMethod · 0.80
recalculateSpecificMethod · 0.80
evaluateMethod · 0.80
recalculateMethod · 0.80
recalculateSpecificMethod · 0.80
testevaluateCartesianMethod · 0.80
testEvaluateAndMethod · 0.80
testEvaluateOrMethod · 0.80
testEvaluateNotMethod · 0.80

Calls 12

toStdStringMethod · 0.80
stepSizeMethod · 0.80
parseErrorsMethod · 0.80
variablesCounterMethod · 0.80
sizeMethod · 0.45
startMethod · 0.45
parseMethod · 0.45
nameMethod · 0.45
countMethod · 0.45

Tested by 11

testevaluateCartesianMethod · 0.64
testEvaluateAndMethod · 0.64
testEvaluateOrMethod · 0.64
testEvaluateNotMethod · 0.64
testevaluateLessThanMethod · 0.64
testBenchmarkMethod · 0.64