From 79a70f5b6ef657e6916403c70dc4f3e1a79db6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 23 Sep 2019 16:09:54 +0200 Subject: [PATCH] [apps/graph] Clip t when navigating curves vertically --- apps/shared/function_graph_controller.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 3ed0261c2..02b2a9212 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -12,6 +12,8 @@ namespace Shared { static inline float minFloat(float x, float y) { return x < y ? x : y; } static inline float maxFloat(float x, float y) { return x > y ? x : y; } +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; } FunctionGraphController::FunctionGraphController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, int * indexFunctionSelectedByCursor, uint32_t * modelVersion, uint32_t * rangeVersion, Preferences::AngleUnit * angleUnitVersion) : InteractiveCurveViewController(parentResponder, inputEventHandlerDelegate, header, interactiveRange, curveView, cursor, modelVersion, rangeVersion), @@ -157,8 +159,15 @@ bool FunctionGraphController::moveCursorVertically(int direction) { if (nextActiveFunctionIndex < 0) { return false; } - Poincare::Coordinate2D cursorPosition = xyValues(nextActiveFunctionIndex, m_cursor->t(), context); - m_cursor->moveTo(m_cursor->t(), cursorPosition.x1(), cursorPosition.x2()); + // Clip the current t to the domain of the next function + ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(nextActiveFunctionIndex)); + double clippedT = m_cursor->t(); + if (!std::isnan(f->tMin())) { + assert(!std::isnan(f->tMax())); + clippedT = minDouble(f->tMax(), maxDouble(f->tMin(), clippedT)); + } + Poincare::Coordinate2D cursorPosition = f->evaluateXYAtParameter(clippedT, context); + m_cursor->moveTo(clippedT, cursorPosition.x1(), cursorPosition.x2()); selectFunctionWithCursor(nextActiveFunctionIndex); return true; }