summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qmatrix4x4.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d/qmatrix4x4.cpp')
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp72
1 files changed, 50 insertions, 22 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index fd4f69a..8ef4da3 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -1488,8 +1488,6 @@ QTransform QMatrix4x4::toTransform() const
#endif
/*!
- \fn QRect QMatrix4x4::mapRect(const QRect& rect) const
-
Maps \a rect by multiplying this matrix by the corners
of \a rect and then forming a new rectangle from the results.
The returned rectangle will be an ordinary 2D rectangle
@@ -1497,10 +1495,43 @@ QTransform QMatrix4x4::toTransform() const
\sa map()
*/
+QRect QMatrix4x4::mapRect(const QRect& rect) const
+{
+ if (flagBits == (Translation | Scale) || flagBits == Scale) {
+ qreal x = rect.x() * m[0][0] + m[3][0];
+ qreal y = rect.y() * m[1][1] + m[3][1];
+ qreal w = rect.width() * m[0][0];
+ qreal h = rect.height() * m[1][1];
+ if (w < 0) {
+ w = -w;
+ x -= w;
+ }
+ if (h < 0) {
+ h = -h;
+ y -= h;
+ }
+ return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
+ } else if (flagBits == Translation) {
+ return QRect(qRound(rect.x() + m[3][0]),
+ qRound(rect.y() + m[3][1]),
+ rect.width(), rect.height());
+ }
-/*!
- \fn QRectF QMatrix4x4::mapRect(const QRectF& rect) const
+ QPoint tl = map(rect.topLeft());
+ QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));
+ QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));
+ QPoint br = map(QPoint(rect.x() + rect.width(),
+ rect.y() + rect.height()));
+ int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+
+ return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
+}
+
+/*!
Maps \a rect by multiplying this matrix by the corners
of \a rect and then forming a new rectangle from the results.
The returned rectangle will be an ordinary 2D rectangle
@@ -1510,24 +1541,22 @@ QTransform QMatrix4x4::toTransform() const
*/
QRectF QMatrix4x4::mapRect(const QRectF& rect) const
{
- if (flagBits & Translation) {
- if (flagBits & Scale) {
- qreal x = rect.x() * m[0][0] + m[3][0];
- qreal y = rect.y() * m[1][1] + m[3][1];
- qreal w = rect.width() * m[0][0];
- qreal h = rect.height() * m[1][1];
- if (w < 0) {
- w = -w;
- x -= w;
- }
- if (h < 0) {
- h = -h;
- y -= h;
- }
- return QRectF(x, y, w, h);
- } else {
- return rect.translated(m[3][0], m[3][1]);
+ if (flagBits == (Translation | Scale) || flagBits == Scale) {
+ qreal x = rect.x() * m[0][0] + m[3][0];
+ qreal y = rect.y() * m[1][1] + m[3][1];
+ qreal w = rect.width() * m[0][0];
+ qreal h = rect.height() * m[1][1];
+ if (w < 0) {
+ w = -w;
+ x -= w;
+ }
+ if (h < 0) {
+ h = -h;
+ y -= h;
}
+ return QRectF(x, y, w, h);
+ } else if (flagBits == Translation) {
+ return rect.translated(m[3][0], m[3][1]);
}
QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
@@ -1541,7 +1570,6 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
}
-
/*!
\fn float *QMatrix4x4::data()