diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-09-04 20:54:02 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-08-04 10:46:11 +0000 |
commit | 2079081dcf6968690d0c8c50c46531c31989ffd4 (patch) | |
tree | 9cd0b610e8f8869d3e067f8c9bbd26df3fbb08e1 /src/gui/painting/qpolygon.cpp | |
parent | ecec9edd5a5ab4157e860268b56dc77dbc49d748 (diff) |
QPolygon: prepare boundingRect() to be extracted as an algorithm
That basically involves reformatting the loop to use iterators.
Change-Id: Ie8e80e7f32b386eae50ab4520c62219e18d2a1bd
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui/painting/qpolygon.cpp')
-rw-r--r-- | src/gui/painting/qpolygon.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index d2203595c8..126b752811 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -443,14 +443,15 @@ void QPolygon::putPoints(int index, int nPoints, const QPolygon & from, int from QRect QPolygon::boundingRect() const { - if (isEmpty()) - return QRect(0, 0, 0, 0); const QPoint *pd = constData(); + const QPoint *pe = pd + size(); + if (pd == pe) + return QRect(0, 0, 0, 0); int minx, maxx, miny, maxy; minx = maxx = pd->x(); miny = maxy = pd->y(); ++pd; - for (int i = 1; i < size(); ++i) { + for (; pd != pe; ++pd) { if (pd->x() < minx) minx = pd->x(); else if (pd->x() > maxx) @@ -459,7 +460,6 @@ QRect QPolygon::boundingRect() const miny = pd->y(); else if (pd->y() > maxy) maxy = pd->y(); - ++pd; } return QRect(QPoint(minx,miny), QPoint(maxx,maxy)); } @@ -657,14 +657,15 @@ QPolygonF QPolygonF::translated(const QPointF &offset) const QRectF QPolygonF::boundingRect() const { - if (isEmpty()) - return QRectF(0, 0, 0, 0); const QPointF *pd = constData(); + const QPointF *pe = pd + size(); + if (pd == pe) + return QRectF(0, 0, 0, 0); qreal minx, maxx, miny, maxy; minx = maxx = pd->x(); miny = maxy = pd->y(); ++pd; - for (int i = 1; i < size(); ++i) { + while (pd != pe) { if (pd->x() < minx) minx = pd->x(); else if (pd->x() > maxx) |