From f1fc3283557d0cdb7338c5ab99fa0d8385c5dfa2 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Thu, 8 Aug 2019 11:30:41 +0200 Subject: Fix math in valueAt DiveCartesianAxis::valueAt() is supposed to be the inverse of posAtValue(). This fixes the math such that inverted orientations are correctly taken care of. Signed-off-by: Robert C. Helling --- profile-widget/divecartesianaxis.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 72d1081a6..ec959d03e 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -284,14 +284,19 @@ void DiveCartesianAxis::setTickInterval(double i) qreal DiveCartesianAxis::valueAt(const QPointF &p) const { + double fraction; QLineF m = line(); QPointF relativePosition = p; relativePosition -= pos(); // normalize p based on the axis' offset on screen - double retValue = (orientation == LeftToRight || orientation == RightToLeft) ? - max * (relativePosition.x() - m.x1()) / (m.x2() - m.x1()) : - max * (relativePosition.y() - m.y1()) / (m.y2() - m.y1()); - return retValue; + if (orientation == LeftToRight || orientation == RightToLeft) + fraction = (relativePosition.x() - m.x1()) / (m.x2() - m.x1()); + else + fraction = (relativePosition.y() - m.y1()) / (m.y2() - m.y1()); + + if (orientation == RightToLeft || orientation == BottomToTop) + fraction = 1 - fraction; + return fraction * (max - min) + min; } qreal DiveCartesianAxis::posAtValue(qreal value) -- cgit v1.2.3-70-g09d2