diff options
author | Robert C. Helling <helling@atdotde.de> | 2019-08-08 11:30:41 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-08-08 08:56:44 -0700 |
commit | f1fc3283557d0cdb7338c5ab99fa0d8385c5dfa2 (patch) | |
tree | 3b012eb6c6527fd2e5f381330d3b6fc3ead3eea6 /profile-widget/divecartesianaxis.cpp | |
parent | a8b1c86139fe03c838e54a0940f878d5da6d57ae (diff) | |
download | subsurface-f1fc3283557d0cdb7338c5ab99fa0d8385c5dfa2.tar.gz |
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 <helling@atdotde.de>
Diffstat (limited to 'profile-widget/divecartesianaxis.cpp')
-rw-r--r-- | profile-widget/divecartesianaxis.cpp | 13 |
1 files 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) |