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>
This commit is contained in:
Robert C. Helling 2019-08-08 11:30:41 +02:00 committed by Dirk Hohndel
parent a8b1c86139
commit f1fc328355

View file

@ -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)