[poincare/zoom] Factor range sanitation

Checking wether the range that has been computed is suitable is now
done in Poincare::Zoom by SanitizeRange.

Change-Id: Ib7ff73a3beae29996b1a773744021ad85c6ba946
This commit is contained in:
Gabriel Ozouf
2020-10-15 16:04:25 +02:00
committed by Émilie Feral
parent b10be2c60c
commit c4cd3ecffa
5 changed files with 6 additions and 36 deletions

View File

@@ -160,14 +160,12 @@ void FunctionGraphController::interestingRanges(InteractiveCurveViewRange * rang
float xMin, xMax, yMin, yMax;
Poincare::Zoom::CombineRanges(length, xMins, xMaxs, &xMin, &xMax);
Poincare::Zoom::CombineRanges(length, yMins, yMaxs, &yMin, &yMax);
if (std::isfinite(xMin) && std::isfinite(xMax) && std::isfinite(yMin) && std::isfinite(yMax) && xMax > xMin && yMax > yMin) {
range->setXMin(xMin);
range->setXMax(xMax);
range->setYMin(yMin);
range->setYMax(yMax);
} else {
range->setNullRange();
}
Poincare::Zoom::SanitizeRange(&xMin, &xMax, &yMin, &yMax, range->NormalYXRatio());
range->setXMin(xMin);
range->setXMax(xMax);
range->setYMin(yMin);
range->setYMax(yMax);
}
}

View File

@@ -137,14 +137,6 @@ void InteractiveCurveViewRange::setDefault() {
setZoomAuto(true);
}
void InteractiveCurveViewRange::setNullRange() {
m_xRange.setMin(- Range1D::k_default);
setXMax(Range1D::k_default);
m_yRange.setMin(0);
m_yRange.setMax(0);
normalize();
}
void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) {
if (std::isnan(position)) {
return;

View File

@@ -44,7 +44,6 @@ public:
void panWithVector(float x, float y);
virtual void normalize();
virtual void setDefault();
void setNullRange();
void centerAxisAround(Axis axis, float position);
void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation, float pixelWidth);

View File

@@ -30,9 +30,6 @@ public:
* 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);
/* Compute a default range so that boundMin < value < boundMax */
static void RangeFromSingleValue(float value, float * boundMin, float * boundMax);
private:
static constexpr int k_peakNumberOfPointsOfInterest = 3;
static constexpr int k_sampleSize = Ion::Display::Width / 4;

View File

@@ -205,9 +205,6 @@ void Zoom::RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float
*yMin = sampleYMin;
*yMax = sampleYMax;
}
if (*yMin == *yMax) {
RangeFromSingleValue(*yMin, yMin, yMax);
}
/* Round out the smallest bound to 0 if it is negligible compare to the
* other one. This way, we can display the X axis for positive functions such
* as sqrt(x) even if we do not sample close to 0. */
@@ -232,9 +229,6 @@ void Zoom::CombineRanges(int length, const float * mins, const float * maxs, flo
if (max > *maxRes) {
*maxRes = max;
}
if (*minRes == *maxRes) {
RangeFromSingleValue(*minRes, minRes, maxRes);
}
}
void Zoom::SanitizeRange(float * xMin, float * xMax, float * yMin, float * yMax, float normalRatio) {
@@ -351,16 +345,6 @@ void Zoom::FullRange(ValueAtAbscissa evaluation, float tMin, float tMax, float t
}
}
void Zoom::RangeFromSingleValue(float value, float * boundMin, float * boundMax) {
constexpr float margin = 0.2f;
float delta = margin * std::fabs(value);
if (delta < k_minimalRangeLength) {
delta = 1.f;
}
*boundMin = value - delta;
*boundMax = value + delta;
}
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;