Numworks Epsilon  1.4.1
Graphing Calculator Operating System
intersection_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 IntersectionGraphController::IntersectionGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, CartesianFunctionStore * store) :
10  CalculationGraphController(parentResponder, graphView, bannerView, curveViewRange, cursor, I18n::Message::NoIntersectionFound),
11  m_intersectedFunction(nullptr),
12  m_functionStore(store)
13 {
14 }
15 
17  return I18n::translate(I18n::Message::Intersection);
18 }
19 
20 void IntersectionGraphController::reloadBannerView() {
23  char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
24  const char * space = " ";
25  int spaceLength = strlen(space);
26  const char * legend = "0(x)=0(x)=";
27  int legendLength = strlen(legend);
28  int numberOfChar = 0;
29  strlcpy(buffer, legend, legendLength+1);
30  numberOfChar += legendLength;
31  buffer[0] = m_function->name()[0];
32  buffer[5] = m_intersectedFunction->name()[0];
33  numberOfChar += PrintFloat::convertFloatToText<double>(m_cursor->y(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
34  strlcpy(buffer+numberOfChar, space, spaceLength+1);
35  buffer[FunctionBannerDelegate::k_maxDigitLegendLength+legendLength] = 0;
36  bannerView()->setLegendAtIndex(buffer, 1);
37 }
38 
39 CartesianFunction::Point IntersectionGraphController::computeNewPointOfInterest(double start, double step, double max, Context * context) {
40  CartesianFunction::Point result = {.abscissa = NAN, .value = NAN};
41  for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
42  Function * f = m_functionStore->activeFunctionAtIndex(i);
43  if (f != m_function) {
44  CartesianFunction::Point intersection = m_function->nextIntersectionFrom(start, step, max, context, f);
45  if ((std::isnan(result.abscissa) || std::fabs(intersection.abscissa-start) < std::fabs(result.abscissa-start)) && !std::isnan(intersection.abscissa)) {
46  m_intersectedFunction = f;
47  result = (std::isnan(result.abscissa) || std::fabs(intersection.abscissa-start) < std::fabs(result.abscissa-start)) ? intersection : result;
48  }
49  }
50  }
51  return result;
52 }
53 
54 }
void setLegendAtIndex(char *text, int index)
Definition: banner_view.cpp:7
#define NAN
Definition: math.h:30
Definition: i18n.h:6
static constexpr int MediumNumberOfSignificantDigits
Definition: constant.h:7
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
#define fabs(x)
Definition: math.h:178
Definition: app.cpp:9
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
void reloadBannerViewForCursorOnFunction(CurveViewCursor *cursor, Function *function, char symbol)
size_t strlen(const char *s)
Definition: strlen.c:3
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
const char * name() const
Definition: function.cpp:68
#define isnan(x)
Definition: math.h:43
void start()
Definition: rt0.cpp:31
CartesianFunction * activeFunctionAtIndex(int i) override
Point nextIntersectionFrom(double start, double step, double max, Poincare::Context *context, const Shared::Function *function) const