diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index db5e4a147..f3e61fd8b 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -10,6 +10,9 @@ using namespace Poincare; namespace Graph { +static inline double minDouble(double x, double y) { return x < y ? x : y; } +static inline double maxDouble(double x, double y) { return x > y ? x : y; } + bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record) { ExpiringPointer function = App::app()->functionStore()->modelForRecord(record); double tCursorPosition = cursor->t(); @@ -19,11 +22,12 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso double dir = (direction > 0 ? 1.0 : -1.0); ContinuousFunction::PlotType type = function->plotType(); if (type == ContinuousFunction::PlotType::Cartesian) { - t+= dir * range->xGridUnit()/numberOfStepsInGradUnit; + t += dir * range->xGridUnit()/numberOfStepsInGradUnit; } else { assert(type == ContinuousFunction::PlotType::Polar || type == ContinuousFunction::PlotType::Parametric); t += dir * (tMax-tMin)/k_definitionDomainDivisor; } + t = maxDouble(tMin, minDouble(tMax, t)); Coordinate2D xy = function->evaluateXYAtParameter(t, App::app()->localContext()); cursor->moveTo(t, xy.x1(), xy.x2()); return true;