[poincare/zoom] Method CombineRanges

The logic behind combining several ranges will be handled by the Zoom
class directly.

Change-Id: I4de3f020d94b9bc1a21953b0c416158c65beb606
This commit is contained in:
Gabriel Ozouf
2020-10-13 11:15:57 +02:00
committed by Émilie Feral
parent 81e425eb04
commit 8572f4953c
2 changed files with 21 additions and 3 deletions

View File

@@ -23,6 +23,8 @@ public:
static void RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, Context * context, const void * auxiliary);
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);
/* 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.*/
static void SetToRatio(float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, bool shrink = false);

View File

@@ -204,6 +204,25 @@ void Zoom::RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float
}
}
void Zoom::CombineRanges(int length, const float * mins, const float * maxs, float * minRes, float * maxRes) {
ValueAtAbscissa evaluation = [](float x, Context * context, const void * auxiliary) {
int index = std::round(x);
return static_cast<const float *>(auxiliary)[index];
};
FullRange(evaluation, 0, length - 1, 1, minRes, maxRes, nullptr, mins);
float min, max;
FullRange(evaluation, 0, length - 1, 1, &min, &max, nullptr, maxs);
if (min < *minRes) {
*minRes = min;
}
if (max > *maxRes) {
*maxRes = max;
}
if (*minRes == *maxRes) {
RangeFromSingleValue(*minRes, minRes, maxRes);
}
}
void Zoom::SetToRatio(float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, bool shrink) {
float currentRatio = (*yMax - *yMin) / (*xMax - *xMin);
@@ -276,9 +295,6 @@ void Zoom::FullRange(ValueAtAbscissa evaluation, float tMin, float tMax, float t
}
t += tStep;
}
if (*fMin == *fMax) {
RangeFromSingleValue(*fMin, fMin, fMax);
}
}
void Zoom::RangeFromSingleValue(float value, float * boundMin, float * boundMax) {