From 9fa031ca4da5785de5eb6ea28e694a398c7726d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Fri, 1 Apr 2016 19:20:55 +0200 Subject: [PATCH] Code cleanup --- src/graphview.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphview.cpp b/src/graphview.cpp index a400c612..1d5d6c8f 100644 --- a/src/graphview.cpp +++ b/src/graphview.cpp @@ -282,6 +282,9 @@ static qreal yAtX(const QPainterPath &path, qreal x) int high = path.elementCount() - 1; int mid = 0; + Q_ASSERT(high > low); + Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x); + while (low <= high) { mid = low + ((high - low) / 2); const QPainterPath::Element &e = path.elementAt(mid); @@ -294,15 +297,12 @@ static qreal yAtX(const QPainterPath &path, qreal x) } QLineF l; - if (path.elementAt(mid).x < x) { - Q_ASSERT(mid >= 0 && mid+1 < path.elementCount()); + if (path.elementAt(mid).x < x) l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y, path.elementAt(mid+1).x, path.elementAt(mid+1).y); - } else { - Q_ASSERT(mid-1 >= 0 && mid < path.elementCount()); + else l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y, path.elementAt(mid).x, path.elementAt(mid).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); - if (_graphs.size() > 1) + if (_graphs.size() != 1) return; const QPainterPath &path = _graphs.at(0)->path();