Here are two other options:
#include <limits>
QVector<QPoint> array;
Q_ASSERT(array.size() > 0);
int xMin = std::numeric_limits<int>::max(); // everything is <= this
int xMax = std::numeric_limits<int>::min(); // everything is >= this
int yMin = std::numeric_limits<int>::max();
int yMax = std::numeric_limits<int>::min();
xMin = qMin(xMin, p.x());
xMax = qMax(xMax, p.x());
yMin = qMin(yMin, p.y());
yMax = qMax(yMax, p.y());
}
qDebug() << xMin << xMax << yMin << yMax;
#include <limits>
QVector<QPoint> array;
array << QPoint(-1, 5) << QPoint(-2, 0) << QPoint(0, 3);
Q_ASSERT(array.size() > 0);
int xMin = std::numeric_limits<int>::max(); // everything is <= this
int xMax = std::numeric_limits<int>::min(); // everything is >= this
int yMin = std::numeric_limits<int>::max();
int yMax = std::numeric_limits<int>::min();
foreach (QPoint p, array) {
xMin = qMin(xMin, p.x());
xMax = qMax(xMax, p.x());
yMin = qMin(yMin, p.y());
yMax = qMax(yMax, p.y());
}
qDebug() << xMin << xMax << yMin << yMax;
To copy to clipboard, switch view to plain text mode
or
QRect brect
= poly.
boundingRect();
qDebug() << brect.left() << brect.right() << brect.top() << brect.bottom(); // note the smallest y is the top of the box not the bottom
QPolygon poly(array);
QRect brect = poly.boundingRect();
qDebug() << brect.left() << brect.right() << brect.top() << brect.bottom(); // note the smallest y is the top of the box not the bottom
To copy to clipboard, switch view to plain text mode
Bookmarks