From 921853c7443060d21e18909ba806a859f8af86a5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 5 Oct 2014 20:37:09 +0200 Subject: mapping was set to nonsense when exceeded spline bounds --- qfunctionconfigurator/functionconfig.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'qfunctionconfigurator') diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp index 7c4aaaab..99b6d871 100644 --- a/qfunctionconfigurator/functionconfig.cpp +++ b/qfunctionconfigurator/functionconfig.cpp @@ -14,8 +14,9 @@ #include #include #include -#include #include +#include +#include void Map::setTrackingActive(bool blnActive) { @@ -48,18 +49,14 @@ bool Map::getLastPoint(QPointF& point ) { float Map::getValueInternal(int x) { float sign = x < 0 ? -1 : 1; - x = x < 0 ? -x : x; + x = fabs(x); float ret; int sz = data.size(); - if (sz == 0) - ret = 0; - else if (x < 0) - ret = 0; - else if (x < sz && x >= 0) - ret = data[x]; - else - ret = data[sz - 1]; - return ret * sign; + if (sz == 0) + ret = 0; + else + ret = std::max(std::min(x, sz-1), 0); + return ret * sign; } static __inline QPointF ensureInBounds(QList points, int i) { -- cgit v1.2.3