From ad6edffc071ec73bc659867ee05f1083a734dc43 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 8 Oct 2020 11:56:21 +0200 Subject: [PATCH] [poincare/zoom] Remove tuneXRange argument The ability to perform a range search without changing the X range was only there to accomodate the Yauto feature. Change-Id: I8c2b61b447fbd3dc1f4e303dff06d1a8d6e7a4f2 --- apps/shared/continuous_function.cpp | 4 +-- apps/shared/continuous_function.h | 2 +- apps/shared/function.cpp | 4 +-- apps/shared/function.h | 4 +-- apps/shared/function_graph_controller.cpp | 10 ++---- apps/shared/function_graph_controller.h | 1 - apps/shared/sequence.h | 2 +- poincare/include/poincare/zoom.h | 2 +- poincare/src/zoom.cpp | 44 +++++++++++------------ 9 files changed, 32 insertions(+), 41 deletions(-) diff --git a/apps/shared/continuous_function.cpp b/apps/shared/continuous_function.cpp index 36d6b4390..7fd9b47c3 100644 --- a/apps/shared/continuous_function.cpp +++ b/apps/shared/continuous_function.cpp @@ -261,9 +261,9 @@ void ContinuousFunction::setTMax(float tMax) { setCache(nullptr); } -void ContinuousFunction::rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange) const { +void ContinuousFunction::rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context) const { if (plotType() == PlotType::Cartesian) { - protectedRangeForDisplay(xMin, xMax, yMin, yMax, context, tuneXRange, true); + protectedRangeForDisplay(xMin, xMax, yMin, yMax, context, true); } else { fullXYRange(xMin, xMax, yMin, yMax, context); } diff --git a/apps/shared/continuous_function.h b/apps/shared/continuous_function.h index c66be00f7..34642fb8a 100644 --- a/apps/shared/continuous_function.h +++ b/apps/shared/continuous_function.h @@ -70,7 +70,7 @@ public: void setTMax(float tMax); float rangeStep() const override { return plotType() == PlotType::Cartesian ? NAN : (tMax() - tMin())/k_polarParamRangeSearchNumberOfPoints; } - void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange = true) const override; + void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context) const override; // Extremum Poincare::Coordinate2D nextMinimumFrom(double start, double step, double max, Poincare::Context * context) const; diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index 6cfc69963..253e51f77 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -79,7 +79,7 @@ Function::RecordDataBuffer * Function::recordData() const { return reinterpret_cast(const_cast(d.buffer)); } -void Function::protectedRangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange, bool boundByMagnitude) const { +void Function::protectedRangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool boundByMagnitude) const { Zoom::ValueAtAbscissa evaluation = [](float x, Context * context, const void * auxiliary) { /* When evaluating sin(x)/x close to zero using the standard sine function, * one can detect small variations, while the cardinal sine is supposed to be @@ -89,7 +89,7 @@ void Function::protectedRangeForDisplay(float * xMin, float * xMax, float * yMin constexpr float precision = 1e-5; return precision * std::round(static_cast(auxiliary)->evaluateXYAtParameter(x, context).x2() / precision); }; - Zoom::InterestingRangesForDisplay(evaluation, xMin, xMax, yMin, yMax, tMin(), tMax(), context, this, tuneXRange); + Zoom::InterestingRangesForDisplay(evaluation, xMin, xMax, yMin, yMax, tMin(), tMax(), context, this); evaluation = [](float x, Context * context, const void * auxiliary) { return static_cast(auxiliary)->evaluateXYAtParameter(x, context).x2(); diff --git a/apps/shared/function.h b/apps/shared/function.h index 49442d1b3..83e65f273 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -55,7 +55,7 @@ public: virtual Poincare::Expression sumBetweenBounds(double start, double end, Poincare::Context * context) const = 0; // Range - virtual void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange = true) const = 0; + virtual void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context) const = 0; protected: /* RecordDataBuffer is the layout of the data buffer of Record @@ -93,7 +93,7 @@ protected: bool m_active; }; - void protectedRangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange, bool boundByMagnitude) const; + void protectedRangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool boundByMagnitude) const; private: RecordDataBuffer * recordData() const; diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 7f6bf66d7..eb5547827 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -137,20 +137,16 @@ int FunctionGraphController::numberOfCurves() const { } void FunctionGraphController::interestingRanges(InteractiveCurveViewRange * range) const { - privateComputeRanges(true, range); -} - -void FunctionGraphController::privateComputeRanges(bool tuneXRange, InteractiveCurveViewRange * range) const { Poincare::Context * context = textFieldDelegateApp()->localContext(); - float resultXMin = tuneXRange ? FLT_MAX : range->xMin(); - float resultXMax = tuneXRange ? -FLT_MAX : range->xMax(); + float resultXMin = FLT_MAX; + float resultXMax = -FLT_MAX; float resultYMin = FLT_MAX; float resultYMax = -FLT_MAX; assert(functionStore()->numberOfActiveFunctions() > 0); int functionsCount = functionStore()->numberOfActiveFunctions(); for (int i = 0; i < functionsCount; i++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); - f->rangeForDisplay(&resultXMin, &resultXMax, &resultYMin, &resultYMax, context, tuneXRange); + f->rangeForDisplay(&resultXMin, &resultXMax, &resultYMin, &resultYMax, context); } range->setXMin(resultXMin); diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 9605564d8..6c3469a25 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -39,7 +39,6 @@ protected: void initCursorParameters() override; CurveView * curveView() override; - void privateComputeRanges(bool tuneXRange, Shared::InteractiveCurveViewRange * range) const; void yRangeForCursorFirstMove(Shared::InteractiveCurveViewRange * range) const; private: diff --git a/apps/shared/sequence.h b/apps/shared/sequence.h index 58ac6e7ad..2918f7041 100644 --- a/apps/shared/sequence.h +++ b/apps/shared/sequence.h @@ -76,7 +76,7 @@ public: constexpr static int k_initialRankNumberOfDigits = 3; // m_initialRank is capped by 999 //Range - void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context, bool tuneXRange = true) const override { protectedRangeForDisplay(xMin, xMax, yMin, yMax, context, tuneXRange, false); }; + void rangeForDisplay(float * xMin, float * xMax, float * yMin, float * yMax, Poincare::Context * context) const override { protectedRangeForDisplay(xMin, xMax, yMin, yMax, context, false); }; private: constexpr static const KDFont * k_layoutFont = KDFont::LargeFont; diff --git a/poincare/include/poincare/zoom.h b/poincare/include/poincare/zoom.h index 69a33d5f7..33a08e932 100644 --- a/poincare/include/poincare/zoom.h +++ b/poincare/include/poincare/zoom.h @@ -12,7 +12,7 @@ public: typedef float (*ValueAtAbscissa)(float abscissa, Context * context, const void * auxiliary); - static void InterestingRangesForDisplay(ValueAtAbscissa evaluation, float * xMin, float * xMax, float * yMin, float * yMax, float tMin, float tMax, Context * context, const void * auxiliary, bool tuneXRange = false); + 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); private: diff --git a/poincare/src/zoom.cpp b/poincare/src/zoom.cpp index 315f255bf..b5aedb0a7 100644 --- a/poincare/src/zoom.cpp +++ b/poincare/src/zoom.cpp @@ -17,15 +17,12 @@ constexpr float Zoom::k_defaultHalfRange, Zoom::k_maxRatioBetweenPointsOfInterest; -void Zoom::InterestingRangesForDisplay(ValueAtAbscissa evaluation, float * xMin, float * xMax, float * yMin, float * yMax, float tMin, float tMax, Context * context, const void * auxiliary, bool tuneXRange) { +void Zoom::InterestingRangesForDisplay(ValueAtAbscissa evaluation, float * xMin, float * xMax, float * yMin, float * yMax, float tMin, float tMax, Context * context, const void * auxiliary) { assert(xMin && xMax && yMin && yMax); const bool hasIntervalOfDefinition = std::isfinite(tMin) && std::isfinite(tMax); float center, maxDistance; - if (!tuneXRange) { - center = (*xMax + *xMin) / 2.f; - maxDistance = (*xMax - *xMin) / 2.f; - } else if (hasIntervalOfDefinition) { + if (hasIntervalOfDefinition) { center = (tMax + tMin) / 2.f; maxDistance = (tMax - tMin) / 2.f; } else { @@ -132,26 +129,25 @@ void Zoom::InterestingRangesForDisplay(ValueAtAbscissa evaluation, float * xMin, } } - if (tuneXRange) { - /* Cut after horizontal asymptotes. */ - resultX[0] = std::min(resultX[0], asymptote[0]); - resultX[1] = std::max(resultX[1], asymptote[1]); - if (resultX[0] >= resultX[1]) { - /* Fallback to default range. */ - resultX[0] = - k_defaultHalfRange; - resultX[1] = k_defaultHalfRange; - } else { - /* Add breathing room around points of interest. */ - float xRange = resultX[1] - resultX[0]; - resultX[0] -= k_breathingRoom * xRange; - resultX[1] += k_breathingRoom * xRange; - /* Round to the next integer. */ - resultX[0] = std::floor(resultX[0]); - resultX[1] = std::ceil(resultX[1]); - } - *xMin = std::min(resultX[0], *xMin); - *xMax = std::max(resultX[1], *xMax); + /* Cut after horizontal asymptotes. */ + resultX[0] = std::min(resultX[0], asymptote[0]); + resultX[1] = std::max(resultX[1], asymptote[1]); + if (resultX[0] >= resultX[1]) { + /* Fallback to default range. */ + resultX[0] = - k_defaultHalfRange; + resultX[1] = k_defaultHalfRange; + } else { + /* Add breathing room around points of interest. */ + float xRange = resultX[1] - resultX[0]; + resultX[0] -= k_breathingRoom * xRange; + resultX[1] += k_breathingRoom * xRange; + /* Round to the next integer. */ + resultX[0] = std::floor(resultX[0]); + resultX[1] = std::ceil(resultX[1]); } + *xMin = std::min(resultX[0], *xMin); + *xMax = std::max(resultX[1], *xMax); + *yMin = std::min(resultYMin, *yMin); *yMax = std::max(resultYMax, *yMax); }