[poincare/zoom] Comment on the RangeWithRatio method

This commit is contained in:
Gabriel Ozouf
2020-12-07 15:40:34 +01:00
committed by LeaNumworks
parent 71be09b4e7
commit 89979b4f50

View File

@@ -247,6 +247,12 @@ void Zoom::RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float
}
void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, Context * context, const void * auxiliary) {
/* The goal of this algorithm is to find the window with given ratio, that
* best suits the function.
* - The X range is centered around a point of interest of the function, or
* 0 if none exist, and uses a default width of 20.
* - The Y range's height is fixed at 20*yxRatio. Its center is chosen to
* maximize the number of visible points of the function. */
constexpr float minimalXCoverage = 0.15f;
constexpr float minimalYCoverage = 0.3f;
constexpr int sampleSize = k_sampleSize * 2;
@@ -274,6 +280,18 @@ void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, f
sample,
sampleSize);
/* For each value taken by the sample of the function on [xMin, xMax], given
* a fixed value for yRange, we measure the number (referred to as breadth)
* of other points that could be displayed if this value was chosen as yMin.
* In other terms, given a sorted set Y={y1,...,yn} and a length dy, we look
* for the pair 1<=i,j<=n such that :
* - yj - yi <= dy
* - i - j is maximal
* The fact that the sample is sorted makes it possible to find i and j in
* linear time.
* In case of pairs having the same breadth, we chose the pair that minimizes
* the criteria distanceFromCenter, which makes the window symmetrical when
* dealing with linear functions. */
float yRange = yxRatio * xRange;
int j = 1;
int bestIndex, bestBreadth = 0, bestDistanceToCenter;
@@ -295,6 +313,9 @@ void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, f
}
}
/* Functions with a very steep slope might only take a small portion of the
* X axis. Conversely, very flat functions may only take a small portion of
* the Y range. In those cases, the ratio is not suitable. */
if (bestBreadth < minimalXCoverage * sampleSize
|| sample[bestIndex + bestBreadth] - sample[bestIndex] < minimalYCoverage * yRange) {
*xMin = NAN;