From c4cd3ecffaaff9f04a33b00e14952562222b6c74 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 15 Oct 2020 16:04:25 +0200 Subject: [PATCH] [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 --- apps/shared/function_graph_controller.cpp | 14 ++++++-------- apps/shared/interactive_curve_view_range.cpp | 8 -------- apps/shared/interactive_curve_view_range.h | 1 - poincare/include/poincare/zoom.h | 3 --- poincare/src/zoom.cpp | 16 ---------------- 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index c634ed493..a87f128fb 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -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); } } diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index ac3ce0b8f..7a3d70d97 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -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; diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index ce23d261b..0014d3dc1 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -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); diff --git a/poincare/include/poincare/zoom.h b/poincare/include/poincare/zoom.h index 132071d20..bd3fb9bca 100644 --- a/poincare/include/poincare/zoom.h +++ b/poincare/include/poincare/zoom.h @@ -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; diff --git a/poincare/src/zoom.cpp b/poincare/src/zoom.cpp index e18c0ebfb..cb17dc509 100644 --- a/poincare/src/zoom.cpp +++ b/poincare/src/zoom.cpp @@ -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;