[apps/graph] Fix computeYRange for polar/cartesian functions

Was very slow, compute only 1000 values to evaluate the yRange
This commit is contained in:
Léa Saviot
2019-09-03 13:57:06 +02:00
parent a4099c4c3e
commit c3ee6a71e7
4 changed files with 14 additions and 5 deletions

View File

@@ -81,10 +81,6 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(
float max = -FLT_MAX;
float xMin = interactiveCurveViewRange->xMin();
float xMax = interactiveCurveViewRange->xMax();
/* In practice, a step smaller than a pixel's width is needed for sampling
* the values of a function. Otherwise some relevant extremal values may be
* missed. */
const float step = curveView()->pixelWidth() / 2;
assert(functionStore()->numberOfActiveFunctions() > 0);
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
ExpiringPointer<Function> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
@@ -102,6 +98,11 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(
} else if (f->shouldClipTRangeToXRange()) {
tMax = minFloat(tMax, xMax);
}
/* In practice, a step smaller than a pixel's width is needed for sampling
* the values of a function. Otherwise some relevant extremal values may be
* missed. */
float rangeStep = f->rangeStep();
const float step = std::isnan(rangeStep) ? curveView()->pixelWidth() / 2.0f : rangeStep;
const int balancedBound = std::floor((tMax-tMin)/2/step);
for (int j = -balancedBound; j <= balancedBound ; j++) {
float t = (tMin+tMax)/2 + step * j;