src/gui/painting/qtransform.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
    45 #include "qmatrix.h"
    45 #include "qmatrix.h"
    46 #include "qregion.h"
    46 #include "qregion.h"
    47 #include "qpainterpath.h"
    47 #include "qpainterpath.h"
    48 #include "qvariant.h"
    48 #include "qvariant.h"
    49 #include <qmath.h>
    49 #include <qmath.h>
       
    50 #include <qnumeric.h>
    50 
    51 
    51 #include <private/qbezier_p.h>
    52 #include <private/qbezier_p.h>
    52 
    53 
    53 QT_BEGIN_NAMESPACE
    54 QT_BEGIN_NAMESPACE
    54 
    55 
   408 */
   409 */
   409 QTransform &QTransform::translate(qreal dx, qreal dy)
   410 QTransform &QTransform::translate(qreal dx, qreal dy)
   410 {
   411 {
   411     if (dx == 0 && dy == 0)
   412     if (dx == 0 && dy == 0)
   412         return *this;
   413         return *this;
       
   414 #ifndef QT_NO_DEBUG
       
   415     if (qIsNaN(dx) | qIsNaN(dy)) {
       
   416         qWarning() << "QTransform::translate with NaN called";
       
   417         return *this;
       
   418     }
       
   419 #endif
   413 
   420 
   414     switch(inline_type()) {
   421     switch(inline_type()) {
   415     case TxNone:
   422     case TxNone:
   416         affine._dx = dx;
   423         affine._dx = dx;
   417         affine._dy = dy;
   424         affine._dy = dy;
   445 
   452 
   446     \since 4.5
   453     \since 4.5
   447 */
   454 */
   448 QTransform QTransform::fromTranslate(qreal dx, qreal dy)
   455 QTransform QTransform::fromTranslate(qreal dx, qreal dy)
   449 {
   456 {
       
   457 #ifndef QT_NO_DEBUG
       
   458     if (qIsNaN(dx) | qIsNaN(dy)) {
       
   459         qWarning() << "QTransform::fromTranslate with NaN called";
       
   460         return QTransform();
       
   461 }
       
   462 #endif
   450     QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true);
   463     QTransform transform(1, 0, 0, 0, 1, 0, dx, dy, 1, true);
   451     if (dx == 0 && dy == 0)
   464     if (dx == 0 && dy == 0)
   452         transform.m_type = TxNone;
   465         transform.m_type = TxNone;
   453     else
   466     else
   454         transform.m_type = TxTranslate;
   467         transform.m_type = TxTranslate;
   464 */
   477 */
   465 QTransform & QTransform::scale(qreal sx, qreal sy)
   478 QTransform & QTransform::scale(qreal sx, qreal sy)
   466 {
   479 {
   467     if (sx == 1 && sy == 1)
   480     if (sx == 1 && sy == 1)
   468         return *this;
   481         return *this;
       
   482 #ifndef QT_NO_DEBUG
       
   483     if (qIsNaN(sx) | qIsNaN(sy)) {
       
   484         qWarning() << "QTransform::scale with NaN called";
       
   485         return *this;
       
   486     }
       
   487 #endif
   469 
   488 
   470     switch(inline_type()) {
   489     switch(inline_type()) {
   471     case TxNone:
   490     case TxNone:
   472     case TxTranslate:
   491     case TxTranslate:
   473         affine._m11 = sx;
   492         affine._m11 = sx;
   499 
   518 
   500     \since 4.5
   519     \since 4.5
   501 */
   520 */
   502 QTransform QTransform::fromScale(qreal sx, qreal sy)
   521 QTransform QTransform::fromScale(qreal sx, qreal sy)
   503 {
   522 {
       
   523 #ifndef QT_NO_DEBUG
       
   524     if (qIsNaN(sx) | qIsNaN(sy)) {
       
   525         qWarning() << "QTransform::fromScale with NaN called";
       
   526         return QTransform();
       
   527 }
       
   528 #endif
   504     QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true);
   529     QTransform transform(sx, 0, 0, 0, sy, 0, 0, 0, 1, true);
   505     if (sx == 1. && sy == 1.)
   530     if (sx == 1. && sy == 1.)
   506         transform.m_type = TxNone;
   531         transform.m_type = TxNone;
   507     else
   532     else
   508         transform.m_type = TxScale;
   533         transform.m_type = TxScale;
   518 */
   543 */
   519 QTransform & QTransform::shear(qreal sh, qreal sv)
   544 QTransform & QTransform::shear(qreal sh, qreal sv)
   520 {
   545 {
   521     if (sh == 0 && sv == 0)
   546     if (sh == 0 && sv == 0)
   522         return *this;
   547         return *this;
       
   548 #ifndef QT_NO_DEBUG
       
   549     if (qIsNaN(sh) | qIsNaN(sv)) {
       
   550         qWarning() << "QTransform::shear with NaN called";
       
   551         return *this;
       
   552     }
       
   553 #endif
   523 
   554 
   524     switch(inline_type()) {
   555     switch(inline_type()) {
   525     case TxNone:
   556     case TxNone:
   526     case TxTranslate:
   557     case TxTranslate:
   527         affine._m12 = sv;
   558         affine._m12 = sv;
   573 */
   604 */
   574 QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
   605 QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
   575 {
   606 {
   576     if (a == 0)
   607     if (a == 0)
   577         return *this;
   608         return *this;
       
   609 #ifndef QT_NO_DEBUG
       
   610     if (qIsNaN(a)) {
       
   611         qWarning() << "QTransform::rotate with NaN called";
       
   612         return *this;
       
   613     }
       
   614 #endif
   578 
   615 
   579     qreal sina = 0;
   616     qreal sina = 0;
   580     qreal cosa = 0;
   617     qreal cosa = 0;
   581     if (a == 90. || a == -270.)
   618     if (a == 90. || a == -270.)
   582         sina = 1.;
   619         sina = 1.;
   658 
   695 
   659     \sa setMatrix()
   696     \sa setMatrix()
   660 */
   697 */
   661 QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
   698 QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
   662 {
   699 {
       
   700 #ifndef QT_NO_DEBUG
       
   701     if (qIsNaN(a)) {
       
   702         qWarning() << "QTransform::rotateRadians with NaN called";
       
   703         return *this;
       
   704     }
       
   705 #endif
   663     qreal sina = qSin(a);
   706     qreal sina = qSin(a);
   664     qreal cosa = qCos(a);
   707     qreal cosa = qCos(a);
   665 
   708 
   666     if (axis == Qt::ZAxis) {
   709     if (axis == Qt::ZAxis) {
   667         switch(inline_type()) {
   710         switch(inline_type()) {
  1035 #endif // QT_NO_DATASTREAM
  1078 #endif // QT_NO_DATASTREAM
  1036 
  1079 
  1037 #ifndef QT_NO_DEBUG_STREAM
  1080 #ifndef QT_NO_DEBUG_STREAM
  1038 QDebug operator<<(QDebug dbg, const QTransform &m)
  1081 QDebug operator<<(QDebug dbg, const QTransform &m)
  1039 {
  1082 {
  1040     dbg.nospace() << "QTransform("
  1083     static const char *typeStr[] =
  1041                   << "11="  << m.m11()
  1084     {
       
  1085         "TxNone",
       
  1086         "TxTranslate",
       
  1087         "TxScale",
       
  1088         "TxRotate",
       
  1089         "TxShear",
       
  1090         "TxProject"
       
  1091     };
       
  1092 
       
  1093     dbg.nospace() << "QTransform(type=" << typeStr[m.type()] << ','
       
  1094                   << " 11=" << m.m11()
  1042                   << " 12=" << m.m12()
  1095                   << " 12=" << m.m12()
  1043                   << " 13=" << m.m13()
  1096                   << " 13=" << m.m13()
  1044                   << " 21=" << m.m21()
  1097                   << " 21=" << m.m21()
  1045                   << " 22=" << m.m22()
  1098                   << " 22=" << m.m22()
  1046                   << " 23=" << m.m23()
  1099                   << " 23=" << m.m23()
  1047                   << " 31=" << m.m31()
  1100                   << " 31=" << m.m31()
  1048                   << " 32=" << m.m32()
  1101                   << " 32=" << m.m32()
  1049                   << " 33=" << m.m33()
  1102                   << " 33=" << m.m33()
  1050                   << ')';
  1103                   << ')';
       
  1104 
  1051     return dbg.space();
  1105     return dbg.space();
  1052 }
  1106 }
  1053 #endif
  1107 #endif
  1054 
  1108 
  1055 /*!
  1109 /*!
  1489     if (needsLineTo)
  1543     if (needsLineTo)
  1490         path.lineTo(hb.toPoint());
  1544         path.lineTo(hb.toPoint());
  1491 
  1545 
  1492     return true;
  1546     return true;
  1493 }
  1547 }
       
  1548 Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale);
  1494 
  1549 
  1495 static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo)
  1550 static inline bool cubicTo_clipped(QPainterPath &path, const QTransform &transform, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d, bool needsMoveTo)
  1496 {
  1551 {
  1497     // Convert projective xformed curves to line
  1552     // Convert projective xformed curves to line
  1498     // segments so they can be transformed more accurately
  1553     // segments so they can be transformed more accurately
  1499     QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon();
  1554 
       
  1555     qreal scale;
       
  1556     qt_scaleForTransform(transform, &scale);
       
  1557 
       
  1558     qreal curveThreshold = scale == 0 ? qreal(0.25) : (qreal(0.25) / scale);
       
  1559 
       
  1560     QPolygonF segment = QBezier::fromPoints(a, b, c, d).toPolygon(curveThreshold);
  1500 
  1561 
  1501     for (int i = 0; i < segment.size() - 1; ++i)
  1562     for (int i = 0; i < segment.size() - 1; ++i)
  1502         if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo))
  1563         if (lineTo_clipped(path, transform, segment.at(i), segment.at(i+1), needsMoveTo))
  1503             needsMoveTo = false;
  1564             needsMoveTo = false;
  1504 
  1565