Numworks Epsilon  1.4.1
Graphing Calculator Operating System
go_to_parameter_controller.cpp
Go to the documentation of this file.
2 #include "graph_controller.h"
3 #include "../apps_container.h"
4 #include <assert.h>
5 #include <float.h>
6 #include <cmath>
7 
8 using namespace Shared;
9 using namespace Poincare;
10 
11 namespace Regression {
12 
13 GoToParameterController::GoToParameterController(Responder * parentResponder, Store * store, CurveViewCursor * cursor, GraphController * graphController) :
14  Shared::GoToParameterController(parentResponder, store, cursor, I18n::Message::X),
15  m_store(store),
16  m_xPrediction(true),
17  m_graphController(graphController)
18 {
19 }
20 
22  m_xPrediction = xPrediction;
23 }
24 
26  if (m_xPrediction) {
27  return I18n::translate(I18n::Message::XPrediction);
28  }
29  return I18n::translate(I18n::Message::YPrediction);
30 }
31 
32 double GoToParameterController::parameterAtIndex(int index) {
33  assert(index == 0);
34  if (m_xPrediction) {
35  return m_cursor->x();
36  }
37  return m_cursor->y();
38 }
39 
40 bool GoToParameterController::setParameterAtIndex(int parameterIndex, double f) {
41  assert(parameterIndex == 0);
43  app()->displayWarning(I18n::Message::ForbiddenValue);
44  return false;
45  }
46  double x = m_store->xValueForYValue(f);
47  if (m_xPrediction) {
48  x = m_store->yValueForXValue(f);
49  }
51  app()->displayWarning(I18n::Message::ForbiddenValue);
52  return false;
53  }
54  if (std::isnan(x)) {
55  if (m_store->slope() < DBL_EPSILON && f == m_store->yIntercept()) {
56  m_graphController->selectRegressionCurve();
57  m_cursor->moveTo(m_cursor->x(), f);
58  return true;
59  }
60  app()->displayWarning(I18n::Message::ValueNotReachedByRegression);
61  return false;
62  }
63  m_graphController->selectRegressionCurve();
64  if (m_xPrediction) {
65  m_cursor->moveTo(f, x);
66  } else {
67  m_cursor->moveTo(x, f);
68  }
69  m_graphRange->centerAxisAround(CurveViewRange::Axis::X, m_cursor->x());
70  m_graphRange->centerAxisAround(CurveViewRange::Axis::Y, m_cursor->y());
71  return true;
72 }
73 
75  if (index == numberOfRows()-1) {
76  return;
77  }
79  if (m_xPrediction) {
80  myCell->setMessage(I18n::Message::X);
81  } else {
82  myCell->setMessage(I18n::Message::Y);
83  }
84  FloatParameterController::willDisplayCellForIndex(cell, index);
85 }
86 
87 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
#define fabs(x)
Definition: math.h:178
void willDisplayCellForIndex(HighlightCell *cell, int index) override
#define DBL_EPSILON
Definition: float.h:11
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
void displayWarning(I18n::Message warningMessage)
Definition: app.cpp:97
static constexpr double k_maxDisplayableFloat
InteractiveCurveViewRange * m_graphRange
double yIntercept()
Definition: store.cpp:186
void moveTo(double x, double y)
#define isnan(x)
Definition: math.h:43
double xValueForYValue(double y)
Definition: store.cpp:194
void setMessage(I18n::Message message)
double yValueForXValue(double x)
Definition: store.cpp:190
void centerAxisAround(Axis axis, float position)
App * app()
Definition: responder.cpp:77
double slope()
Definition: store.cpp:182
GoToParameterController(Responder *parentResponder, InteractiveCurveViewRange *graphRange, CurveViewCursor *cursor, I18n::Message symbol)
#define true
Definition: stdbool.h:8