| 768 | } |
| 769 | |
| 770 | bool 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 | |
| 814 | QString ExpressionParser::errorMessage() const { |
| 815 | return m_lastErrorMessage; |
no test coverage detected