Numworks Epsilon  1.4.1
Graphing Calculator Operating System
graph_controller_helper.cpp
Go to the documentation of this file.
2 #include "../../constant.h"
3 
4 using namespace Shared;
5 using namespace Poincare;
6 
7 namespace Graph {
8 
9 bool GraphControllerHelper::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) {
10  double xCursorPosition = cursor->x();
11  double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit;
12  double y = function->evaluateAtAbscissa(x, app->localContext());
13  cursor->moveTo(x, y);
14  range->panToMakePointVisible(x, y, cursorTopMarginRatio, cursorRightMarginRatio, cursorBottomMarginRatio, cursorLeftMarginRatio);
15  return true;
16 }
17 
18 void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, CartesianFunction * function, TextFieldDelegateApp * app) {
19  char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
20  const char * space = " ";
21  int spaceLength = strlen(space);
22  const char * legend = "00(x)=";
23  int legendLength = strlen(legend);
24  int numberOfChar = strlcpy(buffer, legend, legendLength+1);
25  buffer[0] = function->name()[0];
26  buffer[1] = '\'';
27  double y = function->approximateDerivative(cursor->x(), app->localContext());
28  numberOfChar += PrintFloat::convertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
29  strlcpy(buffer+numberOfChar, space, spaceLength+1);
30  buffer[k_maxDigitLegendLength+6] = 0;
31  bannerView()->setLegendAtIndex(buffer, 2);
32 }
33 
34 }
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
static constexpr int k_maxNumberOfCharacters
Definition: app.cpp:9
static constexpr int ShortNumberOfSignificantDigits
Definition: constant.h:8
virtual Poincare::Context * localContext()
size_t strlen(const char *s)
Definition: strlen.c:3
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
void moveTo(double x, double y)
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation)