From 37c3f6189d2b5cef32a8e6089a661886f79f0f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 19 Jan 2018 17:19:45 +0100 Subject: [PATCH] [apps] Graph: create a RootGraphController --- apps/graph/Makefile | 1 + .../calculation_parameter_controller.cpp | 7 +++++- .../graph/calculation_parameter_controller.h | 2 ++ apps/graph/graph/root_graph_controller.cpp | 22 +++++++++++++++++++ apps/graph/graph/root_graph_controller.h | 18 +++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 apps/graph/graph/root_graph_controller.cpp create mode 100644 apps/graph/graph/root_graph_controller.h diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 8759bd5e8..fbda46dbd 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -16,6 +16,7 @@ app_objs += $(addprefix apps/graph/,\ graph/graph_view.o\ graph/integral_graph_controller.o\ graph/tangent_graph_controller.o\ + graph/root_graph_controller.o\ list/list_controller.o\ values/derivative_parameter_controller.o\ values/function_parameter_controller.o\ diff --git a/apps/graph/graph/calculation_parameter_controller.cpp b/apps/graph/graph/calculation_parameter_controller.cpp index dfdfed960..2d1bed7d3 100644 --- a/apps/graph/graph/calculation_parameter_controller.cpp +++ b/apps/graph/graph/calculation_parameter_controller.cpp @@ -15,7 +15,8 @@ CalculationParameterController::CalculationParameterController(Responder * paren m_tangentGraphController(nullptr, graphView, bannerView, range, cursor), m_integralGraphController(nullptr, graphView, range, cursor), m_minimumGraphController(nullptr, graphView, bannerView, range, cursor), - m_maximumGraphController(nullptr, graphView, bannerView, range, cursor) + m_maximumGraphController(nullptr, graphView, bannerView, range, cursor), + m_rootGraphController(nullptr, graphView, bannerView, range, cursor) { } @@ -44,6 +45,10 @@ bool CalculationParameterController::handleEvent(Ion::Events::Event event) { m_minimumGraphController.setFunction(m_function); controller = &m_minimumGraphController; break; + case 3: + m_rootGraphController.setFunction(m_function); + controller = &m_rootGraphController; + break; case 4: m_tangentGraphController.setFunction(m_function); controller = &m_tangentGraphController; diff --git a/apps/graph/graph/calculation_parameter_controller.h b/apps/graph/graph/calculation_parameter_controller.h index 02031605a..7a3a41bba 100644 --- a/apps/graph/graph/calculation_parameter_controller.h +++ b/apps/graph/graph/calculation_parameter_controller.h @@ -6,6 +6,7 @@ #include "tangent_graph_controller.h" #include "extremum_graph_controller.h" #include "integral_graph_controller.h" +#include "root_graph_controller.h" #include "graph_view.h" #include "banner_view.h" #include "../../i18n.h" @@ -34,6 +35,7 @@ private: IntegralGraphController m_integralGraphController; MinimumGraphController m_minimumGraphController; MaximumGraphController m_maximumGraphController; + RootGraphController m_rootGraphController; }; } diff --git a/apps/graph/graph/root_graph_controller.cpp b/apps/graph/graph/root_graph_controller.cpp new file mode 100644 index 000000000..ec1d379ff --- /dev/null +++ b/apps/graph/graph/root_graph_controller.cpp @@ -0,0 +1,22 @@ +#include "root_graph_controller.h" +#include "../app.h" + +using namespace Shared; +using namespace Poincare; + +namespace Graph { + +RootGraphController::RootGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor) : + CalculationGraphController(parentResponder, graphView, bannerView, curveViewRange, cursor, I18n::Message::NoZeroFound) +{ +} + +const char * RootGraphController::title() { + return I18n::translate(I18n::Message::Zeros); +} + +CartesianFunction::Point RootGraphController::computeNewPointOfInterest(double start, double step, double max, Context * context) { + return {.abscissa = m_function->nextRootFrom(start, step, max, context), .value = 0.0}; +} + +} diff --git a/apps/graph/graph/root_graph_controller.h b/apps/graph/graph/root_graph_controller.h new file mode 100644 index 000000000..2d53898e7 --- /dev/null +++ b/apps/graph/graph/root_graph_controller.h @@ -0,0 +1,18 @@ +#ifndef GRAPH_ROOT_GRAPH_CONTROLLER_H +#define GRAPH_ROOT_GRAPH_CONTROLLER_H + +#include "calculation_graph_controller.h" + +namespace Graph { + +class RootGraphController : public CalculationGraphController { +public: + RootGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor); + const char * title() override; +private: + CartesianFunction::Point computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override; +}; + +} + +#endif