[apps/regession] Return warning when the user want to go to a point no

reached by the regression curve

Change-Id: Iefaabcc470e65ee5bc2b447af9f2dacbf2902f31
This commit is contained in:
Émilie Feral
2017-02-17 11:33:17 +01:00
parent 00d4688a86
commit 4b3e5f30b6
3 changed files with 23 additions and 0 deletions

View File

@@ -1,7 +1,9 @@
#include "go_to_parameter_controller.h"
#include "../apps_container.h"
#include <assert.h>
using namespace Shared;
using namespace Poincare;
namespace Regression {
@@ -42,6 +44,9 @@ void GoToParameterController::setParameterAtIndex(int parameterIndex, float f) {
m_cursor->moveTo(f, y);
} else {
float x = m_store->xValueForYValue(f);
if (isnan(x)) {
return;
}
m_store->centerAxisAround(CurveViewRange::Axis::X, x);
m_store->centerAxisAround(CurveViewRange::Axis::Y, f);
m_cursor->moveTo(x, f);
@@ -72,6 +77,17 @@ void GoToParameterController::willDisplayCellForIndex(HighlightCell * cell, int
}
bool GoToParameterController::textFieldDidFinishEditing(TextField * textField, const char * text) {
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
float parameter = m_store->yValueForXValue(floatBody);
if (!m_xPrediction) {
parameter = m_store->xValueForYValue(floatBody);
}
if (isnan(parameter)) {
app()->displayWarning("Valeur non atteinte par la regression");
return false;
}
FloatParameterController::textFieldDidFinishEditing(textField, text);
StackViewController * stack = (StackViewController *)parentResponder();
stack->pop();

View File

@@ -231,6 +231,9 @@ float Store::yValueForXValue(float x) {
}
float Store::xValueForYValue(float y) {
if (fabsf(slope()) < FLT_EPSILON) {
return NAN;
}
return (y - yIntercept())/slope();
}

View File

@@ -39,6 +39,10 @@ bool FloatParameterController::textFieldDidFinishEditing(TextField * textField,
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
Context * globalContext = appsContainer->globalContext();
float floatBody = Expression::parse(text)->approximate(*globalContext);
if (isnan(floatBody)) {
app()->displayWarning("Valeur non defini");
return false;
}
setParameterAtIndex(m_selectableTableView.selectedRow(), floatBody);
willDisplayCellForIndex(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(),
m_selectableTableView.selectedRow()), activeCell());