mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/zoom] Method RangeFromSingleValue
This method adds margins to a range whose bounds are equal. Change-Id: I2b2fe26fe431deda112389060d401f738a75b1ae
This commit is contained in:
committed by
Émilie Feral
parent
a525c35ebb
commit
09c061e871
@@ -19,7 +19,7 @@ class __attribute__((packed)) Range1D final {
|
||||
public:
|
||||
/* If m_min and m_max are too close, we cannot divide properly the range by
|
||||
* the number of pixels, which creates a drawing problem. */
|
||||
constexpr static float k_minFloat = 1E-4f;
|
||||
constexpr static float k_minFloat = Poincare::Zoom::k_minimalRangeLength;
|
||||
constexpr static float k_default = Poincare::Zoom::k_defaultHalfRange;
|
||||
Range1D(float min = -k_default, float max = k_default) :
|
||||
m_min(min),
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
static constexpr float k_smallUnitMantissa = 1.f;
|
||||
static constexpr float k_mediumUnitMantissa = 2.f;
|
||||
static constexpr float k_largeUnitMantissa = 5.f;
|
||||
static constexpr float k_minimalRangeLength = 1e-4f;
|
||||
|
||||
typedef float (*ValueAtAbscissa)(float abscissa, Context * context, const void * auxiliary);
|
||||
|
||||
@@ -25,6 +26,9 @@ 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;
|
||||
|
||||
@@ -18,7 +18,8 @@ constexpr float
|
||||
Zoom::k_maxRatioBetweenPointsOfInterest,
|
||||
Zoom::k_smallUnitMantissa,
|
||||
Zoom::k_mediumUnitMantissa,
|
||||
Zoom::k_largeUnitMantissa;
|
||||
Zoom::k_largeUnitMantissa,
|
||||
Zoom::k_minimalRangeLength;
|
||||
|
||||
bool 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);
|
||||
@@ -191,9 +192,7 @@ void Zoom::RefinedYRangeForDisplay(ValueAtAbscissa evaluation, float xMin, float
|
||||
*yMin = std::min(*yMin, sampleYMin);
|
||||
*yMax = std::max(*yMax, sampleYMax);
|
||||
if (*yMin == *yMax) {
|
||||
float d = (*yMin == 0.f) ? 1.f : *yMin * 0.2f;
|
||||
*yMin -= d;
|
||||
*yMax += d;
|
||||
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
|
||||
@@ -263,6 +262,16 @@ void Zoom::RangeWithRatioForDisplay(ValueAtAbscissa evaluation, float yxRatio, f
|
||||
SetToRatio(yxRatio, xMin, xMax, yMin, yMax, true);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user