[apps/graph] Clip cursor navigation to definition domain

This commit is contained in:
Léa Saviot
2019-08-30 11:35:55 +02:00
parent b3ecd16218
commit 67e5114194

View File

@@ -9,12 +9,22 @@ using namespace Poincare;
namespace Graph {
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; }
bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record) {
ExpiringPointer<CartesianFunction> function = App::app()->functionStore()->modelForRecord(record);
double tCursorPosition = cursor->t();
double t = tCursorPosition;
double tMin = function->tMin();
double tMax = function->tMax();
double dir = (direction > 0 ? 1.0 : -1.0);
CartesianFunction::PlotType type = function->plotType();
if ((dir > 0 && t >= tMax) || (dir < 0 && t <= tMin)) {
// Stay inside the definition domain
assert((t == tMax) || (t == tMin));
return true;
}
if (type == CartesianFunction::PlotType::Cartesian) {
t+= dir * range->xGridUnit()/numberOfStepsInGradUnit;
} else if (type == CartesianFunction::PlotType::Polar) {
@@ -23,7 +33,7 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso
assert(type == CartesianFunction::PlotType::Parametric);
t += dir; //TODO LEA delt
}
t = maxFloat(minFloat(t, tMax), tMin); // Stay inside the definition domain
Coordinate2D<double> xy = function->evaluateXYAtParameter(t, App::app()->localContext());
cursor->moveTo(t, xy.x1(), xy.x2());
return true;