From 18381fd33470761319c84fdee471873a2d7357e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 4 Dec 2018 10:12:01 +0100 Subject: [PATCH] [apps] Add FLT_EPSILON in float comparisons in interactive_curve_vw_rge This fixes the removal of yAuto when displaying the function f(x)=cos(x) --- apps/shared/interactive_curve_view_range.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index adb83b87e..dd15f78a9 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -1,6 +1,7 @@ #include "interactive_curve_view_range.h" #include #include +#include #include #include #include @@ -174,24 +175,24 @@ void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) { void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation) { float xRange = m_xMax - m_xMin; float yRange = m_yMax - m_yMin; - if (x < m_xMin + leftMarginRation*xRange && !std::isinf(x) && !std::isnan(x)) { + if (x < m_xMin + leftMarginRation*xRange - FLT_EPSILON && !std::isinf(x) && !std::isnan(x)) { float newXMin = clipped(x - leftMarginRation*xRange, false); m_xMax = clipped(newXMin + xRange, true); MemoizedCurveViewRange::setXMin(newXMin); m_yAuto = false; } - if (x > m_xMax - rightMarginRatio*xRange && !std::isinf(x) && !std::isnan(x)) { + if (x > m_xMax - rightMarginRatio*xRange + FLT_EPSILON && !std::isinf(x) && !std::isnan(x)) { m_xMax = clipped(x + rightMarginRatio*xRange, true); MemoizedCurveViewRange::setXMin(clipped(m_xMax - xRange, false)); m_yAuto = false; } - if (y < m_yMin + bottomMarginRation*yRange && !std::isinf(y) && !std::isnan(y)) { + if (y < m_yMin + bottomMarginRation*yRange - FLT_EPSILON && !std::isinf(y) && !std::isnan(y)) { float newYMin = clipped(y - bottomMarginRation*yRange, false); m_yMax = clipped(newYMin + yRange, true); MemoizedCurveViewRange::setYMin(newYMin); m_yAuto = false; } - if (y > m_yMax - topMarginRatio*yRange && !std::isinf(y) && !std::isnan(y)) { + if (y > m_yMax - topMarginRatio*yRange + FLT_EPSILON && !std::isinf(y) && !std::isnan(y)) { m_yMax = clipped(y + topMarginRatio*yRange, true); MemoizedCurveViewRange::setYMin(clipped(m_yMax - yRange, false)); m_yAuto = false;