From b140c768bb9fb22ff642264b25ffad1d4a3937ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 10:30:51 +0200 Subject: [PATCH 1/7] [poincare] Fix bug in convert float to text Change-Id: Iee47a093ffc6c3829183d16cf1224abf876bc087 --- poincare/src/complex.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/poincare/src/complex.cpp b/poincare/src/complex.cpp index 19a573f9c..3a92f5ece 100644 --- a/poincare/src/complex.cpp +++ b/poincare/src/complex.cpp @@ -252,11 +252,10 @@ int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSigni } float logBase10 = f != 0.0f ? log10f(fabsf(f)) : 0; - int exponentInBase10 = logBase10; - if ((int)f == 0 && logBase10 != exponentInBase10) { - /* For floats < 0, the exponent in base 10 is the inferior integer part of - * log10(float). We thus decrement the exponent for float < 0 whose exponent - * is not an integer. */ + int exponentInBase10 = floorf(logBase10); + /* Correct the exponent in base 10: sometines the exact log10 of f is 6.999999 + * but is stored as 7 in hardware. We catch these cases here. */ + if (f != 0.0f && logBase10 == (int)logBase10 && fabsf(f) < powf(10.0f, logBase10)) { exponentInBase10--; } @@ -281,11 +280,16 @@ int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSigni int numberOfDigitBeforeDecimal = exponentInBase10 >= 0 || displayMode == FloatDisplayMode::Scientific ? exponentInBase10 + 1 : 1; int mantissa = roundf(f * powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)); + /* We update the exponent in base 10 (if 0.99999999 was rounded to 1 for + * instance) */ + if (mantissa != (int)(f * powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))) { + float newLogBase10 = mantissa != 0.0f ? log10f(fabsf(mantissa/powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))) : 0; + exponentInBase10 = floorf(newLogBase10); + } // Correct the number of digits in mantissa after rounding int mantissaExponentInBase10 = exponentInBase10 > 0 || displayMode == FloatDisplayMode::Scientific ? availableCharsForMantissaWithoutSign - 1 : availableCharsForMantissaWithoutSign + exponentInBase10; if ((int)(mantissa * powf(10, - mantissaExponentInBase10)) > 0) { mantissa = mantissa/10; - exponentInBase10++; } int numberOfCharExponent = exponentInBase10 != 0 ? log10f(fabsf((float)exponentInBase10)) + 1 : 1; From 32252b0d25a7dde4d78661a7a3cd597a066cfe3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 11:13:29 +0200 Subject: [PATCH 2/7] [poincare] In convert float to text, avoid getting infinite values by using log. Change-Id: If4d66adcf5c9668fef8b733afdecebae8cd6d259 --- poincare/src/complex.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/poincare/src/complex.cpp b/poincare/src/complex.cpp index 3a92f5ece..6189524ec 100644 --- a/poincare/src/complex.cpp +++ b/poincare/src/complex.cpp @@ -279,11 +279,24 @@ int Complex::convertFloatToTextPrivate(float f, char * buffer, int numberOfSigni assert(availableCharsForMantissaWithoutSign - 1 < numberMaximalOfCharsInInteger); int numberOfDigitBeforeDecimal = exponentInBase10 >= 0 || displayMode == FloatDisplayMode::Scientific ? exponentInBase10 + 1 : 1; - int mantissa = roundf(f * powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)); + float mantissa = roundf(f * powf(10.0f, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)); + /* if availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal + * is too big (or too small), mantissa is now inf. We handle this case by + * using logarithm function. */ + if (isnan(mantissa) || isinf(mantissa)) { + mantissa = roundf(powf(10.0f, log10f(f)+(float)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))); + } /* We update the exponent in base 10 (if 0.99999999 was rounded to 1 for * instance) */ - if (mantissa != (int)(f * powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))) { - float newLogBase10 = mantissa != 0.0f ? log10f(fabsf(mantissa/powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))) : 0; + float truncatedMantissa = (int)(f * powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal)); + if (isinf(truncatedMantissa) || isnan(truncatedMantissa)) { + truncatedMantissa = (int)(powf(10.0f, log10f(f)+(float)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))); + } + if (mantissa != truncatedMantissa) { + float newLogBase10 = mantissa != 0.0f ? log10f(fabsf(mantissa/powf(10, availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal))) : 0.0f; + if (isnan(newLogBase10) || isinf(newLogBase10)) { + newLogBase10 = log10f(fabsf(mantissa)) - (float)(availableCharsForMantissaWithoutSign - 1 - numberOfDigitBeforeDecimal); + } exponentInBase10 = floorf(newLogBase10); } // Correct the number of digits in mantissa after rounding From 24631abb496d6288f301a0d0ba2f1925dec28a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 11:32:42 +0200 Subject: [PATCH 3/7] [poincare] Fix bug in store Change-Id: I7f88159df7034ede49dff3321b45d50777395b77 --- poincare/src/store.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 2050838cd..2f0a8dae0 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -76,7 +76,10 @@ Expression * Store::privateEvaluate(Context& context, AngleUnit angleUnit) const Expression * valueEvaluation = m_value->evaluate(context, angleUnit); context.setExpressionForSymbolName(valueEvaluation, m_symbol); delete valueEvaluation; - return context.expressionForSymbol(m_symbol)->clone(); + if (context.expressionForSymbol(m_symbol) != nullptr) { + return context.expressionForSymbol(m_symbol)->clone(); + } + return new Complex(Complex::Float(NAN)); } float Store::privateApproximate(Context& context, AngleUnit angleUnit) const { From db7aeba16a49a04f7c1174ad43b1ab6744c42d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 12:04:03 +0200 Subject: [PATCH 4/7] [apps/sequence] Fix bug: confusing rows and columns Change-Id: I7fd6a620ab8e950342aad67a302657f974dced44 --- apps/sequence/list/list_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 82156d866..3e20e222d 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -79,7 +79,7 @@ void ListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int void ListController::selectPreviousNewSequenceCell() { if (sequenceDefinitionForRow(m_selectableTableView.selectedRow()) >= 0) { - m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedRow()-sequenceDefinitionForRow(m_selectableTableView.selectedRow()), m_selectableTableView.selectedColumn()); + m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()-sequenceDefinitionForRow(m_selectableTableView.selectedRow())); } } From 0b837d07722540d8c7185dba58d08111053d6a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 12:17:02 +0200 Subject: [PATCH 5/7] [apps/shared] In interval, fix bug Change-Id: Ie49a47f6de9ad738835111c6f3b4ac8b5f594e54 --- apps/shared/interval.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/shared/interval.cpp b/apps/shared/interval.cpp index e2c423f0c..691f7cf85 100644 --- a/apps/shared/interval.cpp +++ b/apps/shared/interval.cpp @@ -74,7 +74,7 @@ void Interval::computeElements() { m_numberOfElements = 0; } else { m_numberOfElements = m_step > 0 ? 1 + (m_end - m_start)/m_step : k_maxNumberOfElements; - m_numberOfElements = m_numberOfElements > k_maxNumberOfElements ? k_maxNumberOfElements : m_numberOfElements; + m_numberOfElements = m_numberOfElements > k_maxNumberOfElements || m_numberOfElements < 0 ? k_maxNumberOfElements : m_numberOfElements; } for (int i = 0; i < m_numberOfElements; i += 1) { m_intervalBuffer[i] = m_start + i * m_step; From f2d745fa14eee50cca824caeb2eaddf2610e5af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 15:36:06 +0200 Subject: [PATCH 6/7] [apps/shared] In range parameter controller, fix bug Change-Id: I4d7229e353ffcfd50933e08986359a3fe89f8487 --- apps/shared/range_parameter_controller.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/shared/range_parameter_controller.cpp b/apps/shared/range_parameter_controller.cpp index 5222bdcec..05501eb59 100644 --- a/apps/shared/range_parameter_controller.cpp +++ b/apps/shared/range_parameter_controller.cpp @@ -91,16 +91,10 @@ void RangeParameterController::tableViewDidChangeSelection(SelectableTableView * } bool RangeParameterController::handleEvent(Ion::Events::Event event) { - if (activeCell() == 2) { - if (event == Ion::Events::OK) { - m_interactiveRange->setYAuto(!m_interactiveRange->yAuto()); - m_selectableTableView.reloadData(); - return true; - } - return false; - } - if (m_interactiveRange->yAuto() && (activeCell() == 3 || activeCell() == 4)) { - return false; + if (activeCell() == 2 && event == Ion::Events::OK) { + m_interactiveRange->setYAuto(!m_interactiveRange->yAuto()); + m_selectableTableView.reloadData(); + return true; } if (event == Ion::Events::Back) { m_interactiveRange->setYAuto(m_previousSwitchState); From ffd6e613281d2eddd078348fe695c242e3d97f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 29 Mar 2017 15:50:43 +0200 Subject: [PATCH 7/7] [apps/shared] In range, fix bug when clipping range values Change-Id: Ibd6dd8bf5668aaabc9f47c781a606b41cb64e6db --- apps/regression/go_to_parameter_controller.h | 2 +- apps/shared/curve_view_cursor.h | 2 +- apps/shared/go_to_parameter_controller.h | 2 +- apps/shared/interactive_curve_view_range.cpp | 84 +++++++++++--------- apps/shared/interactive_curve_view_range.h | 3 + apps/shared/memoized_curve_view_range.cpp | 4 +- 6 files changed, 56 insertions(+), 41 deletions(-) diff --git a/apps/regression/go_to_parameter_controller.h b/apps/regression/go_to_parameter_controller.h index 4b57e2bc6..42138f06b 100644 --- a/apps/regression/go_to_parameter_controller.h +++ b/apps/regression/go_to_parameter_controller.h @@ -18,7 +18,7 @@ public: bool textFieldDidFinishEditing(TextField * textField, const char * text) override; void viewWillAppear() override; private: - constexpr static float k_maxDisplayableFloat = 1E7f; + constexpr static float k_maxDisplayableFloat = 1E8f; HighlightCell * reusableParameterCell(int index, int type) override; int reusableParameterCellCount(int type) override; float previousParameterAtIndex(int index) override; diff --git a/apps/shared/curve_view_cursor.h b/apps/shared/curve_view_cursor.h index a6666533a..edc154e87 100644 --- a/apps/shared/curve_view_cursor.h +++ b/apps/shared/curve_view_cursor.h @@ -9,8 +9,8 @@ public: float x(); float y(); void moveTo(float x, float y); - static float clipped(float f); private: + static float clipped(float f); constexpr static float k_maxFloat = 1E+8f; float m_x; float m_y; diff --git a/apps/shared/go_to_parameter_controller.h b/apps/shared/go_to_parameter_controller.h index 755b5d548..209e85390 100644 --- a/apps/shared/go_to_parameter_controller.h +++ b/apps/shared/go_to_parameter_controller.h @@ -17,7 +17,7 @@ public: void setFunction(Function * function); int numberOfRows() override; private: - constexpr static float k_maxDisplayableFloat = 1E7f; + constexpr static float k_maxDisplayableFloat = 1E8f; void buttonAction() override; HighlightCell * reusableParameterCell(int index, int type) override; int reusableParameterCellCount(int type) override; diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 6b0f8b1f8..d1573ad58 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -34,10 +34,11 @@ bool InteractiveCurveViewRange::yAuto() { void InteractiveCurveViewRange::setXMin(float xMin) { float newXMin = xMin; - if (m_xMax - m_xMin < k_minFloat) { + MemoizedCurveViewRange::setXMin(clipped(newXMin, false)); + if (m_xMax - newXMin < k_minFloat) { newXMin = m_xMax - k_minFloat; + MemoizedCurveViewRange::setXMin(clipped(newXMin, false)); } - MemoizedCurveViewRange::setXMin(CurveViewCursor::clipped(newXMin)); if (m_delegate) { m_delegate->didChangeRange(this); } @@ -45,10 +46,11 @@ void InteractiveCurveViewRange::setXMin(float xMin) { void InteractiveCurveViewRange::setXMax(float xMax) { float newXMax = xMax; - if (m_xMax - m_xMin < k_minFloat) { + MemoizedCurveViewRange::setXMax(clipped(newXMax, true)); + if (newXMax - m_xMin < k_minFloat) { newXMax = m_xMin + k_minFloat; + MemoizedCurveViewRange::setXMax(clipped(newXMax, true)); } - MemoizedCurveViewRange::setXMax(CurveViewCursor::clipped(newXMax)); if (m_delegate) { m_delegate->didChangeRange(this); } @@ -56,18 +58,20 @@ void InteractiveCurveViewRange::setXMax(float xMax) { void InteractiveCurveViewRange::setYMin(float yMin) { float newYMin = yMin; - if (m_yMax - m_yMin < k_minFloat) { + MemoizedCurveViewRange::setYMin(clipped(newYMin, false)); + if (m_yMax - newYMin < k_minFloat) { newYMin = m_yMax - k_minFloat; + MemoizedCurveViewRange::setYMin(clipped(newYMin, false)); } - MemoizedCurveViewRange::setYMin(CurveViewCursor::clipped(newYMin)); } void InteractiveCurveViewRange::setYMax(float yMax) { float newYMax = yMax; - if (m_yMax - m_yMin < k_minFloat) { + MemoizedCurveViewRange::setYMax(clipped(newYMax, true)); + if (newYMax - m_yMin < k_minFloat) { newYMax = m_yMin + k_minFloat; + MemoizedCurveViewRange::setYMax(clipped(newYMax, true)); } - MemoizedCurveViewRange::setYMax(CurveViewCursor::clipped(newYMax)); } void InteractiveCurveViewRange::setYAuto(bool yAuto) { @@ -85,24 +89,24 @@ void InteractiveCurveViewRange::zoom(float ratio) { if (2.0f*ratio*fabsf(xMax-xMin) < k_minFloat || 2.0f*ratio*fabsf(yMax-yMin) < k_minFloat) { return; } - m_xMin = CurveViewCursor::clipped((xMax+xMin)/2.0f - ratio*fabsf(xMax-xMin)); - m_xMax = CurveViewCursor::clipped((xMax+xMin)/2.0f + ratio*fabsf(xMax-xMin)); + m_xMin = clipped((xMax+xMin)/2.0f - ratio*fabsf(xMax-xMin), false); + m_xMax = clipped((xMax+xMin)/2.0f + ratio*fabsf(xMax-xMin), true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); m_yAuto = false; - m_yMin = CurveViewCursor::clipped((yMax+yMin)/2.0f - ratio*fabsf(yMax-yMin)); - m_yMax = CurveViewCursor::clipped((yMax+yMin)/2.0f + ratio*fabsf(yMax-yMin)); + m_yMin = clipped((yMax+yMin)/2.0f - ratio*fabsf(yMax-yMin), false); + m_yMax = clipped((yMax+yMin)/2.0f + ratio*fabsf(yMax-yMin), true); m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); } void InteractiveCurveViewRange::panWithVector(float x, float y) { m_yAuto = false; - if (CurveViewCursor::clipped(m_xMin + x) != m_xMin + x || CurveViewCursor::clipped(m_xMax + x) != m_xMax + x || CurveViewCursor::clipped(m_yMin + y) != m_yMin + y || CurveViewCursor::clipped(m_yMax + y) != m_yMax + y) { + if (clipped(m_xMin + x, false) != m_xMin + x || clipped(m_xMax + x, true) != m_xMax + x || clipped(m_yMin + y, false) != m_yMin + y || clipped(m_yMax + y, true) != m_yMax + y) { return; } - m_xMin = CurveViewCursor::clipped(m_xMin + x); - m_xMax = CurveViewCursor::clipped(m_xMax + x); - m_yMin = CurveViewCursor::clipped(m_yMin + y); - m_yMax = CurveViewCursor::clipped(m_yMax + y); + m_xMin = clipped(m_xMin + x, false); + m_xMax = clipped(m_xMax + x, true); + m_yMin = clipped(m_yMin + y, false); + m_yMax = clipped(m_yMax + y, true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); } @@ -110,8 +114,8 @@ void InteractiveCurveViewRange::panWithVector(float x, float y) { void InteractiveCurveViewRange::roundAbscissa() { float xMin = m_xMin; float xMax = m_xMax; - m_xMin = roundf((xMin+xMax)/2) - (float)Ion::Display::Width/2.0f; - m_xMax = roundf((xMin+xMax)/2) + (float)Ion::Display::Width/2.0f-1.0f; + m_xMin = clipped(roundf((xMin+xMax)/2) - (float)Ion::Display::Width/2.0f, false); + m_xMax = clipped(roundf((xMin+xMax)/2) + (float)Ion::Display::Width/2.0f-1.0f, true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); if (m_delegate) { m_delegate->didChangeRange(this); @@ -123,12 +127,12 @@ void InteractiveCurveViewRange::normalize() { float xMax = m_xMax; float yMin = m_yMin; float yMax = m_yMax; - m_xMin = (xMin+xMax)/2 - 5.3f; - m_xMax = (xMin+xMax)/2 + 5.3f; + m_xMin = clipped((xMin+xMax)/2 - 5.3f, false); + m_xMax = clipped((xMin+xMax)/2 + 5.3f, true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); m_yAuto = false; - m_yMin = (yMin+yMax)/2 - 3.1f; - m_yMax = (yMin+yMax)/2 + 3.1f; + m_yMin = clipped((yMin+yMax)/2 - 3.1f, false); + m_yMax = clipped((yMin+yMax)/2 + 3.1f, true); m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); } @@ -156,15 +160,15 @@ void InteractiveCurveViewRange::setDefault() { void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) { if (axis == Axis::X) { float range = m_xMax - m_xMin; - m_xMin = CurveViewCursor::clipped(position - range/2.0f); - m_xMax = CurveViewCursor::clipped(position + range/2.0f); + m_xMin = clipped(position - range/2.0f, false); + m_xMax = clipped(position + range/2.0f, true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); } else { m_yAuto = false; float range = m_yMax - m_yMin; - m_yMin = CurveViewCursor::clipped(position - range/2.0f); - m_yMax = CurveViewCursor::clipped(position + range/2.0f); - m_yGridUnit = CurveViewCursor::clipped(computeGridUnit(Axis::Y, m_yMin, m_yMax)); + m_yMin = clipped(position - range/2.0f, false); + m_yMax = clipped(position + range/2.0f, true); + m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); } } @@ -172,29 +176,37 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to float xRange = m_xMax - m_xMin; float yRange = m_yMax - m_yMin; if (x < m_xMin + leftMarginRation*xRange && !isinf(x) && !isnan(x)) { - m_xMin = CurveViewCursor::clipped(x - leftMarginRation*xRange); - m_xMax = m_xMin + xRange; + m_xMin = clipped(x - leftMarginRation*xRange, false); + m_xMax = clipped(m_xMin + xRange, true); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); m_yAuto = false; } if (x > m_xMax - rightMarginRatio*xRange && !isinf(x) && !isnan(x)) { - m_xMax = CurveViewCursor::clipped(x + rightMarginRatio*xRange); - m_xMin = m_xMax - xRange; + m_xMax = clipped(x + rightMarginRatio*xRange, true); + m_xMin = clipped(m_xMax - xRange, false); m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); m_yAuto = false; } if (y < m_yMin + bottomMarginRation*yRange && !isinf(y) && !isnan(y)) { - m_yMin = CurveViewCursor::clipped(y - bottomMarginRation*yRange); - m_yMax = m_yMin + yRange; + m_yMin = clipped(y - bottomMarginRation*yRange, false); + m_yMax = clipped(m_yMin + yRange, true); m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); m_yAuto = false; } if (y > m_yMax - topMarginRatio*yRange && !isinf(y) && !isnan(y)) { - m_yMax = CurveViewCursor::clipped(y + topMarginRatio*yRange); - m_yMin = m_yMax - yRange; + m_yMax = clipped(y + topMarginRatio*yRange, true); + m_yMin = clipped(m_yMax - yRange, false); m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); m_yAuto = false; } } +float InteractiveCurveViewRange::clipped(float x, bool isMax) { + float max = isMax ? k_upperMaxFloat : k_lowerMaxFloat; + float min = isMax ? -k_lowerMaxFloat : -k_upperMaxFloat; + float clippedX = x > max ? max : x; + clippedX = clippedX < min ? min : clippedX; + return clippedX; +} + } diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 6272f402c..f4b39a141 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -36,6 +36,9 @@ protected: InteractiveCurveViewRangeDelegate * m_delegate; private: constexpr static float k_minFloat = 1E-8f; + constexpr static float k_upperMaxFloat = 1E+8f; + constexpr static float k_lowerMaxFloat = 9E+7f; + static float clipped(float f, bool isMax); CurveViewCursor * m_cursor; }; diff --git a/apps/shared/memoized_curve_view_range.cpp b/apps/shared/memoized_curve_view_range.cpp index da5c93e4a..29ce57344 100644 --- a/apps/shared/memoized_curve_view_range.cpp +++ b/apps/shared/memoized_curve_view_range.cpp @@ -42,7 +42,7 @@ float MemoizedCurveViewRange::yGridUnit() { void MemoizedCurveViewRange::setXMin(float xMin) { m_xMin = xMin; if (m_xMin >= m_xMax) { - m_xMax = xMin + 1.0f; + m_xMax = xMin + powf(10.0f, floorf(log10f(fabsf(xMin)))-1.0f); } m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); } @@ -50,7 +50,7 @@ void MemoizedCurveViewRange::setXMin(float xMin) { void MemoizedCurveViewRange::setXMax(float xMax) { m_xMax = xMax; if (m_xMin >= m_xMax) { - m_xMin = xMax - 1.0f; + m_xMin = xMax - powf(10.0f, floorf(log10f(fabsf(xMax)))-1.0f); } m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); }