From 604e2211abc1b46470d382a1f9365d81e50f1126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 10 Oct 2016 17:28:08 +0200 Subject: [PATCH] [apps/graph/function] Add a method to evaluate the function Change-Id: I54516369bbbde8d65d98ad41d6e94cd3780e6162 --- apps/graph/function.cpp | 7 +++++++ apps/graph/function.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index d0e6a316f..f96a0c8e7 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -58,3 +58,10 @@ bool Graph::Function::isActive() { void Graph::Function::setActive(bool active) { m_active = active; } + +float Graph::Function::evaluateAtAbscissa(float x) { + Context plotContext; + Float xExp = Float(x); + plotContext.setExpressionForSymbolName(&xExp, "x"); + return m_expression->approximate(plotContext); +} diff --git a/apps/graph/function.h b/apps/graph/function.h index 58d2b3fb1..154fefeba 100644 --- a/apps/graph/function.h +++ b/apps/graph/function.h @@ -9,6 +9,7 @@ namespace Graph { class Function { public: static constexpr const char * Parameter = "(x)"; + Function(const char * text = nullptr, KDColor color = KDColorBlack); ~Function(); // Delete expression and layout, if needed const char * text(); @@ -20,6 +21,7 @@ public: void setActive(bool active); void setContent(const char * c); void setColor(KDColor m_color); + float evaluateAtAbscissa(float x); private: constexpr static int k_bodyLength = 255; char m_text[k_bodyLength];