mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:33:24 +00:00
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:
parent
a8b1c86139
commit
f1fc328355
1 changed files with 9 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue