From 8572f4953c393b92a74f531f2e5a02d372608b1a Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 13 Oct 2020 11:15:57 +0200 Subject: [PATCH] [poincare/zoom] Method CombineRanges The logic behind combining several ranges will be handled by the Zoom class directly. Change-Id: I4de3f020d94b9bc1a21953b0c416158c65beb606 --- poincare/include/poincare/zoom.h | 2 ++ poincare/src/zoom.cpp | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/poincare/include/poincare/zoom.h b/poincare/include/poincare/zoom.h index ff375415c..2c0b7b891 100644 --- a/poincare/include/poincare/zoom.h +++ b/poincare/include/poincare/zoom.h @@ -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); diff --git a/poincare/src/zoom.cpp b/poincare/src/zoom.cpp index f20a596ba..b7004baa4 100644 --- a/poincare/src/zoom.cpp +++ b/poincare/src/zoom.cpp @@ -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(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) {