[poincare/zoom] Method SanitizeRange

Create a method to clean up an ill-formed range, ie a range whose bounds
are not finite, or where max <= min.

Change-Id: If4525e65f95385cfa970be72bbcc21ad84286bfa
This commit is contained in:
Gabriel Ozouf
2020-10-15 15:41:34 +02:00
committed by Émilie Feral
parent 71e7070657
commit b10be2c60c
2 changed files with 35 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ public:
static void FullRange(ValueAtAbscissa evaluation, float tMin, float tMax, float tStep, float * fMin, float * fMax, Context * context, const void * auxiliary);
static void CombineRanges(int length, const float * mins, const float * maxs, float * minRes, float * maxRes);
static void SanitizeRange(float * xMin, float * xMax, float * yMin, float * yMax, float normalRatio);
/* If shrink is false, the range will be set to ratio by increasing the size
* of the smallest axis. If it is true, the longest axis will be reduced.*/

View File

@@ -237,6 +237,40 @@ void Zoom::CombineRanges(int length, const float * mins, const float * maxs, flo
}
}
void Zoom::SanitizeRange(float * xMin, float * xMax, float * yMin, float * yMax, float normalRatio) {
/* Axes of the window can be :
* - well-formed
* - empty (min = max)
* - ill-formed (min > max, or either bound is not finite)
*
* The general strategy to sanitize a window is as follow :
* - for all ill-formed axes, set both bounds to 0
* - if both axes are empty, set the X axis to default bounds
* - if one axis is empty, normalize the window
* - do nothing if both axes are well-formed. */
if (!std::isfinite(*xMin) || !std::isfinite(*xMax) || *xMax < *xMin) {
*xMin = 0;
*xMax = 0;
}
if (!std::isfinite(*yMin) || !std::isfinite(*yMax) || *yMax < *yMin) {
*yMin = 0;
*yMax = 0;
}
float xRange = *xMax - *xMin;
float yRange = *yMax - *yMin;
if (xRange < k_minimalRangeLength && yRange < k_minimalRangeLength) {
*xMax = *xMin + k_defaultHalfRange;
*xMin -= k_defaultHalfRange;
xRange = 2 * k_defaultHalfRange;
}
if (xRange < k_minimalRangeLength || yRange < k_minimalRangeLength) {
SetToRatio(normalRatio, xMin, xMax, yMin, yMax, false);
}
}
void Zoom::SetToRatio(float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, bool shrink) {
float currentRatio = (*yMax - *yMin) / (*xMax - *xMin);