diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 64403e926..ef588599a 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -37,6 +37,7 @@ int ValuesController::numberOfColumns() { } void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { + Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); // The cell is the abscissa title cell: if (j == 0 && i == 0) { EvenOddMessageTextCell * mytitleCell = (EvenOddMessageTextCell *)cell; @@ -59,20 +60,7 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in } myFunctionCell->setText(name); myFunctionCell->setColor(function->color()); - return; } - // The cell is a derivative value cell - if (j > 0 && i > 0 && isDerivativeColumn(i)) { - TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)]; - EvenOddBufferTextCell * myValueCell = (EvenOddBufferTextCell *)cell; - CartesianFunction * function = functionAtColumn(i); - float x = m_interval.element(j-1); - Complex::convertFloatToText(function->approximateDerivative(x, myApp->localContext()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); - myValueCell->setText(buffer); - return; - } - Shared::ValuesController::willDisplayCellAtLocation(cell, i, j); } I18n::Message ValuesController::emptyMessage() { @@ -169,5 +157,14 @@ FunctionParameterController * ValuesController::functionParameterController() { return &m_functionParameterController; } +float ValuesController::evaluationOfAbscissaAtColumn(float abscissa, int columnIndex) { + CartesianFunction * function = functionAtColumn(columnIndex); + TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); + if (isDerivativeColumn(columnIndex)) { + return function->approximateDerivative(abscissa, myApp->localContext()); + } + return function->evaluateAtAbscissa(abscissa, myApp->localContext()); +} + } diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index baed47da9..2219f977a 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -25,6 +25,7 @@ private: void configureDerivativeFunction(); int maxNumberOfCells() override; int maxNumberOfFunctions() override; + float evaluationOfAbscissaAtColumn(float abscissa, int columnIndex) override; constexpr static int k_maxNumberOfCells = 50; constexpr static int k_maxNumberOfFunctions = 5; FunctionTitleCell m_functionTitleCells[k_maxNumberOfFunctions]; diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index cfac54c19..dee08d37e 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -109,7 +109,6 @@ Button * ValuesController::buttonAtIndex(int index, ButtonRowController::Positio } void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { - TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); willDisplayCellAtLocationWithDisplayMode(cell, i, j, Expression::FloatDisplayMode::Default); if (cellAtLocationIsEditable(i, j)) { return; @@ -129,9 +128,8 @@ void ValuesController::willDisplayCellAtLocation(HighlightCell * cell, int i, in } // The cell is a value cell EvenOddBufferTextCell * myValueCell = (EvenOddBufferTextCell *)cell; - Function * function = functionAtColumn(i); float x = m_interval.element(j-1); - Complex::convertFloatToText(function->evaluateAtAbscissa(x, myApp->localContext()), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Complex::convertFloatToText(evaluationOfAbscissaAtColumn(x, i), buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); myValueCell->setText(buffer); } } @@ -277,5 +275,11 @@ int ValuesController::maxNumberOfElements() const { return Interval::k_maxNumberOfElements; } +float ValuesController::evaluationOfAbscissaAtColumn(float abscissa, int columnIndex) { + Function * function = functionAtColumn(columnIndex); + TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); + return function->evaluateAtAbscissa(abscissa, myApp->localContext()); +} + } diff --git a/apps/shared/values_controller.h b/apps/shared/values_controller.h index 45fdd19d7..5c792e0a1 100644 --- a/apps/shared/values_controller.h +++ b/apps/shared/values_controller.h @@ -52,6 +52,7 @@ private: float dataAtLocation(int columnIndex, int rowIndex) override; int numberOfElements() override; int maxNumberOfElements() const override; + virtual float evaluationOfAbscissaAtColumn(float abscissa, int columnIndex); constexpr static int k_maxNumberOfAbscissaCells = 10; virtual int maxNumberOfCells() = 0; virtual int maxNumberOfFunctions() = 0;