[poincare/zoom] Method SetToRatio

Added a method to Zoom to set a range to a specific ratio. This method
is used by InteractiveCurveViewRange::normalize.

Change-Id: Id3029439294ece02ea19fb6c6de90b9edc85d771
This commit is contained in:
Gabriel Ozouf
2020-10-08 16:36:37 +02:00
committed by Émilie Feral
parent c4aad1641e
commit 08c96c5107
3 changed files with 37 additions and 17 deletions

View File

@@ -15,6 +15,10 @@ public:
static void InterestingRangesForDisplay(ValueAtAbscissa evaluation, float * xMin, float * xMax, float * yMin, float * yMax, float tMin, float tMax, Context * context, const void * auxiliary);
static void RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float xMax, float * yMin, float * yMax, Context * context, const void * auxiliary, bool boundByMagnitude = false);
/* 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);
private:
static constexpr int k_peakNumberOfPointsOfInterest = 3;
static constexpr int k_sampleSize = Ion::Display::Width / 4;

View File

@@ -199,6 +199,29 @@ void Zoom::RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float
}
}
void Zoom::SetToRatio(float yxRatio, float * xMin, float * xMax, float * yMin, float * yMax, bool shrink) {
float currentRatio = (*yMax - *yMin) / (*xMax - *xMin);
float * tMin;
float * tMax;
float newRange;
if ((currentRatio < yxRatio) == shrink) {
/* Y axis too small and shrink, or Y axis too large and do not shrink
* --> we change the X axis*/
tMin = xMin;
tMax = xMax;
newRange = (*yMax - *yMin) / yxRatio;
} else {
tMin = yMin;
tMax = yMax;
newRange = (*xMax - *xMin) * yxRatio;
}
float center = (*tMax + *tMin) / 2.f;
*tMax = center + newRange / 2.f;
*tMin = center - newRange / 2.f;
}
bool Zoom::IsConvexAroundExtremum(ValueAtAbscissa evaluation, float x1, float x2, float x3, float y1, float y2, float y3, Context * context, const void * auxiliary, int iterations) {
if (iterations <= 0) {
return false;