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

Method tryEvaluateParametric

src/backend/gsl/ExpressionParser.cpp:770–812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

768}
769
770bool ExpressionParser::tryEvaluateParametric(const QString& xexpr,
771 const QString& yexpr,
772 const QString& min,
773 const QString& max,
774 int count,
775 QVector<double>* xVector,
776 QVector<double>* yVector) {
777 gsl_set_error_handler_off();
778
779 const Range<double> range{min, max};
780 const double step = range.stepSize(count);
781
782 Parser parser(true);
783 ParserLastErrorMessage lock(parser, m_lastErrorMessage);
784
785 const auto numberLocale = QLocale();
786 for (int i = 0; i < count; i++) {
787 parser.assign_symbol("t", range.start() + step * i);
788 parser.assign_symbol("i", i + 1);
789
790 double x = parser.parse(qPrintable(xexpr), qPrintable(numberLocale.name()));
791 if (parser.parseErrors() > 0) // try default locale if failing
792 x = parser.parse(qPrintable(xexpr), "en_US");
793 if (parser.parseErrors() > 0)
794 return false;
795
796 double y = parser.parse(qPrintable(yexpr), qPrintable(numberLocale.name()));
797 if (parser.parseErrors() > 0) // try default locale if failing
798 y = parser.parse(qPrintable(yexpr), "en_US");
799 if (parser.parseErrors() > 0)
800 return false;
801
802 if (std::isnan(x))
803 WARN(Q_FUNC_INFO << ", WARNING: X expression " << STDSTRING(xexpr) << " evaluated @ " << range.start() + step * i << " is NAN")
804 if (std::isnan(y))
805 WARN(Q_FUNC_INFO << ", WARNING: Y expression " << STDSTRING(yexpr) << " evaluated @ " << range.start() + step * i << " is NAN")
806
807 (*xVector)[i] = x;
808 (*yVector)[i] = y;
809 }
810
811 return true;
812}
813
814QString ExpressionParser::errorMessage() const {
815 return m_lastErrorMessage;

Callers 1

recalculateMethod · 0.80

Calls 5

stepSizeMethod · 0.80
parseErrorsMethod · 0.80
startMethod · 0.45
parseMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected