diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 0cae543c2..8eb6daa24 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -75,4 +75,12 @@ int GraphController::closestCurveIndexVertically(bool goingUp, int currentSelect return nextActiveFunctionIndex >= nbOfActiveFunctions ? -1 : nextActiveFunctionIndex; } +double GraphController::defaultCursorT(Ion::Storage::Record record) { + ExpiringPointer function = functionStore()->modelForRecord(record); + if (function->plotType() == CartesianFunction::PlotType::Cartesian) { + return FunctionGraphController::defaultCursorT(record); + } + return function->tMin(); +} + } diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 482714543..2c804fbb8 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -28,6 +28,7 @@ private: void reloadBannerView() override; bool moveCursorHorizontally(int direction) override; int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const override; + double defaultCursorT(Ion::Storage::Record record) override; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } GraphView * functionGraphView() override { return &m_view; } CurveParameterController * curveParameterController() override { return &m_curveParameterController; } diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 3714388eb..d77870675 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -99,8 +99,8 @@ bool GraphController::moveCursorHorizontally(int direction) { return true; } -double GraphController::defaultCursorT() { - return std::fmax(0.0, std::round(Shared::FunctionGraphController::defaultCursorT())); +double GraphController::defaultCursorT(Ion::Storage::Record record) { + return std::fmax(0.0, std::round(Shared::FunctionGraphController::defaultCursorT(record))); } } diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index b7cc19542..f0e4bb118 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -26,7 +26,7 @@ private: Shared::XYBannerView * bannerView() override { return &m_bannerView; } bool handleEnter() override; bool moveCursorHorizontally(int direction) override; - double defaultCursorT() override; + double defaultCursorT(Ion::Storage::Record record) override; CurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } SequenceStore * functionStore() const override { return static_cast(Shared::FunctionGraphController::functionStore()); } GraphView * functionGraphView() override { return &m_view; } diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index f7b4bf010..38a02e780 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -122,8 +122,8 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange( return range; } -double FunctionGraphController::defaultCursorT() { - return 0.0; //TODO LEA interactiveCurveViewRange()->xCenter(); +double FunctionGraphController::defaultCursorT(Ion::Storage::Record record) { + return (interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0f; } FunctionStore * FunctionGraphController::functionStore() const { @@ -131,12 +131,14 @@ FunctionStore * FunctionGraphController::functionStore() const { } void FunctionGraphController::initCursorParameters() { - double t = defaultCursorT(); Poincare::Context * context = textFieldDelegateApp()->localContext(); int functionIndex = 0; Coordinate2D xy; + double t; do { - ExpiringPointer firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++)); + Ion::Storage::Record record = functionStore()->activeRecordAtIndex(functionIndex++); + ExpiringPointer firstFunction = functionStore()->modelForRecord(record); + t = defaultCursorT(record); xy = firstFunction->evaluateXYAtParameter(t, context); } while ((std::isnan(xy.x2()) || std::isinf(xy.x2())) && functionIndex < functionStore()->numberOfActiveFunctions()); m_cursor->moveTo(t, xy.x1(), xy.x2()); diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 7c37742d3..3565d2a77 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -25,7 +25,7 @@ protected: bool handleEnter() override; int indexFunctionSelectedByCursor() const { return *m_indexFunctionSelectedByCursor; } virtual void selectFunctionWithCursor(int functionIndex); - virtual double defaultCursorT(); + virtual double defaultCursorT(Ion::Storage::Record record); virtual FunctionStore * functionStore() const; // Closest vertical curve helper