Numworks Epsilon  1.4.1
Graphing Calculator Operating System
tangent_graph_controller.cpp
Go to the documentation of this file.
2 #include "../app.h"
3 
4 using namespace Shared;
5 using namespace Poincare;
6 
7 namespace Graph {
8 
9 TangentGraphController::TangentGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor) :
10  SimpleInteractiveCurveViewController(parentResponder, curveViewRange, graphView, cursor),
11  m_graphView(graphView),
12  m_bannerView(bannerView),
13  m_graphRange(curveViewRange),
14  m_function(nullptr)
15 {
16 }
17 
20 }
21 
23  m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
24  m_graphView->drawTangent(true);
25  m_graphView->setOkView(nullptr);
26  m_graphView->selectMainView(true);
27  reloadBannerView();
28  m_graphView->reload();
29 }
30 
32  m_graphView->selectFunction(function);
33  m_function = function;
34 }
35 
36 void TangentGraphController::reloadBannerView() {
37  m_bannerView->setNumberOfSubviews(6);
38  if (m_function == nullptr) {
39  return;
40  }
41  FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x');
44  char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
45  const char * legend = "a=";
46  int legendLength = strlen(legend);
47  strlcpy(buffer, legend, legendLength+1);
48  double y = m_function->approximateDerivative(m_cursor->x(), myApp->localContext());
49  PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
50  m_bannerView->setLegendAtIndex(buffer, 4);
51 
52  legend = "b=";
53  legendLength = strlen(legend);
54  strlcpy(buffer, legend, legendLength+1);
55  y = -y*m_cursor->x()+m_function->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
56  PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
57  m_bannerView->setLegendAtIndex(buffer, 5);
58 }
59 
60 bool TangentGraphController::moveCursorHorizontally(int direction) {
62  return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_function, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
63 }
64 
65 bool TangentGraphController::handleEnter() {
66  StackViewController * stack = static_cast<StackViewController *>(parentResponder());
67  stack->pop();
68  return true;
69 }
70 
71 }
void setLegendAtIndex(char *text, int index)
Definition: banner_view.cpp:7
constexpr Event Tangent
Definition: events.h:87
static constexpr int MediumNumberOfSignificantDigits
Definition: constant.h:7
Responder * parentResponder() const
Definition: responder.cpp:12
void reload() override
Definition: graph_view.cpp:16
void setOkView(View *okView)
Definition: curve_view.cpp:77
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
void setFunction(CartesianFunction *function)
Definition: app.cpp:9
virtual Poincare::Context * localContext()
void setNumberOfSubviews(int numberOfSubviews)
Definition: banner_view.cpp:17
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
double approximateDerivative(double x, Poincare::Context *context) const
void drawTangent(bool tangent)
Definition: graph_view.h:16
bool privateMoveCursorHorizontally(Shared::CurveViewCursor *cursor, int direction, Shared::InteractiveCurveViewRange *range, int numberOfStepsInGradUnit, Shared::Function *function, Shared::TextFieldDelegateApp *app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio)
size_t strlen(const char *s)
Definition: strlen.c:3
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation)
void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor *cursor, CartesianFunction *function, Shared::TextFieldDelegateApp *app)
virtual float evaluateAtAbscissa(float x, Poincare::Context *context) const
Definition: function.h:30
void selectMainView(bool mainViewSelected)
Definition: curve_view.cpp:46
void selectFunction(Function *function)
App * app()
Definition: responder.cpp:77