mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
profile: shorten DiveCartesianAxis::posAtValue(qreal value)
This function was just needlessly complicated. For one, it considered the position of the line, but that is never changed since redoing the positioning code. Moreover, it does in lots of lines what is a very idiomatic operation: a one-dimensional affine transformation. Let's shorten the actual calculation to two lines. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8ff949650a
commit
afb0978460
1 changed files with 7 additions and 19 deletions
|
@ -365,27 +365,15 @@ qreal DiveCartesianAxis::valueAt(const QPointF &p) const
|
|||
qreal DiveCartesianAxis::posAtValue(qreal value) const
|
||||
{
|
||||
QLineF m = line();
|
||||
QPointF p = pos();
|
||||
|
||||
double size = max - min;
|
||||
// unused for now:
|
||||
// double distanceFromOrigin = value - min;
|
||||
double percent = IS_FP_SAME(min, max) ? 0.0 : (value - min) / size;
|
||||
|
||||
|
||||
double realSize = position == Position::Bottom ?
|
||||
m.x2() - m.x1() :
|
||||
m.y2() - m.y1();
|
||||
|
||||
// Inverted axis, just invert the percentage.
|
||||
double screenFrom = position == Position::Bottom ? m.x1() : m.y1();
|
||||
double screenTo = position == Position::Bottom ? m.x2() : m.y2();
|
||||
if (IS_FP_SAME(min, max))
|
||||
return (screenFrom + screenTo) / 2.0;
|
||||
if ((position == Position::Bottom) == inverted)
|
||||
percent = 1.0 - percent;
|
||||
|
||||
double retValue = realSize * percent;
|
||||
double adjusted = position == Position::Bottom ?
|
||||
retValue + m.x1() + p.x() :
|
||||
retValue + m.y1() + p.y();
|
||||
return adjusted;
|
||||
std::swap(screenFrom, screenTo);
|
||||
return (value - min) / (max - min) *
|
||||
(screenTo - screenFrom) + screenFrom;
|
||||
}
|
||||
|
||||
static std::pair<double, double> getLineFromTo(const QLineF &l, bool horizontal)
|
||||
|
|
Loading…
Reference in a new issue