mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: rewrite ProfileScene::pointOnProfile()
This function was used to check wether a screen-point is located on the profile. Bizzarely, this was done by transforming into local coordinates and checking min/max value. Simply check the screen coordinates directly. Moreover, make the function return whether the point is inside the region, not outside the region, to make logic more straight forward. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7df0adef64
commit
210660d057
6 changed files with 23 additions and 14 deletions
|
@ -375,18 +375,31 @@ qreal DiveCartesianAxis::posAtValue(qreal value) const
|
|||
return adjusted;
|
||||
}
|
||||
|
||||
static std::pair<double, double> getLineFromTo(const QLineF &l, bool horizontal)
|
||||
{
|
||||
if (horizontal)
|
||||
return std::make_pair(l.x1(), l.x2());
|
||||
else
|
||||
return std::make_pair(l.y1(), l.y2());
|
||||
}
|
||||
|
||||
double DiveCartesianAxis::screenPosition(double pos) const
|
||||
{
|
||||
QLineF m = line();
|
||||
double from = position == Position::Bottom ? m.x1() : m.y1();
|
||||
double to = position == Position::Bottom ? m.x2() : m.y2();
|
||||
|
||||
if ((position == Position::Bottom) == inverted)
|
||||
pos = 1.0 - pos;
|
||||
|
||||
auto [from, to] = getLineFromTo(line(), position == Position::Bottom);
|
||||
return (to - from) * pos + from;
|
||||
}
|
||||
|
||||
double DiveCartesianAxis::pointInRange(double pos) const
|
||||
{
|
||||
auto [from, to] = getLineFromTo(line(), position == Position::Bottom);
|
||||
if (from > to)
|
||||
std::swap(from, to);
|
||||
return pos >= from && pos <= to;
|
||||
}
|
||||
|
||||
double DiveCartesianAxis::maximum() const
|
||||
{
|
||||
return max;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue