1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2016-04-01 19:20:55 +02:00
parent d3908f1561
commit 9fa031ca4d

View File

@ -282,6 +282,9 @@ static qreal yAtX(const QPainterPath &path, qreal x)
int high = path.elementCount() - 1; int high = path.elementCount() - 1;
int mid = 0; int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
while (low <= high) { while (low <= high) {
mid = low + ((high - low) / 2); mid = low + ((high - low) / 2);
const QPainterPath::Element &e = path.elementAt(mid); const QPainterPath::Element &e = path.elementAt(mid);
@ -294,15 +297,12 @@ static qreal yAtX(const QPainterPath &path, qreal x)
} }
QLineF l; QLineF l;
if (path.elementAt(mid).x < x) { if (path.elementAt(mid).x < x)
Q_ASSERT(mid >= 0 && mid+1 < path.elementCount());
l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y, l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y,
path.elementAt(mid+1).x, path.elementAt(mid+1).y); path.elementAt(mid+1).x, path.elementAt(mid+1).y);
} else { else
Q_ASSERT(mid-1 >= 0 && mid < path.elementCount());
l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y, l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y,
path.elementAt(mid).x, path.elementAt(mid).y); path.elementAt(mid).x, path.elementAt(mid).y);
}
return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y(); return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
} }
@ -311,7 +311,7 @@ void GraphView::updateSliderInfo()
{ {
_sliderInfo->setVisible(_graphs.size() == 1); _sliderInfo->setVisible(_graphs.size() == 1);
if (_graphs.size() > 1) if (_graphs.size() != 1)
return; return;
const QPainterPath &path = _graphs.at(0)->path(); const QPainterPath &path = _graphs.at(0)->path();