diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 86f28a867..470b83c1a 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -17,6 +17,7 @@ app_objs += $(addprefix apps/graph/,\ graph/integral_graph_controller.o\ graph/intersection_graph_controller.o\ graph/root_graph_controller.o\ + graph/tangent_graph_controller.o\ list/storage_list_controller.o\ values/derivative_parameter_controller.o\ values/function_parameter_controller.o\ diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index 077737652..924ab94d0 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -56,7 +56,7 @@ bool CalculationGraphController::handleEvent(Ion::Events::Event event) { return false; } -void CalculationGraphController::setFunction(CartesianFunction * function) { +void CalculationGraphController::setFunction(StorageCartesianFunction * function) { m_graphView->selectFunction(function); m_function = function; } diff --git a/apps/graph/graph/calculation_graph_controller.h b/apps/graph/graph/calculation_graph_controller.h index ffc26e45c..59902d234 100644 --- a/apps/graph/graph/calculation_graph_controller.h +++ b/apps/graph/graph/calculation_graph_controller.h @@ -5,18 +5,18 @@ #include "banner_view.h" #include "../../shared/curve_view_cursor.h" #include "../../shared/interactive_curve_view_range.h" -#include "../../shared/function_banner_delegate.h" -#include "../cartesian_function.h" +#include "../../shared/storage_function_banner_delegate.h" +#include "../storage_cartesian_function_store.h" namespace Graph { -class CalculationGraphController : public ViewController, public Shared::FunctionBannerDelegate { +class CalculationGraphController : public ViewController, public Shared::StorageFunctionBannerDelegate { public: CalculationGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, I18n::Message defaultMessage); View * view() override; void viewWillAppear() override; bool handleEvent(Ion::Events::Event event) override; - void setFunction(CartesianFunction * function); + void setFunction(Shared::StorageCartesianFunction * function); protected: constexpr static float k_cursorTopMarginRatio = 0.07f; // (cursorHeight/2)/graphViewHeight constexpr static float k_cursorBottomMarginRatio = 0.15f; // (cursorHeight/2+bannerHeigh)/graphViewHeight @@ -29,7 +29,7 @@ protected: BannerView * m_bannerView; Shared::InteractiveCurveViewRange * m_graphRange; Shared::CurveViewCursor * m_cursor; - CartesianFunction * m_function; + Shared::StorageCartesianFunction * m_function; MessageTextView m_defaultBannerView; bool m_isActive; }; diff --git a/apps/graph/graph/calculation_parameter_controller.cpp b/apps/graph/graph/calculation_parameter_controller.cpp index 1ea753778..87cfa1382 100644 --- a/apps/graph/graph/calculation_parameter_controller.cpp +++ b/apps/graph/graph/calculation_parameter_controller.cpp @@ -7,7 +7,7 @@ using namespace Shared; namespace Graph { -CalculationParameterController::CalculationParameterController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, CartesianFunctionStore * functionStore) : +CalculationParameterController::CalculationParameterController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, InteractiveCurveViewRange * range, CurveViewCursor * cursor, StorageCartesianFunctionStore * functionStore) : ViewController(parentResponder), m_selectableTableView(this), m_function(nullptr), @@ -103,7 +103,7 @@ void CalculationParameterController::willDisplayCellForIndex(HighlightCell * cel myCell->setMessage(titles[index]); } -void CalculationParameterController::setFunction(CartesianFunction * function) { +void CalculationParameterController::setFunction(StorageCartesianFunction * function) { m_function = function; } diff --git a/apps/graph/graph/calculation_parameter_controller.h b/apps/graph/graph/calculation_parameter_controller.h index 84a395e0a..6abe00a42 100644 --- a/apps/graph/graph/calculation_parameter_controller.h +++ b/apps/graph/graph/calculation_parameter_controller.h @@ -2,7 +2,7 @@ #define GRAPH_CALCULATION_PARAMETER_CONTROLLER_H #include -#include "../cartesian_function.h" +#include "../storage_cartesian_function_store.h" #include "tangent_graph_controller.h" #include "extremum_graph_controller.h" #include "integral_graph_controller.h" @@ -16,7 +16,7 @@ namespace Graph { class CalculationParameterController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource { public: - CalculationParameterController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * range, Shared::CurveViewCursor * cursor, CartesianFunctionStore * functionStore); + CalculationParameterController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * range, Shared::CurveViewCursor * cursor, StorageCartesianFunctionStore * functionStore); View * view() override; const char * title() override; bool handleEvent(Ion::Events::Event event) override; @@ -26,12 +26,12 @@ public: HighlightCell * reusableCell(int index) override; int reusableCellCount() override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; - void setFunction(CartesianFunction * function); + void setFunction(Shared::StorageCartesianFunction * function); private: constexpr static int k_totalNumberOfCells = 6; MessageTableCell m_cells[k_totalNumberOfCells]; SelectableTableView m_selectableTableView; - CartesianFunction * m_function; + Shared::StorageCartesianFunction * m_function; TangentGraphController m_tangentGraphController; IntegralGraphController m_integralGraphController; MinimumGraphController m_minimumGraphController; diff --git a/apps/graph/graph/curve_parameter_controller.cpp b/apps/graph/graph/curve_parameter_controller.cpp index c2401241e..d254718b2 100644 --- a/apps/graph/graph/curve_parameter_controller.cpp +++ b/apps/graph/graph/curve_parameter_controller.cpp @@ -7,8 +7,8 @@ using namespace Shared; namespace Graph { -CurveParameterController::CurveParameterController(InteractiveCurveViewRange * graphRange, BannerView * bannerView, CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController, CartesianFunctionStore * functionStore) : - FunctionCurveParameterController(graphRange, cursor), +CurveParameterController::CurveParameterController(InteractiveCurveViewRange * graphRange, BannerView * bannerView, CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController, StorageCartesianFunctionStore * functionStore) : + StorageFunctionCurveParameterController(graphRange, cursor), m_goToParameterController(this, graphRange, cursor, I18n::Message::X), m_graphController(graphController), m_calculationCell(I18n::Message::Compute), @@ -33,7 +33,7 @@ bool CurveParameterController::handleEvent(Ion::Events::Event event) { switch (selectedRow()) { case 0: { - m_calculationParameterController.setFunction(static_cast(m_function)); + m_calculationParameterController.setFunction(static_cast(m_function)); StackViewController * stack = (StackViewController *)parentResponder(); stack->push(&m_calculationParameterController); return true; @@ -68,7 +68,7 @@ int CurveParameterController::reusableCellCount() { return k_totalNumberOfCells; } -FunctionGoToParameterController * CurveParameterController::goToParameterController() { +StorageFunctionGoToParameterController * CurveParameterController::goToParameterController() { return &m_goToParameterController; } diff --git a/apps/graph/graph/curve_parameter_controller.h b/apps/graph/graph/curve_parameter_controller.h index eeedc80c1..0c5f1c49b 100644 --- a/apps/graph/graph/curve_parameter_controller.h +++ b/apps/graph/graph/curve_parameter_controller.h @@ -1,7 +1,7 @@ #ifndef GRAPH_GRAPH_CURVE_PARAMETER_CONTROLLER_H #define GRAPH_GRAPH_CURVE_PARAMETER_CONTROLLER_H -#include "../../shared/function_curve_parameter_controller.h" +#include "../../shared/storage_function_curve_parameter_controller.h" #include "calculation_parameter_controller.h" #include "banner_view.h" @@ -9,9 +9,9 @@ namespace Graph { class GraphController; -class CurveParameterController : public Shared::FunctionCurveParameterController { +class CurveParameterController : public Shared::StorageFunctionCurveParameterController { public: - CurveParameterController(Shared::InteractiveCurveViewRange * graphRange, BannerView * bannerView, Shared::CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController, CartesianFunctionStore * functionStore); + CurveParameterController(Shared::InteractiveCurveViewRange * graphRange, BannerView * bannerView, Shared::CurveViewCursor * cursor, GraphView * graphView, GraphController * graphController, StorageCartesianFunctionStore * functionStore); const char * title() override; bool handleEvent(Ion::Events::Event event) override; int numberOfRows() override; @@ -19,8 +19,8 @@ public: int reusableCellCount() override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: - Shared::FunctionGoToParameterController * goToParameterController() override; - Shared::FunctionGoToParameterController m_goToParameterController; + Shared::StorageFunctionGoToParameterController * goToParameterController() override; + Shared::StorageFunctionGoToParameterController m_goToParameterController; GraphController * m_graphController; constexpr static int k_totalNumberOfCells = 3; MessageTableCellWithChevron m_calculationCell; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 0e1fc3aa0..5259eaf9b 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -5,8 +5,8 @@ using namespace Shared; namespace Graph { -GraphController::GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : - FunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), +GraphController::GraphController(Responder * parentResponder, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header) : + StorageFunctionGraphController(parentResponder, header, curveViewRange, &m_view, cursor, indexFunctionSelectedByCursor, modelVersion, rangeVersion, angleUnitVersion), m_bannerView(), m_view(functionStore, curveViewRange, m_cursor, &m_bannerView, &m_cursorView), m_graphRange(curveViewRange), @@ -26,7 +26,7 @@ I18n::Message GraphController::emptyMessage() { void GraphController::viewWillAppear() { m_view.drawTangent(false); - FunctionGraphController::viewWillAppear(); + StorageFunctionGraphController::viewWillAppear(); selectFunctionWithCursor(indexFunctionSelectedByCursor()); // update the color of the cursor } @@ -42,7 +42,7 @@ float GraphController::interestingXRange() { float characteristicRange = 0.0f; TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { - Function * f = functionStore()->activeFunctionAtIndex(i); + StorageFunction * f = functionStore()->activeFunctionAtIndex(i); float fRange = f->expression(myApp->localContext()).characteristicXRange(*(myApp->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange)) { characteristicRange = fRange > characteristicRange ? fRange : characteristicRange; @@ -52,8 +52,8 @@ float GraphController::interestingXRange() { } void GraphController::selectFunctionWithCursor(int functionIndex) { - FunctionGraphController::selectFunctionWithCursor(functionIndex); - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); + StorageFunctionGraphController::selectFunctionWithCursor(functionIndex); + StorageCartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); m_cursorView.setColor(f->color()); } @@ -62,18 +62,18 @@ BannerView * GraphController::bannerView() { } void GraphController::reloadBannerView() { - FunctionGraphController::reloadBannerView(); + StorageFunctionGraphController::reloadBannerView(); m_bannerView.setNumberOfSubviews(2+m_displayDerivativeInBanner); if (m_functionStore->numberOfActiveFunctions() == 0 || !m_displayDerivativeInBanner) { return; } - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); + StorageCartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, f, myApp); } bool GraphController::moveCursorHorizontally(int direction) { - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); + StorageCartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, f, myApp, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio); } @@ -82,7 +82,7 @@ InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() { return m_graphRange; } -CartesianFunctionStore * GraphController::functionStore() const { +StorageCartesianFunctionStore * GraphController::functionStore() const { return m_functionStore; } diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index cbffa4d08..3febbe77c 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -5,17 +5,17 @@ #include "graph_controller_helper.h" #include "banner_view.h" #include "curve_parameter_controller.h" -#include "../../shared/function_graph_controller.h" +#include "../../shared/storage_function_graph_controller.h" #include "../../shared/curve_view_cursor.h" #include "../../shared/round_cursor_view.h" #include "../../shared/interactive_curve_view_range.h" -#include "../cartesian_function_store.h" +#include "../storage_cartesian_function_store.h" namespace Graph { -class GraphController : public Shared::FunctionGraphController, public GraphControllerHelper { +class GraphController : public Shared::StorageFunctionGraphController, public GraphControllerHelper { public: - GraphController(Responder * parentResponder, CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); + GraphController(Responder * parentResponder, StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Poincare::Preferences::AngleUnit * angleUnitVersion, ButtonRowController * header); I18n::Message emptyMessage() override; void viewWillAppear() override; bool displayDerivativeInBanner() const; @@ -27,7 +27,7 @@ private: void reloadBannerView() override; bool moveCursorHorizontally(int direction) override; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override; - CartesianFunctionStore * functionStore() const override; + StorageCartesianFunctionStore * functionStore() const override; GraphView * functionGraphView() override; View * cursorView() override { return &m_cursorView; @@ -38,7 +38,7 @@ private: GraphView m_view; Shared::InteractiveCurveViewRange * m_graphRange; CurveParameterController m_curveParameterController; - CartesianFunctionStore * m_functionStore; + StorageCartesianFunctionStore * m_functionStore; bool m_displayDerivativeInBanner; }; diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index 4fcc4439f..c3d8c6a38 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -7,7 +7,7 @@ using namespace Poincare; namespace Graph { -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) { +bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Shared::StorageFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio) { double xCursorPosition = cursor->x(); double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit; double y = function->evaluateAtAbscissa(x, app->localContext()); @@ -16,18 +16,16 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso return true; } -void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, CartesianFunction * function, TextFieldDelegateApp * app) { +void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, StorageCartesianFunction * function, TextFieldDelegateApp * app) { constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; - int spaceLength = strlen(space); - const char * legend = "00(x)="; - int numberOfChar = strlcpy(buffer, legend, bufferSize); - buffer[0] = function->name()[0]; - buffer[1] = '\''; + int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, 'x'); + const char * legend = "="; + numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); double y = function->approximateDerivative(cursor->x(), app->localContext()); - numberOfChar += PoincareHelpers::ConvertFloatToText(y, buffer + numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits); - strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar); + numberOfChar += PoincareHelpers::ConvertFloatToText(y, buffer + numberOfChar, bufferSize-numberOfChar, Constant::ShortNumberOfSignificantDigits); + strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar); buffer[k_maxDigitLegendLength+6] = 0; bannerView()->setLegendAtIndex(buffer, 2); } diff --git a/apps/graph/graph/graph_controller_helper.h b/apps/graph/graph/graph_controller_helper.h index 3122755d9..71ba74add 100644 --- a/apps/graph/graph/graph_controller_helper.h +++ b/apps/graph/graph/graph_controller_helper.h @@ -4,15 +4,15 @@ #include "../../shared/function_banner_delegate.h" #include "../../shared/text_field_delegate_app.h" #include "../../shared/interactive_curve_view_range.h" -#include "../cartesian_function_store.h" +#include "../storage_cartesian_function_store.h" namespace Graph { class GraphControllerHelper { protected: constexpr static int k_maxDigitLegendLength = 10; - 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); - void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, CartesianFunction * function, Shared::TextFieldDelegateApp * app); + bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Shared::StorageFunction * function, Shared::TextFieldDelegateApp * app, float cursorTopMarginRatio, float cursorRightMarginRatio, float cursorBottomMarginRatio, float cursorLeftMarginRatio); + void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, Shared::StorageCartesianFunction * function, Shared::TextFieldDelegateApp * app); virtual Shared::BannerView * bannerView() = 0; }; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 21cdac509..a42cc9899 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -5,9 +5,9 @@ using namespace Shared; namespace Graph { -GraphView::GraphView(CartesianFunctionStore * functionStore, InteractiveCurveViewRange * graphRange, +GraphView::GraphView(StorageCartesianFunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) : - FunctionGraphView(graphRange, cursor, bannerView, cursorView), + StorageFunctionGraphView(graphRange, cursor, bannerView, cursorView), m_functionStore(functionStore), m_tangent(false) { @@ -18,24 +18,24 @@ void GraphView::reload() { KDRect dirtyZone(KDRect(0, 0, bounds().width(), bounds().height()-m_bannerView->bounds().height())); markRectAsDirty(dirtyZone); } - return FunctionGraphView::reload(); + return StorageFunctionGraphView::reload(); } void GraphView::drawRect(KDContext * ctx, KDRect rect) const { - FunctionGraphView::drawRect(ctx, rect); + StorageFunctionGraphView::drawRect(ctx, rect); for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) { - CartesianFunction * f = m_functionStore->activeFunctionAtIndex(i); + StorageCartesianFunction * f = m_functionStore->activeFunctionAtIndex(i); /* Draw function (color the area under curve of the selected function) */ if (f == m_selectedFunction) { drawCurve(ctx, rect, [](float t, void * model, void * context) { - CartesianFunction * f = (CartesianFunction *)model; + StorageCartesianFunction * f = (StorageCartesianFunction *)model; Poincare::Context * c = (Poincare::Context *)context; return f->evaluateAtAbscissa(t, c); }, f, context(), f->color(), true, m_highlightedStart, m_highlightedEnd); } else { drawCurve(ctx, rect, [](float t, void * model, void * context) { - CartesianFunction * f = (CartesianFunction *)model; + StorageCartesianFunction * f = (StorageCartesianFunction *)model; Poincare::Context * c = (Poincare::Context *)context; return f->evaluateAtAbscissa(t, c); }, f, context(), f->color()); diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 294bb2b3f..e43bc9143 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -1,15 +1,15 @@ #ifndef GRAPH_GRAPH_VIEW_H #define GRAPH_GRAPH_VIEW_H -#include "../../shared/function_graph_view.h" -#include "../cartesian_function_store.h" +#include "../../shared/storage_function_graph_view.h" +#include "../storage_cartesian_function_store.h" namespace Graph { -class GraphView : public Shared::FunctionGraphView { +class GraphView : public Shared::StorageFunctionGraphView { public: - GraphView(CartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * graphRange, + GraphView(StorageCartesianFunctionStore * functionStore, Shared::InteractiveCurveViewRange * graphRange, Shared::CurveViewCursor * cursor, Shared::BannerView * bannerView, View * cursorView); void reload() override; void drawRect(KDContext * ctx, KDRect rect) const override; @@ -20,7 +20,7 @@ public: * of the graph where the area under the curve is colored. */ void setAreaHighlightColor(bool highlightColor) override {}; private: - CartesianFunctionStore * m_functionStore; + StorageCartesianFunctionStore * m_functionStore; bool m_tangent; }; diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index aa6daadc0..a64e24c0a 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -13,7 +13,7 @@ using namespace Poincare; namespace Graph { IntegralGraphController::IntegralGraphController(Responder * parentResponder, GraphView * graphView, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor) : - SumGraphController(parentResponder, graphView, graphRange, cursor, Ion::Charset::Integral) + StorageSumGraphController(parentResponder, graphView, graphRange, cursor, Ion::Charset::Integral) { } @@ -36,10 +36,13 @@ double IntegralGraphController::cursorNextStep(double x, int direction) { return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit); } -Layout IntegralGraphController::createFunctionLayout(const char * functionName) { - char buffer[7] = "0(x)dx"; - buffer[0] = functionName[0]; - return LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont); +Layout IntegralGraphController::createFunctionLayout(StorageFunction * function) { + constexpr size_t bufferSize = SymbolAbstract::k_maxNameSize+5; // f(x)dx + char buffer[bufferSize]; + const char * dx = "dx"; + int numberOfChars = function->nameWithArgument(buffer, bufferSize-strlen(dx), 'x'); + strlcpy(buffer+numberOfChars, dx, bufferSize-numberOfChars); + return LayoutHelper::String(buffer, strlen(buffer), KFont::SmallFont); } } diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h index 42cdae043..0840afd1e 100644 --- a/apps/graph/graph/integral_graph_controller.h +++ b/apps/graph/graph/integral_graph_controller.h @@ -3,18 +3,18 @@ #include #include "graph_view.h" -#include "../../shared/sum_graph_controller.h" +#include "../../shared/storage_sum_graph_controller.h" namespace Graph { -class IntegralGraphController : public Shared::SumGraphController { +class IntegralGraphController : public Shared::StorageSumGraphController { public: IntegralGraphController(Responder * parentResponder, GraphView * graphView, Shared::InteractiveCurveViewRange * graphRange, Shared::CurveViewCursor * cursor); const char * title() override; private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; - Poincare::Layout createFunctionLayout(const char * functionName) override; + Poincare::Layout createFunctionLayout(Shared::StorageFunction * function) override; }; } diff --git a/apps/graph/graph/intersection_graph_controller.cpp b/apps/graph/graph/intersection_graph_controller.cpp index 71b47b3d8..89ef1490b 100644 --- a/apps/graph/graph/intersection_graph_controller.cpp +++ b/apps/graph/graph/intersection_graph_controller.cpp @@ -6,7 +6,7 @@ using namespace Shared; namespace Graph { -IntersectionGraphController::IntersectionGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, CartesianFunctionStore * store) : +IntersectionGraphController::IntersectionGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, CurveViewCursor * cursor, StorageCartesianFunctionStore * store) : CalculationGraphController(parentResponder, graphView, bannerView, curveViewRange, cursor, I18n::Message::NoIntersectionFound), m_intersectedFunction(nullptr), m_functionStore(store) @@ -20,26 +20,25 @@ const char * IntersectionGraphController::title() { void IntersectionGraphController::reloadBannerView() { m_bannerView->setNumberOfSubviews(2); reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x'); - size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); + constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; const char * space = " "; - int spaceLength = strlen(space); - const char * legend = "0(x)=0(x)="; - int legendLength = strlen(legend); - int numberOfChar = 0; - numberOfChar += strlcpy(buffer, legend, bufferSize); - buffer[0] = m_function->name()[0]; - buffer[5] = m_intersectedFunction->name()[0]; - numberOfChar += PoincareHelpers::ConvertFloatToText(m_cursor->y(), buffer+numberOfChar, Poincare::PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); - strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar); - buffer[FunctionBannerDelegate::k_maxDigitLegendLength+legendLength] = 0; + const char * legend = "="; + // 'f(x)=g(x)=', keep 2 chars for '=' + int numberOfChar = m_function->nameWithArgument(buffer, bufferSize-2, 'x'); + numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); + // keep 1 char for '='; + numberOfChar += m_intersectedFunction->nameWithArgument(buffer, bufferSize-numberOfChar-1, 'x'); + numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar); + numberOfChar += PoincareHelpers::ConvertFloatToText(m_cursor->y(), buffer+numberOfChar, bufferSize-numberOfChar, Constant::MediumNumberOfSignificantDigits); + strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar); bannerView()->setLegendAtIndex(buffer, 1); } Poincare::Expression::Coordinate2D IntersectionGraphController::computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) { Poincare::Expression::Coordinate2D result = {.abscissa = NAN, .value = NAN}; for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) { - Function * f = m_functionStore->activeFunctionAtIndex(i); + StorageFunction * f = m_functionStore->activeFunctionAtIndex(i); if (f != m_function) { Poincare::Expression::Coordinate2D intersection = m_function->nextIntersectionFrom(start, step, max, context, f); if ((std::isnan(result.abscissa) || std::fabs(intersection.abscissa-start) < std::fabs(result.abscissa-start)) && !std::isnan(intersection.abscissa)) { diff --git a/apps/graph/graph/intersection_graph_controller.h b/apps/graph/graph/intersection_graph_controller.h index 8e7042081..934d0b5cf 100644 --- a/apps/graph/graph/intersection_graph_controller.h +++ b/apps/graph/graph/intersection_graph_controller.h @@ -2,18 +2,19 @@ #define GRAPH_INTERSECTION_GRAPH_CONTROLLER_H #include "calculation_graph_controller.h" +#include "../storage_cartesian_function_store.h" namespace Graph { class IntersectionGraphController : public CalculationGraphController { public: - IntersectionGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, CartesianFunctionStore * functionStore); + IntersectionGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor, StorageCartesianFunctionStore * functionStore); const char * title() override; private: void reloadBannerView() override; Poincare::Expression::Coordinate2D computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override; - Shared::Function * m_intersectedFunction; - CartesianFunctionStore * m_functionStore; + Shared::StorageFunction * m_intersectedFunction; + StorageCartesianFunctionStore * m_functionStore; }; } diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index 2dcda7bc5..33134214c 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -29,7 +29,7 @@ void TangentGraphController::viewWillAppear() { m_graphView->reload(); } -void TangentGraphController::setFunction(CartesianFunction * function) { +void TangentGraphController::setFunction(StorageCartesianFunction * function) { m_graphView->selectFunction(function); m_function = function; } @@ -39,7 +39,7 @@ void TangentGraphController::reloadBannerView() { if (m_function == nullptr) { return; } - FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x'); + StorageFunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x'); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_function, myApp); constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); diff --git a/apps/graph/graph/tangent_graph_controller.h b/apps/graph/graph/tangent_graph_controller.h index c1850dcba..cad6a2219 100644 --- a/apps/graph/graph/tangent_graph_controller.h +++ b/apps/graph/graph/tangent_graph_controller.h @@ -5,17 +5,17 @@ #include "banner_view.h" #include "graph_controller_helper.h" #include "../../shared/simple_interactive_curve_view_controller.h" -#include "../../shared/function_banner_delegate.h" -#include "../cartesian_function_store.h" +#include "../../shared/storage_function_banner_delegate.h" +#include "../storage_cartesian_function_store.h" namespace Graph { -class TangentGraphController : public Shared::SimpleInteractiveCurveViewController, public Shared::FunctionBannerDelegate, public GraphControllerHelper { +class TangentGraphController : public Shared::SimpleInteractiveCurveViewController, public Shared::StorageFunctionBannerDelegate, public GraphControllerHelper { public: TangentGraphController(Responder * parentResponder, GraphView * graphView, BannerView * bannerView, Shared::InteractiveCurveViewRange * curveViewRange, Shared::CurveViewCursor * cursor); const char * title() override; void viewWillAppear() override; - void setFunction(CartesianFunction * function); + void setFunction(Shared::StorageCartesianFunction * function); private: constexpr static float k_cursorTopMarginRatio = 0.07f; // (cursorHeight/2)/graphViewHeight constexpr static float k_cursorBottomMarginRatio = 0.22f; // (cursorHeight/2+bannerHeigh)/graphViewHeight @@ -28,7 +28,7 @@ private: GraphView * m_graphView; BannerView * m_bannerView; Shared::InteractiveCurveViewRange * m_graphRange; - CartesianFunction * m_function; + Shared::StorageCartesianFunction * m_function; }; }