summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorThomas Zander <t.zander@nokia.com>2010-04-12 12:10:28 (GMT)
committerThomas Zander <t.zander@nokia.com>2010-04-16 12:04:40 (GMT)
commit113b65dce51f37566b58fd730b206537820889e6 (patch)
tree422a44b3eb3b8e5bf1d64050b583222af49e1996 /src/gui
parent9827cd78256c24e8311400198864aaadfff4e7ab (diff)
downloadQt-113b65dce51f37566b58fd730b206537820889e6.zip
Qt-113b65dce51f37566b58fd730b206537820889e6.tar.gz
Qt-113b65dce51f37566b58fd730b206537820889e6.tar.bz2
Make debugging floating point mistakes much easier.
Its a common mistake that a floating point error, like divide by zero, is not detected and just propagated till it breaks in curious ways elsewhere. Like QBezier hitting an infinite loop due to operating on NaN floating points. Adding detection of this in a debug build of Qt is sure to help a lot of these issues be detected much faster and so Qt helps people write code even faster. Reviewed-By: Gunnar Sletta
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qtransform.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp
index 988d678..80b7520 100644
--- a/src/gui/painting/qtransform.cpp
+++ b/src/gui/painting/qtransform.cpp
@@ -47,6 +47,7 @@
#include "qpainterpath.h"
#include "qvariant.h"
#include <qmath.h>
+#include <qnumeric.h>
#include <private/qbezier_p.h>
@@ -410,6 +411,12 @@ QTransform &QTransform::translate(qreal dx, qreal dy)
{
if (dx == 0 && dy == 0)
return *this;
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(dx) | qIsNaN(dy)) {
+ qWarning() << "QTransform::translate with NaN called";
+ return *this;
+ }
+#endif
switch(inline_type()) {
case TxNone:
@@ -447,6 +454,12 @@ QTransform &QTransform::translate(qreal dx, qreal dy)
*/
QTransform QTransform::fromTranslate(qreal dx, qreal dy)
{
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(dx) | qIsNaN(dy)) {
+ qWarning() << "QTransform::fromTranslate with NaN called";
+ return QTransform();
+}
+#endif
QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true);
if (dx == 0 && dy == 0)
transform.m_type = TxNone;
@@ -466,6 +479,12 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
{
if (sx == 1 && sy == 1)
return *this;
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(sx) | qIsNaN(sy)) {
+ qWarning() << "QTransform::scale with NaN called";
+ return *this;
+ }
+#endif
switch(inline_type()) {
case TxNone:
@@ -501,6 +520,12 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
*/
QTransform QTransform::fromScale(qreal sx, qreal sy)
{
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(sx) | qIsNaN(sy)) {
+ qWarning() << "QTransform::fromScale with NaN called";
+ return QTransform();
+}
+#endif
QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true);
if (sx == 1. && sy == 1.)
transform.m_type = TxNone;
@@ -520,6 +545,12 @@ QTransform & QTransform::shear(qreal sh, qreal sv)
{
if (sh == 0 && sv == 0)
return *this;
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(sh) | qIsNaN(sv)) {
+ qWarning() << "QTransform::shear with NaN called";
+ return *this;
+ }
+#endif
switch(inline_type()) {
case TxNone:
@@ -575,6 +606,12 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
{
if (a == 0)
return *this;
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(a)) {
+ qWarning() << "QTransform::rotate with NaN called";
+ return *this;
+ }
+#endif
qreal sina = 0;
qreal cosa = 0;
@@ -660,6 +697,12 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
*/
QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
{
+#ifndef QT_NO_DEBUG
+ if (qIsNaN(a)) {
+ qWarning() << "QTransform::rotateRadians with NaN called";
+ return *this;
+ }
+#endif
qreal sina = qSin(a);
qreal cosa = qCos(a);