[function_graph_controller] Fix y for first move

Method yForCursorFirstMove is supposed to expand the window so that the
first move of the cursor won't cause it to pan. It now filters extreme
values to prevent the original window to be totally squashed, such as
with the drawing of e^x and (x-100)(x+10) at the same time.

Change-Id: Icd6c26b01475a112c4231f293e03ab31d80d5e51
This commit is contained in:
Gabriel Ozouf
2020-10-15 10:48:25 +02:00
committed by Émilie Feral
parent 0a6ac0b40b
commit 20cbefad41

View File

@@ -174,16 +174,27 @@ void FunctionGraphController::yRangeForCursorFirstMove(InteractiveCurveViewRange
int functionsCount = functionStore()->numberOfActiveFunctions();
float cursorStep = range->xGridUnit() / k_numberOfCursorStepsInGradUnit;
float yN, yP;
float y[2]; // Left and Right
bool normalized = range->isOrthonormal();
constexpr float maximalExpansion = 10.f;
float yRange = range->yMax() - range->yMin();
for (int i = 0; i < functionsCount; i++) {
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
yN = f->evaluateXYAtParameter(range->xCenter() - cursorStep, context).x2();
yP = f->evaluateXYAtParameter(range->xCenter() + cursorStep, context).x2();
range->setYMin(std::min(range->yMin(), std::min(yN, yP)));
range->setYMax(std::max(range->yMax(), std::max(yN, yP)));
for (int i = 0; i < 2; i++) {
float step = cursorStep * (i == 0 ? -1 : 1);
y[i] = f->evaluateXYAtParameter(range->xCenter() + step, context).x2();
if (std::isfinite(y[i])) {
if (y[i] < range->yMin() && (range->yMax() - y[i]) < maximalExpansion * yRange) {
range->setYMin(y[i]);
}
if (y[i] > range->yMax() && (y[i] - range->yMin()) < maximalExpansion * yRange) {
range->setYMax(y[i]);
}
}
}
}
if (normalized) {