summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-06-02 01:15:46 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-06-02 01:18:40 (GMT)
commitd106350fc8357efa1f400947f79e75625aec34da (patch)
tree8c981f6e8018af8ce87183300a6d6e5c005b483f /src/gui/math3d
parent111c9143dc34be69c503a90bf9d6f6e5f5f67041 (diff)
downloadQt-d106350fc8357efa1f400947f79e75625aec34da.zip
Qt-d106350fc8357efa1f400947f79e75625aec34da.tar.gz
Qt-d106350fc8357efa1f400947f79e75625aec34da.tar.bz2
Improve perf of QMatrix4x4::mapRect(const QRectF &) by 3x for scaled/translated matrix
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp33
-rw-r--r--src/gui/math3d/qmatrix4x4.h13
2 files changed, 33 insertions, 13 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index a8dabf3..976315f 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -1431,6 +1431,39 @@ QTransform QMatrix4x4::toTransform() const
\sa map()
*/
+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]);
+ }
+ }
+
+ QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
+ QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
+
+ qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+
+ return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
+}
+
/*!
\fn float *QMatrix4x4::data()
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 2b485c1..f946da8 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -914,19 +914,6 @@ inline QRect QMatrix4x4::mapRect(const QRect& rect) const
return QRect(QPoint(xmin, ymin), QPoint(xmax, ymax));
}
-inline QRectF QMatrix4x4::mapRect(const QRectF& rect) const
-{
- QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
- QPointF bl = map(rect.bottomLeft()); QPointF br = map(rect.bottomRight());
-
- qreal xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
- qreal xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
- qreal ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
- qreal ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
-
- return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
-}
-
inline float *QMatrix4x4::data()
{
// We have to assume that the caller will modify the matrix elements,