Replace the QMatrix field of QTransform with qreal[3][3]

Remove temporarily the reference returned by QTransform::toAffine()
since we don't keep the QMatrix object internally anymore.
This is done in order to compile the rest of the code.
The follow-up patch is going to remove that method completely.

Task-number: QTBUG-81628
Change-Id: If7140eedb7582d81ac8da529017cf792174e86ab
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Jarek Kobus 2020-02-03 17:08:57 +01:00
parent 1c571e5fe7
commit e14e5e104d
6 changed files with 336 additions and 391 deletions

View File

@ -90,7 +90,7 @@ public:
void setStyle(Qt::BrushStyle); void setStyle(Qt::BrushStyle);
#if QT_DEPRECATED_SINCE(5, 15) #if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_X("Use transform()") inline const QMatrix &matrix() const; QT_DEPRECATED_X("Use transform()") inline QMatrix matrix() const;
QT_DEPRECATED_X("Use setTransform()") void setMatrix(const QMatrix &mat); QT_DEPRECATED_X("Use setTransform()") void setMatrix(const QMatrix &mat);
#endif // QT_DEPRECATED_SINCE(5, 15) #endif // QT_DEPRECATED_SINCE(5, 15)
@ -161,7 +161,7 @@ inline Qt::BrushStyle QBrush::style() const { return d->style; }
inline const QColor &QBrush::color() const { return d->color; } inline const QColor &QBrush::color() const { return d->color; }
#if QT_DEPRECATED_SINCE(5, 15) #if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_X("Use transform()") QT_DEPRECATED_X("Use transform()")
inline const QMatrix &QBrush::matrix() const { return d->transform.toAffine(); } inline QMatrix QBrush::matrix() const { return d->transform.toAffine(); }
#endif // QT_DEPRECATED_SINCE(5, 15) #endif // QT_DEPRECATED_SINCE(5, 15)
inline QTransform QBrush::transform() const { return d->transform; } inline QTransform QBrush::transform() const { return d->transform; }
inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; } inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }

View File

@ -2958,7 +2958,7 @@ void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine)
{Coordinate System} {Coordinate System}
*/ */
const QMatrix &QPainter::worldMatrix() const QMatrix QPainter::worldMatrix() const
{ {
Q_D(const QPainter); Q_D(const QPainter);
if (!d->engine) { if (!d->engine) {
@ -2989,7 +2989,7 @@ void QPainter::setMatrix(const QMatrix &matrix, bool combine)
\sa worldTransform() \sa worldTransform()
*/ */
const QMatrix &QPainter::matrix() const QMatrix QPainter::matrix() const
{ {
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_DEPRECATED
@ -3035,7 +3035,7 @@ QMatrix QPainter::combinedMatrix() const
\sa worldMatrix(), QPaintEngine::hasFeature(), \sa worldMatrix(), QPaintEngine::hasFeature(),
*/ */
const QMatrix &QPainter::deviceMatrix() const QMatrix QPainter::deviceMatrix() const
{ {
Q_D(const QPainter); Q_D(const QPainter);
if (!d->engine) { if (!d->engine) {

View File

@ -240,9 +240,9 @@ public:
QT_DEPRECATED_X("Use setTransform() instead") QT_DEPRECATED_X("Use setTransform() instead")
void setMatrix(const QMatrix &matrix, bool combine = false); void setMatrix(const QMatrix &matrix, bool combine = false);
QT_DEPRECATED_X("Use transform() instead") QT_DEPRECATED_X("Use transform() instead")
const QMatrix &matrix() const; QMatrix matrix() const;
QT_DEPRECATED_X("Use deviceTransform() instead") QT_DEPRECATED_X("Use deviceTransform() instead")
const QMatrix &deviceMatrix() const; QMatrix deviceMatrix() const;
QT_DEPRECATED_X("Use resetTransform() instead") QT_DEPRECATED_X("Use resetTransform() instead")
void resetMatrix(); void resetMatrix();
#endif #endif
@ -256,7 +256,7 @@ public:
QT_DEPRECATED_X("Use setWorldTransform() instead") QT_DEPRECATED_X("Use setWorldTransform() instead")
void setWorldMatrix(const QMatrix &matrix, bool combine = false); void setWorldMatrix(const QMatrix &matrix, bool combine = false);
QT_DEPRECATED_X("Use worldTransform() instead") QT_DEPRECATED_X("Use worldTransform() instead")
const QMatrix &worldMatrix() const; QMatrix worldMatrix() const;
QT_DEPRECATED_X("Use combinedTransform() instead") QT_DEPRECATED_X("Use combinedTransform() instead")
QMatrix combinedMatrix() const; QMatrix combinedMatrix() const;
QT_DEPRECATED_X("Use setWorldMatrixEnabled() instead") QT_DEPRECATED_X("Use setWorldMatrixEnabled() instead")

View File

@ -76,20 +76,20 @@ static void nanWarning(const char *func)
ny = FY_; \ ny = FY_; \
break; \ break; \
case TxTranslate: \ case TxTranslate: \
nx = FX_ + affine._dx; \ nx = FX_ + m_matrix[2][0]; \
ny = FY_ + affine._dy; \ ny = FY_ + m_matrix[2][1]; \
break; \ break; \
case TxScale: \ case TxScale: \
nx = affine._m11 * FX_ + affine._dx; \ nx = m_matrix[0][0] * FX_ + m_matrix[2][0]; \
ny = affine._m22 * FY_ + affine._dy; \ ny = m_matrix[1][1] * FY_ + m_matrix[2][1]; \
break; \ break; \
case TxRotate: \ case TxRotate: \
case TxShear: \ case TxShear: \
case TxProject: \ case TxProject: \
nx = affine._m11 * FX_ + affine._m21 * FY_ + affine._dx; \ nx = m_matrix[0][0] * FX_ + m_matrix[1][0] * FY_ + m_matrix[2][0]; \
ny = affine._m12 * FX_ + affine._m22 * FY_ + affine._dy; \ ny = m_matrix[0][1] * FX_ + m_matrix[1][1] * FY_ + m_matrix[2][1]; \
if (t == TxProject) { \ if (t == TxProject) { \
qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); \ qreal w = (m_matrix[0][2] * FX_ + m_matrix[1][2] * FY_ + m_matrix[2][2]); \
if (w < qreal(Q_NEAR_CLIP)) w = qreal(Q_NEAR_CLIP); \ if (w < qreal(Q_NEAR_CLIP)) w = qreal(Q_NEAR_CLIP); \
w = 1./w; \ w = 1./w; \
nx *= w; \ nx *= w; \
@ -261,8 +261,7 @@ static void nanWarning(const char *func)
\sa reset() \sa reset()
*/ */
QTransform::QTransform() QTransform::QTransform()
: affine(true) : m_matrix{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }
, m_13(0), m_23(0), m_33(1)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxNone) , m_dirty(TxNone)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -282,8 +281,7 @@ QTransform::QTransform()
QTransform::QTransform(qreal h11, qreal h12, qreal h13, QTransform::QTransform(qreal h11, qreal h12, qreal h13,
qreal h21, qreal h22, qreal h23, qreal h21, qreal h22, qreal h23,
qreal h31, qreal h32, qreal h33) qreal h31, qreal h32, qreal h33)
: affine(h11, h12, h21, h22, h31, h32, true) : m_matrix{ {h11, h12, h13}, {h21, h22, h23}, {h31, h32, h33} }
, m_13(h13), m_23(h23), m_33(h33)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxProject) , m_dirty(TxProject)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -301,8 +299,7 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h13,
*/ */
QTransform::QTransform(qreal h11, qreal h12, qreal h21, QTransform::QTransform(qreal h11, qreal h12, qreal h21,
qreal h22, qreal dx, qreal dy) qreal h22, qreal dx, qreal dy)
: affine(h11, h12, h21, h22, dx, dy, true) : m_matrix{ {h11, h12, 0}, {h21, h22, 0}, {dx, dy, 1} }
, m_13(0), m_23(0), m_33(1)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxShear) , m_dirty(TxShear)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -321,8 +318,7 @@ QTransform::QTransform(qreal h11, qreal h12, qreal h21,
and 1 respectively. and 1 respectively.
*/ */
QTransform::QTransform(const QMatrix &mtx) QTransform::QTransform(const QMatrix &mtx)
: affine(mtx._m11, mtx._m12, mtx._m21, mtx._m22, mtx._dx, mtx._dy, true), : m_matrix{ {mtx._m11, mtx._m12, 0}, {mtx._m21, mtx._m22, 0}, {mtx._dx, mtx._dy, 1} }
m_13(0), m_23(0), m_33(1)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxShear) , m_dirty(TxShear)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -340,15 +336,15 @@ QTransform QTransform::adjoint() const
qreal h11, h12, h13, qreal h11, h12, h13,
h21, h22, h23, h21, h22, h23,
h31, h32, h33; h31, h32, h33;
h11 = affine._m22*m_33 - m_23*affine._dy; h11 = m_matrix[1][1] * m_matrix[2][2] - m_matrix[1][2] * m_matrix[2][1];
h21 = m_23*affine._dx - affine._m21*m_33; h21 = m_matrix[1][2] * m_matrix[2][0] - m_matrix[1][0] * m_matrix[2][2];
h31 = affine._m21*affine._dy - affine._m22*affine._dx; h31 = m_matrix[1][0] * m_matrix[2][1] - m_matrix[1][1] * m_matrix[2][0];
h12 = m_13*affine._dy - affine._m12*m_33; h12 = m_matrix[0][2] * m_matrix[2][1] - m_matrix[0][1] * m_matrix[2][2];
h22 = affine._m11*m_33 - m_13*affine._dx; h22 = m_matrix[0][0] * m_matrix[2][2] - m_matrix[0][2] * m_matrix[2][0];
h32 = affine._m12*affine._dx - affine._m11*affine._dy; h32 = m_matrix[0][1] * m_matrix[2][0] - m_matrix[0][0] * m_matrix[2][1];
h13 = affine._m12*m_23 - m_13*affine._m22; h13 = m_matrix[0][1] * m_matrix[1][2] - m_matrix[0][2] * m_matrix[1][1];
h23 = m_13*affine._m21 - affine._m11*m_23; h23 = m_matrix[0][2] * m_matrix[1][0] - m_matrix[0][0] * m_matrix[1][2];
h33 = affine._m11*affine._m22 - affine._m12*affine._m21; h33 = m_matrix[0][0] * m_matrix[1][1] - m_matrix[0][1] * m_matrix[1][0];
return QTransform(h11, h12, h13, return QTransform(h11, h12, h13,
h21, h22, h23, h21, h22, h23,
@ -360,9 +356,9 @@ QTransform QTransform::adjoint() const
*/ */
QTransform QTransform::transposed() const QTransform QTransform::transposed() const
{ {
QTransform t(affine._m11, affine._m21, affine._dx, QTransform t(m_matrix[0][0], m_matrix[1][0], m_matrix[2][0],
affine._m12, affine._m22, affine._dy, m_matrix[0][1], m_matrix[1][1], m_matrix[2][1],
m_13, m_23, m_33, true); m_matrix[0][2], m_matrix[1][2], m_matrix[2][2], true);
return t; return t;
} }
@ -385,23 +381,23 @@ QTransform QTransform::inverted(bool *invertible) const
case TxNone: case TxNone:
break; break;
case TxTranslate: case TxTranslate:
invert.affine._dx = -affine._dx; invert.m_matrix[2][0] = -m_matrix[2][0];
invert.affine._dy = -affine._dy; invert.m_matrix[2][1] = -m_matrix[2][1];
break; break;
case TxScale: case TxScale:
inv = !qFuzzyIsNull(affine._m11); inv = !qFuzzyIsNull(m_matrix[0][0]);
inv &= !qFuzzyIsNull(affine._m22); inv &= !qFuzzyIsNull(m_matrix[1][1]);
if (inv) { if (inv) {
invert.affine._m11 = 1. / affine._m11; invert.m_matrix[0][0] = 1. / m_matrix[0][0];
invert.affine._m22 = 1. / affine._m22; invert.m_matrix[1][1] = 1. / m_matrix[1][1];
invert.affine._dx = -affine._dx * invert.affine._m11; invert.m_matrix[2][0] = -m_matrix[2][0] * invert.m_matrix[0][0];
invert.affine._dy = -affine._dy * invert.affine._m22; invert.m_matrix[2][1] = -m_matrix[2][1] * invert.m_matrix[1][1];
} }
break; break;
case TxRotate: // case TxRotate:
case TxShear: // case TxShear:
invert.affine = affine.inverted(&inv); // invert.affine = affine.inverted(&inv);
break; // break;
default: default:
// general case // general case
qreal det = determinant(); qreal det = determinant();
@ -442,24 +438,24 @@ QTransform &QTransform::translate(qreal dx, qreal dy)
switch(inline_type()) { switch(inline_type()) {
case TxNone: case TxNone:
affine._dx = dx; m_matrix[2][0] = dx;
affine._dy = dy; m_matrix[2][1] = dy;
break; break;
case TxTranslate: case TxTranslate:
affine._dx += dx; m_matrix[2][0] += dx;
affine._dy += dy; m_matrix[2][1] += dy;
break; break;
case TxScale: case TxScale:
affine._dx += dx*affine._m11; m_matrix[2][0] += dx * m_matrix[0][0];
affine._dy += dy*affine._m22; m_matrix[2][1] += dy * m_matrix[1][1];
break; break;
case TxProject: case TxProject:
m_33 += dx*m_13 + dy*m_23; m_matrix[2][2] += dx * m_matrix[0][2] + dy * m_matrix[1][2];
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxShear: case TxShear:
case TxRotate: case TxRotate:
affine._dx += dx*affine._m11 + dy*affine._m21; m_matrix[2][0] += dx * m_matrix[0][0] + dy * m_matrix[1][0];
affine._dy += dy*affine._m22 + dx*affine._m12; m_matrix[2][1] += dy * m_matrix[1][1] + dx * m_matrix[0][1];
break; break;
} }
if (m_dirty < TxTranslate) if (m_dirty < TxTranslate)
@ -511,21 +507,21 @@ QTransform & QTransform::scale(qreal sx, qreal sy)
switch(inline_type()) { switch(inline_type()) {
case TxNone: case TxNone:
case TxTranslate: case TxTranslate:
affine._m11 = sx; m_matrix[0][0] = sx;
affine._m22 = sy; m_matrix[1][1] = sy;
break; break;
case TxProject: case TxProject:
m_13 *= sx; m_matrix[0][2] *= sx;
m_23 *= sy; m_matrix[1][2] *= sy;
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxRotate: case TxRotate:
case TxShear: case TxShear:
affine._m12 *= sx; m_matrix[0][1] *= sx;
affine._m21 *= sy; m_matrix[1][0] *= sy;
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxScale: case TxScale:
affine._m11 *= sx; m_matrix[0][0] *= sx;
affine._m22 *= sy; m_matrix[1][1] *= sy;
break; break;
} }
if (m_dirty < TxScale) if (m_dirty < TxScale)
@ -577,28 +573,30 @@ QTransform & QTransform::shear(qreal sh, qreal sv)
switch(inline_type()) { switch(inline_type()) {
case TxNone: case TxNone:
case TxTranslate: case TxTranslate:
affine._m12 = sv; m_matrix[0][1] = sv;
affine._m21 = sh; m_matrix[1][0] = sh;
break; break;
case TxScale: case TxScale:
affine._m12 = sv*affine._m22; m_matrix[0][1] = sv*m_matrix[1][1];
affine._m21 = sh*affine._m11; m_matrix[1][0] = sh*m_matrix[0][0];
break; break;
case TxProject: { case TxProject: {
qreal tm13 = sv*m_23; qreal tm13 = sv * m_matrix[1][2];
qreal tm23 = sh*m_13; qreal tm23 = sh * m_matrix[0][2];
m_13 += tm13; m_matrix[0][2] += tm13;
m_23 += tm23; m_matrix[1][2] += tm23;
} }
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxRotate: case TxRotate:
case TxShear: { case TxShear: {
qreal tm11 = sv*affine._m21; qreal tm11 = sv * m_matrix[1][0];
qreal tm22 = sh*affine._m12; qreal tm22 = sh * m_matrix[0][1];
qreal tm12 = sv*affine._m22; qreal tm12 = sv * m_matrix[1][1];
qreal tm21 = sh*affine._m11; qreal tm21 = sh * m_matrix[0][0];
affine._m11 += tm11; affine._m12 += tm12; m_matrix[0][0] += tm11;
affine._m21 += tm21; affine._m22 += tm22; m_matrix[0][1] += tm12;
m_matrix[1][0] += tm21;
m_matrix[1][1] += tm22;
break; break;
} }
} }
@ -653,35 +651,39 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
switch(inline_type()) { switch(inline_type()) {
case TxNone: case TxNone:
case TxTranslate: case TxTranslate:
affine._m11 = cosa; m_matrix[0][0] = cosa;
affine._m12 = sina; m_matrix[0][1] = sina;
affine._m21 = -sina; m_matrix[1][0] = -sina;
affine._m22 = cosa; m_matrix[1][1] = cosa;
break; break;
case TxScale: { case TxScale: {
qreal tm11 = cosa*affine._m11; qreal tm11 = cosa * m_matrix[0][0];
qreal tm12 = sina*affine._m22; qreal tm12 = sina * m_matrix[1][1];
qreal tm21 = -sina*affine._m11; qreal tm21 = -sina * m_matrix[0][0];
qreal tm22 = cosa*affine._m22; qreal tm22 = cosa * m_matrix[1][1];
affine._m11 = tm11; affine._m12 = tm12; m_matrix[0][0] = tm11;
affine._m21 = tm21; affine._m22 = tm22; m_matrix[0][1] = tm12;
m_matrix[1][0] = tm21;
m_matrix[1][1] = tm22;
break; break;
} }
case TxProject: { case TxProject: {
qreal tm13 = cosa*m_13 + sina*m_23; qreal tm13 = cosa * m_matrix[0][2] + sina * m_matrix[1][2];
qreal tm23 = -sina*m_13 + cosa*m_23; qreal tm23 = -sina * m_matrix[0][2] + cosa * m_matrix[1][2];
m_13 = tm13; m_matrix[0][2] = tm13;
m_23 = tm23; m_matrix[1][2] = tm23;
Q_FALLTHROUGH(); Q_FALLTHROUGH();
} }
case TxRotate: case TxRotate:
case TxShear: { case TxShear: {
qreal tm11 = cosa*affine._m11 + sina*affine._m21; qreal tm11 = cosa * m_matrix[0][0] + sina * m_matrix[1][0];
qreal tm12 = cosa*affine._m12 + sina*affine._m22; qreal tm12 = cosa * m_matrix[0][1] + sina * m_matrix[1][1];
qreal tm21 = -sina*affine._m11 + cosa*affine._m21; qreal tm21 = -sina * m_matrix[0][0] + cosa * m_matrix[1][0];
qreal tm22 = -sina*affine._m12 + cosa*affine._m22; qreal tm22 = -sina * m_matrix[0][1] + cosa * m_matrix[1][1];
affine._m11 = tm11; affine._m12 = tm12; m_matrix[0][0] = tm11;
affine._m21 = tm21; affine._m22 = tm22; m_matrix[0][1] = tm12;
m_matrix[1][0] = tm21;
m_matrix[1][1] = tm22;
break; break;
} }
} }
@ -690,11 +692,11 @@ QTransform & QTransform::rotate(qreal a, Qt::Axis axis)
} else { } else {
QTransform result; QTransform result;
if (axis == Qt::YAxis) { if (axis == Qt::YAxis) {
result.affine._m11 = cosa; result.m_matrix[0][0] = cosa;
result.m_13 = -sina * inv_dist_to_plane; result.m_matrix[0][2] = -sina * inv_dist_to_plane;
} else { } else {
result.affine._m22 = cosa; result.m_matrix[1][1] = cosa;
result.m_23 = -sina * inv_dist_to_plane; result.m_matrix[1][2] = -sina * inv_dist_to_plane;
} }
result.m_type = TxProject; result.m_type = TxProject;
*this = result * *this; *this = result * *this;
@ -732,35 +734,39 @@ QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
switch(inline_type()) { switch(inline_type()) {
case TxNone: case TxNone:
case TxTranslate: case TxTranslate:
affine._m11 = cosa; m_matrix[0][0] = cosa;
affine._m12 = sina; m_matrix[0][1] = sina;
affine._m21 = -sina; m_matrix[1][0] = -sina;
affine._m22 = cosa; m_matrix[1][1] = cosa;
break; break;
case TxScale: { case TxScale: {
qreal tm11 = cosa*affine._m11; qreal tm11 = cosa * m_matrix[0][0];
qreal tm12 = sina*affine._m22; qreal tm12 = sina * m_matrix[1][1];
qreal tm21 = -sina*affine._m11; qreal tm21 = -sina * m_matrix[0][0];
qreal tm22 = cosa*affine._m22; qreal tm22 = cosa * m_matrix[1][1];
affine._m11 = tm11; affine._m12 = tm12; m_matrix[0][0] = tm11;
affine._m21 = tm21; affine._m22 = tm22; m_matrix[0][1] = tm12;
m_matrix[1][0] = tm21;
m_matrix[1][1] = tm22;
break; break;
} }
case TxProject: { case TxProject: {
qreal tm13 = cosa*m_13 + sina*m_23; qreal tm13 = cosa * m_matrix[0][2] + sina * m_matrix[1][2];
qreal tm23 = -sina*m_13 + cosa*m_23; qreal tm23 = -sina * m_matrix[0][2] + cosa * m_matrix[1][2];
m_13 = tm13; m_matrix[0][2] = tm13;
m_23 = tm23; m_matrix[1][2] = tm23;
Q_FALLTHROUGH(); Q_FALLTHROUGH();
} }
case TxRotate: case TxRotate:
case TxShear: { case TxShear: {
qreal tm11 = cosa*affine._m11 + sina*affine._m21; qreal tm11 = cosa * m_matrix[0][0] + sina * m_matrix[1][0];
qreal tm12 = cosa*affine._m12 + sina*affine._m22; qreal tm12 = cosa * m_matrix[0][1] + sina * m_matrix[1][1];
qreal tm21 = -sina*affine._m11 + cosa*affine._m21; qreal tm21 = -sina * m_matrix[0][0] + cosa * m_matrix[1][0];
qreal tm22 = -sina*affine._m12 + cosa*affine._m22; qreal tm22 = -sina * m_matrix[0][1] + cosa * m_matrix[1][1];
affine._m11 = tm11; affine._m12 = tm12; m_matrix[0][0] = tm11;
affine._m21 = tm21; affine._m22 = tm22; m_matrix[0][1] = tm12;
m_matrix[1][0] = tm21;
m_matrix[1][1] = tm22;
break; break;
} }
} }
@ -769,11 +775,11 @@ QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
} else { } else {
QTransform result; QTransform result;
if (axis == Qt::YAxis) { if (axis == Qt::YAxis) {
result.affine._m11 = cosa; result.m_matrix[0][0] = cosa;
result.m_13 = -sina * inv_dist_to_plane; result.m_matrix[0][2] = -sina * inv_dist_to_plane;
} else { } else {
result.affine._m22 = cosa; result.m_matrix[1][1] = cosa;
result.m_23 = -sina * inv_dist_to_plane; result.m_matrix[1][2] = -sina * inv_dist_to_plane;
} }
result.m_type = TxProject; result.m_type = TxProject;
*this = result * *this; *this = result * *this;
@ -788,15 +794,15 @@ QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
*/ */
bool QTransform::operator==(const QTransform &o) const bool QTransform::operator==(const QTransform &o) const
{ {
return affine._m11 == o.affine._m11 && return m_matrix[0][0] == o.m_matrix[0][0] &&
affine._m12 == o.affine._m12 && m_matrix[0][1] == o.m_matrix[0][1] &&
affine._m21 == o.affine._m21 && m_matrix[1][0] == o.m_matrix[1][0] &&
affine._m22 == o.affine._m22 && m_matrix[1][1] == o.m_matrix[1][1] &&
affine._dx == o.affine._dx && m_matrix[2][0] == o.m_matrix[2][0] &&
affine._dy == o.affine._dy && m_matrix[2][1] == o.m_matrix[2][1] &&
m_13 == o.m_13 && m_matrix[0][2] == o.m_matrix[0][2] &&
m_23 == o.m_23 && m_matrix[1][2] == o.m_matrix[1][2] &&
m_33 == o.m_33; m_matrix[2][2] == o.m_matrix[2][2];
} }
/*! /*!
@ -854,56 +860,59 @@ QTransform & QTransform::operator*=(const QTransform &o)
case TxNone: case TxNone:
break; break;
case TxTranslate: case TxTranslate:
affine._dx += o.affine._dx; m_matrix[2][0] += o.m_matrix[2][0];
affine._dy += o.affine._dy; m_matrix[2][1] += o.m_matrix[2][1];
break; break;
case TxScale: case TxScale:
{ {
qreal m11 = affine._m11*o.affine._m11; qreal m11 = m_matrix[0][0] * o.m_matrix[0][0];
qreal m22 = affine._m22*o.affine._m22; qreal m22 = m_matrix[1][1] * o.m_matrix[1][1];
qreal m31 = affine._dx*o.affine._m11 + o.affine._dx; qreal m31 = m_matrix[2][0] * o.m_matrix[0][0] + o.m_matrix[2][0];
qreal m32 = affine._dy*o.affine._m22 + o.affine._dy; qreal m32 = m_matrix[2][1] * o.m_matrix[1][1] + o.m_matrix[2][1];
affine._m11 = m11; m_matrix[0][0] = m11;
affine._m22 = m22; m_matrix[1][1] = m22;
affine._dx = m31; affine._dy = m32; m_matrix[2][0] = m31; m_matrix[2][1] = m32;
break; break;
} }
case TxRotate: case TxRotate:
case TxShear: case TxShear:
{ {
qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21; qreal m11 = m_matrix[0][0] * o.m_matrix[0][0] + m_matrix[0][1] * o.m_matrix[1][0];
qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22; qreal m12 = m_matrix[0][0] * o.m_matrix[0][1] + m_matrix[0][1] * o.m_matrix[1][1];
qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21; qreal m21 = m_matrix[1][0] * o.m_matrix[0][0] + m_matrix[1][1] * o.m_matrix[1][0];
qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22; qreal m22 = m_matrix[1][0] * o.m_matrix[0][1] + m_matrix[1][1] * o.m_matrix[1][1];
qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + o.affine._dx; qreal m31 = m_matrix[2][0] * o.m_matrix[0][0] + m_matrix[2][1] * o.m_matrix[1][0] + o.m_matrix[2][0];
qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + o.affine._dy; qreal m32 = m_matrix[2][0] * o.m_matrix[0][1] + m_matrix[2][1] * o.m_matrix[1][1] + o.m_matrix[2][1];
affine._m11 = m11; affine._m12 = m12; m_matrix[0][0] = m11;
affine._m21 = m21; affine._m22 = m22; m_matrix[0][1] = m12;
affine._dx = m31; affine._dy = m32; m_matrix[1][0] = m21;
m_matrix[1][1] = m22;
m_matrix[2][0] = m31;
m_matrix[2][1] = m32;
break; break;
} }
case TxProject: case TxProject:
{ {
qreal m11 = affine._m11*o.affine._m11 + affine._m12*o.affine._m21 + m_13*o.affine._dx; qreal m11 = m_matrix[0][0] * o.m_matrix[0][0] + m_matrix[0][1] * o.m_matrix[1][0] + m_matrix[0][2] * o.m_matrix[2][0];
qreal m12 = affine._m11*o.affine._m12 + affine._m12*o.affine._m22 + m_13*o.affine._dy; qreal m12 = m_matrix[0][0] * o.m_matrix[0][1] + m_matrix[0][1] * o.m_matrix[1][1] + m_matrix[0][2] * o.m_matrix[2][1];
qreal m13 = affine._m11*o.m_13 + affine._m12*o.m_23 + m_13*o.m_33; qreal m13 = m_matrix[0][0] * o.m_matrix[0][2] + m_matrix[0][1] * o.m_matrix[1][2] + m_matrix[0][2] * o.m_matrix[2][2];
qreal m21 = affine._m21*o.affine._m11 + affine._m22*o.affine._m21 + m_23*o.affine._dx; qreal m21 = m_matrix[1][0] * o.m_matrix[0][0] + m_matrix[1][1] * o.m_matrix[1][0] + m_matrix[1][2] * o.m_matrix[2][0];
qreal m22 = affine._m21*o.affine._m12 + affine._m22*o.affine._m22 + m_23*o.affine._dy; qreal m22 = m_matrix[1][0] * o.m_matrix[0][1] + m_matrix[1][1] * o.m_matrix[1][1] + m_matrix[1][2] * o.m_matrix[2][1];
qreal m23 = affine._m21*o.m_13 + affine._m22*o.m_23 + m_23*o.m_33; qreal m23 = m_matrix[1][0] * o.m_matrix[0][2] + m_matrix[1][1] * o.m_matrix[1][2] + m_matrix[1][2] * o.m_matrix[2][2];
qreal m31 = affine._dx*o.affine._m11 + affine._dy*o.affine._m21 + m_33*o.affine._dx; qreal m31 = m_matrix[2][0] * o.m_matrix[0][0] + m_matrix[2][1] * o.m_matrix[1][0] + m_matrix[2][2] * o.m_matrix[2][0];
qreal m32 = affine._dx*o.affine._m12 + affine._dy*o.affine._m22 + m_33*o.affine._dy; qreal m32 = m_matrix[2][0] * o.m_matrix[0][1] + m_matrix[2][1] * o.m_matrix[1][1] + m_matrix[2][2] * o.m_matrix[2][1];
qreal m33 = affine._dx*o.m_13 + affine._dy*o.m_23 + m_33*o.m_33; qreal m33 = m_matrix[2][0] * o.m_matrix[0][2] + m_matrix[2][1] * o.m_matrix[1][2] + m_matrix[2][2] * o.m_matrix[2][2];
affine._m11 = m11; affine._m12 = m12; m_13 = m13; m_matrix[0][0] = m11; m_matrix[0][1] = m12; m_matrix[0][2] = m13;
affine._m21 = m21; affine._m22 = m22; m_23 = m23; m_matrix[1][0] = m21; m_matrix[1][1] = m22; m_matrix[1][2] = m23;
affine._dx = m31; affine._dy = m32; m_33 = m33; m_matrix[2][0] = m31; m_matrix[2][1] = m32; m_matrix[2][2] = m33;
} }
} }
@ -937,56 +946,57 @@ QTransform QTransform::operator*(const QTransform &m) const
case TxNone: case TxNone:
break; break;
case TxTranslate: case TxTranslate:
t.affine._dx = affine._dx + m.affine._dx; t.m_matrix[2][0] = m_matrix[2][0] + m.m_matrix[2][0];
t.affine._dy += affine._dy + m.affine._dy; t.m_matrix[2][1] = m_matrix[2][1] + m.m_matrix[2][1];
break; break;
case TxScale: case TxScale:
{ {
qreal m11 = affine._m11*m.affine._m11; qreal m11 = m_matrix[0][0] * m.m_matrix[0][0];
qreal m22 = affine._m22*m.affine._m22; qreal m22 = m_matrix[1][1] * m.m_matrix[1][1];
qreal m31 = affine._dx*m.affine._m11 + m.affine._dx; qreal m31 = m_matrix[2][0] * m.m_matrix[0][0] + m.m_matrix[2][0];
qreal m32 = affine._dy*m.affine._m22 + m.affine._dy; qreal m32 = m_matrix[2][1] * m.m_matrix[1][1] + m.m_matrix[2][1];
t.affine._m11 = m11; t.m_matrix[0][0] = m11;
t.affine._m22 = m22; t.m_matrix[1][1] = m22;
t.affine._dx = m31; t.affine._dy = m32; t.m_matrix[2][0] = m31;
t.m_matrix[2][1] = m32;
break; break;
} }
case TxRotate: case TxRotate:
case TxShear: case TxShear:
{ {
qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21; qreal m11 = m_matrix[0][0] * m.m_matrix[0][0] + m_matrix[0][1] * m.m_matrix[1][0];
qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22; qreal m12 = m_matrix[0][0] * m.m_matrix[0][1] + m_matrix[0][1] * m.m_matrix[1][1];
qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21; qreal m21 = m_matrix[1][0] * m.m_matrix[0][0] + m_matrix[1][1] * m.m_matrix[1][0];
qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22; qreal m22 = m_matrix[1][0] * m.m_matrix[0][1] + m_matrix[1][1] * m.m_matrix[1][1];
qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m.affine._dx; qreal m31 = m_matrix[2][0] * m.m_matrix[0][0] + m_matrix[2][1] * m.m_matrix[1][0] + m.m_matrix[2][0];
qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m.affine._dy; qreal m32 = m_matrix[2][0] * m.m_matrix[0][1] + m_matrix[2][1] * m.m_matrix[1][1] + m.m_matrix[2][1];
t.affine._m11 = m11; t.affine._m12 = m12; t.m_matrix[0][0] = m11; t.m_matrix[0][1] = m12;
t.affine._m21 = m21; t.affine._m22 = m22; t.m_matrix[1][0] = m21; t.m_matrix[1][1] = m22;
t.affine._dx = m31; t.affine._dy = m32; t.m_matrix[2][0] = m31; t.m_matrix[2][1] = m32;
break; break;
} }
case TxProject: case TxProject:
{ {
qreal m11 = affine._m11*m.affine._m11 + affine._m12*m.affine._m21 + m_13*m.affine._dx; qreal m11 = m_matrix[0][0] * m.m_matrix[0][0] + m_matrix[0][1] * m.m_matrix[1][0] + m_matrix[0][2] * m.m_matrix[2][0];
qreal m12 = affine._m11*m.affine._m12 + affine._m12*m.affine._m22 + m_13*m.affine._dy; qreal m12 = m_matrix[0][0] * m.m_matrix[0][1] + m_matrix[0][1] * m.m_matrix[1][1] + m_matrix[0][2] * m.m_matrix[2][1];
qreal m13 = affine._m11*m.m_13 + affine._m12*m.m_23 + m_13*m.m_33; qreal m13 = m_matrix[0][0] * m.m_matrix[0][2] + m_matrix[0][1] * m.m_matrix[1][2] + m_matrix[0][2] * m.m_matrix[2][2];
qreal m21 = affine._m21*m.affine._m11 + affine._m22*m.affine._m21 + m_23*m.affine._dx; qreal m21 = m_matrix[1][0] * m.m_matrix[0][0] + m_matrix[1][1] * m.m_matrix[1][0] + m_matrix[1][2] * m.m_matrix[2][0];
qreal m22 = affine._m21*m.affine._m12 + affine._m22*m.affine._m22 + m_23*m.affine._dy; qreal m22 = m_matrix[1][0] * m.m_matrix[0][1] + m_matrix[1][1] * m.m_matrix[1][1] + m_matrix[1][2] * m.m_matrix[2][1];
qreal m23 = affine._m21*m.m_13 + affine._m22*m.m_23 + m_23*m.m_33; qreal m23 = m_matrix[1][0] * m.m_matrix[0][2] + m_matrix[1][1] * m.m_matrix[1][2] + m_matrix[1][2] * m.m_matrix[2][2];
qreal m31 = affine._dx*m.affine._m11 + affine._dy*m.affine._m21 + m_33*m.affine._dx; qreal m31 = m_matrix[2][0] * m.m_matrix[0][0] + m_matrix[2][1] * m.m_matrix[1][0] + m_matrix[2][2] * m.m_matrix[2][0];
qreal m32 = affine._dx*m.affine._m12 + affine._dy*m.affine._m22 + m_33*m.affine._dy; qreal m32 = m_matrix[2][0] * m.m_matrix[0][1] + m_matrix[2][1] * m.m_matrix[1][1] + m_matrix[2][2] * m.m_matrix[2][1];
qreal m33 = affine._dx*m.m_13 + affine._dy*m.m_23 + m_33*m.m_33; qreal m33 = m_matrix[2][0] * m.m_matrix[0][2] + m_matrix[2][1] * m.m_matrix[1][2] + m_matrix[2][2] * m.m_matrix[2][2];
t.affine._m11 = m11; t.affine._m12 = m12; t.m_13 = m13; t.m_matrix[0][0] = m11; t.m_matrix[0][1] = m12; t.m_matrix[0][2] = m13;
t.affine._m21 = m21; t.affine._m22 = m22; t.m_23 = m23; t.m_matrix[1][0] = m21; t.m_matrix[1][1] = m22; t.m_matrix[1][2] = m23;
t.affine._dx = m31; t.affine._dy = m32; t.m_33 = m33; t.m_matrix[2][0] = m31; t.m_matrix[2][1] = m32; t.m_matrix[2][2] = m33;
} }
} }
@ -1034,15 +1044,15 @@ QTransform QTransform::operator*(const QTransform &m) const
*/ */
QTransform & QTransform::operator=(const QTransform &matrix) noexcept QTransform & QTransform::operator=(const QTransform &matrix) noexcept
{ {
affine._m11 = matrix.affine._m11; m_matrix[0][0] = matrix.m_matrix[0][0];
affine._m12 = matrix.affine._m12; m_matrix[0][1] = matrix.m_matrix[0][1];
affine._m21 = matrix.affine._m21; m_matrix[1][0] = matrix.m_matrix[1][0];
affine._m22 = matrix.affine._m22; m_matrix[1][1] = matrix.m_matrix[1][1];
affine._dx = matrix.affine._dx; m_matrix[2][0] = matrix.m_matrix[2][0];
affine._dy = matrix.affine._dy; m_matrix[2][1] = matrix.m_matrix[2][1];
m_13 = matrix.m_13; m_matrix[0][2] = matrix.m_matrix[0][2];
m_23 = matrix.m_23; m_matrix[1][2] = matrix.m_matrix[1][2];
m_33 = matrix.m_33; m_matrix[2][2] = matrix.m_matrix[2][2];
m_type = matrix.m_type; m_type = matrix.m_type;
m_dirty = matrix.m_dirty; m_dirty = matrix.m_dirty;
@ -1060,8 +1070,8 @@ QTransform & QTransform::operator=(const QTransform &matrix) noexcept
*/ */
void QTransform::reset() void QTransform::reset()
{ {
affine._m11 = affine._m22 = m_33 = 1.0; m_matrix[0][0] = m_matrix[1][1] = m_matrix[2][2] = 1.0;
affine._m12 = m_13 = affine._m21 = m_23 = affine._dx = affine._dy = 0; m_matrix[0][1] = m_matrix[0][2] = m_matrix[1][0] = m_matrix[1][2] = m_matrix[2][0] = m_matrix[2][1] = 0;
m_type = TxNone; m_type = TxNone;
m_dirty = TxNone; m_dirty = TxNone;
} }
@ -1179,20 +1189,20 @@ QPoint QTransform::map(const QPoint &p) const
y = fy; y = fy;
break; break;
case TxTranslate: case TxTranslate:
x = fx + affine._dx; x = fx + m_matrix[2][0];
y = fy + affine._dy; y = fy + m_matrix[2][1];
break; break;
case TxScale: case TxScale:
x = affine._m11 * fx + affine._dx; x = m_matrix[0][0] * fx + m_matrix[2][0];
y = affine._m22 * fy + affine._dy; y = m_matrix[1][1] * fy + m_matrix[2][1];
break; break;
case TxRotate: case TxRotate:
case TxShear: case TxShear:
case TxProject: case TxProject:
x = affine._m11 * fx + affine._m21 * fy + affine._dx; x = m_matrix[0][0] * fx + m_matrix[1][0] * fy + m_matrix[2][0];
y = affine._m12 * fx + affine._m22 * fy + affine._dy; y = m_matrix[0][1] * fx + m_matrix[1][1] * fy + m_matrix[2][1];
if (t == TxProject) { if (t == TxProject) {
qreal w = 1./(m_13 * fx + m_23 * fy + m_33); qreal w = 1./(m_matrix[0][2] * fx + m_matrix[1][2] * fy + m_matrix[2][2]);
x *= w; x *= w;
y *= w; y *= w;
} }
@ -1230,20 +1240,20 @@ QPointF QTransform::map(const QPointF &p) const
y = fy; y = fy;
break; break;
case TxTranslate: case TxTranslate:
x = fx + affine._dx; x = fx + m_matrix[2][0];
y = fy + affine._dy; y = fy + m_matrix[2][1];
break; break;
case TxScale: case TxScale:
x = affine._m11 * fx + affine._dx; x = m_matrix[0][0] * fx + m_matrix[2][0];
y = affine._m22 * fy + affine._dy; y = m_matrix[1][1] * fy + m_matrix[2][1];
break; break;
case TxRotate: case TxRotate:
case TxShear: case TxShear:
case TxProject: case TxProject:
x = affine._m11 * fx + affine._m21 * fy + affine._dx; x = m_matrix[0][0] * fx + m_matrix[1][0] * fy + m_matrix[2][0];
y = affine._m12 * fx + affine._m22 * fy + affine._dy; y = m_matrix[0][1] * fx + m_matrix[1][1] * fy + m_matrix[2][1];
if (t == TxProject) { if (t == TxProject) {
qreal w = 1./(m_13 * fx + m_23 * fy + m_33); qreal w = 1./(m_matrix[0][2] * fx + m_matrix[1][2] * fy + m_matrix[2][2]);
x *= w; x *= w;
y *= w; y *= w;
} }
@ -1303,29 +1313,29 @@ QLine QTransform::map(const QLine &l) const
y2 = fy2; y2 = fy2;
break; break;
case TxTranslate: case TxTranslate:
x1 = fx1 + affine._dx; x1 = fx1 + m_matrix[2][0];
y1 = fy1 + affine._dy; y1 = fy1 + m_matrix[2][1];
x2 = fx2 + affine._dx; x2 = fx2 + m_matrix[2][0];
y2 = fy2 + affine._dy; y2 = fy2 + m_matrix[2][1];
break; break;
case TxScale: case TxScale:
x1 = affine._m11 * fx1 + affine._dx; x1 = m_matrix[0][0] * fx1 + m_matrix[2][0];
y1 = affine._m22 * fy1 + affine._dy; y1 = m_matrix[1][1] * fy1 + m_matrix[2][1];
x2 = affine._m11 * fx2 + affine._dx; x2 = m_matrix[0][0] * fx2 + m_matrix[2][0];
y2 = affine._m22 * fy2 + affine._dy; y2 = m_matrix[1][1] * fy2 + m_matrix[2][1];
break; break;
case TxRotate: case TxRotate:
case TxShear: case TxShear:
case TxProject: case TxProject:
x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx; x1 = m_matrix[0][0] * fx1 + m_matrix[1][0] * fy1 + m_matrix[2][0];
y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy; y1 = m_matrix[0][1] * fx1 + m_matrix[1][1] * fy1 + m_matrix[2][1];
x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; x2 = m_matrix[0][0] * fx2 + m_matrix[1][0] * fy2 + m_matrix[2][0];
y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; y2 = m_matrix[0][1] * fx2 + m_matrix[1][1] * fy2 + m_matrix[2][1];
if (t == TxProject) { if (t == TxProject) {
qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); qreal w = 1./(m_matrix[0][2] * fx1 + m_matrix[1][2] * fy1 + m_matrix[2][2]);
x1 *= w; x1 *= w;
y1 *= w; y1 *= w;
w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); w = 1./(m_matrix[0][2] * fx2 + m_matrix[1][2] * fy2 + m_matrix[2][2]);
x2 *= w; x2 *= w;
y2 *= w; y2 *= w;
} }
@ -1362,29 +1372,29 @@ QLineF QTransform::map(const QLineF &l) const
y2 = fy2; y2 = fy2;
break; break;
case TxTranslate: case TxTranslate:
x1 = fx1 + affine._dx; x1 = fx1 + m_matrix[2][0];
y1 = fy1 + affine._dy; y1 = fy1 + m_matrix[2][1];
x2 = fx2 + affine._dx; x2 = fx2 + m_matrix[2][0];
y2 = fy2 + affine._dy; y2 = fy2 + m_matrix[2][1];
break; break;
case TxScale: case TxScale:
x1 = affine._m11 * fx1 + affine._dx; x1 = m_matrix[0][0] * fx1 + m_matrix[2][0];
y1 = affine._m22 * fy1 + affine._dy; y1 = m_matrix[1][1] * fy1 + m_matrix[2][1];
x2 = affine._m11 * fx2 + affine._dx; x2 = m_matrix[0][0] * fx2 + m_matrix[2][0];
y2 = affine._m22 * fy2 + affine._dy; y2 = m_matrix[1][1] * fy2 + m_matrix[2][1];
break; break;
case TxRotate: case TxRotate:
case TxShear: case TxShear:
case TxProject: case TxProject:
x1 = affine._m11 * fx1 + affine._m21 * fy1 + affine._dx; x1 = m_matrix[0][0] * fx1 + m_matrix[1][0] * fy1 + m_matrix[2][0];
y1 = affine._m12 * fx1 + affine._m22 * fy1 + affine._dy; y1 = m_matrix[0][1] * fx1 + m_matrix[1][1] * fy1 + m_matrix[2][1];
x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx; x2 = m_matrix[0][0] * fx2 + m_matrix[1][0] * fy2 + m_matrix[2][0];
y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy; y2 = m_matrix[0][1] * fx2 + m_matrix[1][1] * fy2 + m_matrix[2][1];
if (t == TxProject) { if (t == TxProject) {
qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33); qreal w = 1./(m_matrix[0][2] * fx1 + m_matrix[1][2] * fy1 + m_matrix[2][2]);
x1 *= w; x1 *= w;
y1 *= w; y1 *= w;
w = 1./(m_13 * fx2 + m_23 * fy2 + m_33); w = 1./(m_matrix[0][2] * fx2 + m_matrix[1][2] * fy2 + m_matrix[2][2]);
x2 *= w; x2 *= w;
y2 *= w; y2 *= w;
} }
@ -1445,7 +1455,7 @@ QPolygonF QTransform::map(const QPolygonF &a) const
{ {
TransformationType t = inline_type(); TransformationType t = inline_type();
if (t <= TxTranslate) if (t <= TxTranslate)
return a.translated(affine._dx, affine._dy); return a.translated(m_matrix[2][0], m_matrix[2][1]);
if (t >= QTransform::TxProject) if (t >= QTransform::TxProject)
return mapProjective(*this, a); return mapProjective(*this, a);
@ -1475,7 +1485,7 @@ QPolygon QTransform::map(const QPolygon &a) const
{ {
TransformationType t = inline_type(); TransformationType t = inline_type();
if (t <= TxTranslate) if (t <= TxTranslate)
return a.translated(qRound(affine._dx), qRound(affine._dy)); return a.translated(qRound(m_matrix[2][0]), qRound(m_matrix[2][1]));
if (t >= QTransform::TxProject) if (t >= QTransform::TxProject)
return mapProjective(*this, QPolygonF(a)).toPolygon(); return mapProjective(*this, QPolygonF(a)).toPolygon();
@ -1524,7 +1534,7 @@ QRegion QTransform::map(const QRegion &r) const
if (t == TxTranslate) { if (t == TxTranslate) {
QRegion copy(r); QRegion copy(r);
copy.translate(qRound(affine._dx), qRound(affine._dy)); copy.translate(qRound(m_matrix[2][0]), qRound(m_matrix[2][1]));
return copy; return copy;
} }
@ -1703,7 +1713,7 @@ QPainterPath QTransform::map(const QPainterPath &path) const
QPainterPath copy = path; QPainterPath copy = path;
if (t == TxTranslate) { if (t == TxTranslate) {
copy.translate(affine._dx, affine._dy); copy.translate(m_matrix[2][0], m_matrix[2][1]);
} else { } else {
copy.detach(); copy.detach();
// Full xform // Full xform
@ -1743,10 +1753,10 @@ QPolygon QTransform::mapToPolygon(const QRect &rect) const
QPolygon a(4); QPolygon a(4);
qreal x[4] = { 0, 0, 0, 0 }, y[4] = { 0, 0, 0, 0 }; qreal x[4] = { 0, 0, 0, 0 }, y[4] = { 0, 0, 0, 0 };
if (t <= TxScale) { if (t <= TxScale) {
x[0] = affine._m11*rect.x() + affine._dx; x[0] = m_matrix[0][0]*rect.x() + m_matrix[2][0];
y[0] = affine._m22*rect.y() + affine._dy; y[0] = m_matrix[1][1]*rect.y() + m_matrix[2][1];
qreal w = affine._m11*rect.width(); qreal w = m_matrix[0][0]*rect.width();
qreal h = affine._m22*rect.height(); qreal h = m_matrix[1][1]*rect.height();
if (w < 0) { if (w < 0) {
w = -w; w = -w;
x[0] -= w; x[0] -= w;
@ -1903,9 +1913,9 @@ void QTransform::setMatrix(qreal m11, qreal m12, qreal m13,
qreal m21, qreal m22, qreal m23, qreal m21, qreal m22, qreal m23,
qreal m31, qreal m32, qreal m33) qreal m31, qreal m32, qreal m33)
{ {
affine._m11 = m11; affine._m12 = m12; m_13 = m13; m_matrix[0][0] = m11; m_matrix[0][1] = m12; m_matrix[0][2] = m13;
affine._m21 = m21; affine._m22 = m22; m_23 = m23; m_matrix[1][0] = m21; m_matrix[1][1] = m22; m_matrix[1][2] = m23;
affine._dx = m31; affine._dy = m32; m_33 = m33; m_matrix[2][0] = m31; m_matrix[2][1] = m32; m_matrix[2][2] = m33;
m_type = TxNone; m_type = TxNone;
m_dirty = TxProject; m_dirty = TxProject;
} }
@ -1922,13 +1932,13 @@ QRect QTransform::mapRect(const QRect &rect) const
{ {
TransformationType t = inline_type(); TransformationType t = inline_type();
if (t <= TxTranslate) if (t <= TxTranslate)
return rect.translated(qRound(affine._dx), qRound(affine._dy)); return rect.translated(qRound(m_matrix[2][0]), qRound(m_matrix[2][1]));
if (t <= TxScale) { if (t <= TxScale) {
int x = qRound(affine._m11*rect.x() + affine._dx); int x = qRound(m_matrix[0][0] * rect.x() + m_matrix[2][0]);
int y = qRound(affine._m22*rect.y() + affine._dy); int y = qRound(m_matrix[1][1] * rect.y() + m_matrix[2][1]);
int w = qRound(affine._m11*rect.width()); int w = qRound(m_matrix[0][0] * rect.width());
int h = qRound(affine._m22*rect.height()); int h = qRound(m_matrix[1][1] * rect.height());
if (w < 0) { if (w < 0) {
w = -w; w = -w;
x -= w; x -= w;
@ -1992,13 +2002,13 @@ QRectF QTransform::mapRect(const QRectF &rect) const
{ {
TransformationType t = inline_type(); TransformationType t = inline_type();
if (t <= TxTranslate) if (t <= TxTranslate)
return rect.translated(affine._dx, affine._dy); return rect.translated(m_matrix[2][0], m_matrix[2][1]);
if (t <= TxScale) { if (t <= TxScale) {
qreal x = affine._m11*rect.x() + affine._dx; qreal x = m_matrix[0][0] * rect.x() + m_matrix[2][0];
qreal y = affine._m22*rect.y() + affine._dy; qreal y = m_matrix[1][1] * rect.y() + m_matrix[2][1];
qreal w = affine._m11*rect.width(); qreal w = m_matrix[0][0] * rect.width();
qreal h = affine._m22*rect.height(); qreal h = m_matrix[1][1] * rect.height();
if (w < 0) { if (w < 0) {
w = -w; w = -w;
x -= w; x -= w;
@ -2093,9 +2103,11 @@ void QTransform::map(int x, int y, int *tx, int *ty) const
\warning If a perspective transformation has been specified, \warning If a perspective transformation has been specified,
then the conversion will cause loss of data. then the conversion will cause loss of data.
*/ */
const QMatrix &QTransform::toAffine() const QMatrix QTransform::toAffine() const
{ {
return affine; return QMatrix(m_matrix[0][0], m_matrix[0][1],
m_matrix[1][0], m_matrix[1][1],
m_matrix[2][0], m_matrix[2][1]);
} }
#endif // QT_DEPRECATED_SINCE(5, 15) #endif // QT_DEPRECATED_SINCE(5, 15)
@ -2118,15 +2130,15 @@ QTransform::TransformationType QTransform::type() const
switch (static_cast<TransformationType>(m_dirty)) { switch (static_cast<TransformationType>(m_dirty)) {
case TxProject: case TxProject:
if (!qFuzzyIsNull(m_13) || !qFuzzyIsNull(m_23) || !qFuzzyIsNull(m_33 - 1)) { if (!qFuzzyIsNull(m_matrix[0][2]) || !qFuzzyIsNull(m_matrix[1][2]) || !qFuzzyIsNull(m_matrix[2][2] - 1)) {
m_type = TxProject; m_type = TxProject;
break; break;
} }
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxShear: case TxShear:
case TxRotate: case TxRotate:
if (!qFuzzyIsNull(affine._m12) || !qFuzzyIsNull(affine._m21)) { if (!qFuzzyIsNull(m_matrix[0][1]) || !qFuzzyIsNull(m_matrix[1][0])) {
const qreal dot = affine._m11 * affine._m12 + affine._m21 * affine._m22; const qreal dot = m_matrix[0][0] * m_matrix[0][1] + m_matrix[1][0] * m_matrix[1][1];
if (qFuzzyIsNull(dot)) if (qFuzzyIsNull(dot))
m_type = TxRotate; m_type = TxRotate;
else else
@ -2135,13 +2147,13 @@ QTransform::TransformationType QTransform::type() const
} }
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxScale: case TxScale:
if (!qFuzzyIsNull(affine._m11 - 1) || !qFuzzyIsNull(affine._m22 - 1)) { if (!qFuzzyIsNull(m_matrix[0][0] - 1) || !qFuzzyIsNull(m_matrix[1][1] - 1)) {
m_type = TxScale; m_type = TxScale;
break; break;
} }
Q_FALLTHROUGH(); Q_FALLTHROUGH();
case TxTranslate: case TxTranslate:
if (!qFuzzyIsNull(affine._dx) || !qFuzzyIsNull(affine._dy)) { if (!qFuzzyIsNull(m_matrix[2][0]) || !qFuzzyIsNull(m_matrix[2][1])) {
m_type = TxTranslate; m_type = TxTranslate;
break; break;
} }

View File

@ -66,7 +66,7 @@ public:
TxProject = 0x10 TxProject = 0x10
}; };
inline explicit QTransform(Qt::Initialization) : affine(Qt::Uninitialized) {} inline explicit QTransform(Qt::Initialization) {}
QTransform(); QTransform();
QTransform(qreal h11, qreal h12, qreal h13, QTransform(qreal h11, qreal h12, qreal h13,
qreal h21, qreal h22, qreal h23, qreal h21, qreal h22, qreal h23,
@ -161,7 +161,7 @@ public:
void map(qreal x, qreal y, qreal *tx, qreal *ty) const; void map(qreal x, qreal y, qreal *tx, qreal *ty) const;
#if QT_DEPRECATED_SINCE(5, 15) #if QT_DEPRECATED_SINCE(5, 15)
const QMatrix &toAffine() const; QMatrix toAffine() const;
#endif // QT_DEPRECATED_SINCE(5, 15) #endif // QT_DEPRECATED_SINCE(5, 15)
QTransform &operator*=(qreal div); QTransform &operator*=(qreal div);
@ -176,8 +176,7 @@ private:
inline QTransform(qreal h11, qreal h12, qreal h13, inline QTransform(qreal h11, qreal h12, qreal h13,
qreal h21, qreal h22, qreal h23, qreal h21, qreal h22, qreal h23,
qreal h31, qreal h32, qreal h33, bool) qreal h31, qreal h32, qreal h33, bool)
: affine(h11, h12, h21, h22, h31, h32, true) : m_matrix{ {h11, h12, h13}, {h21, h22, h23}, {h31, h32, h33} }
, m_13(h13), m_23(h23), m_33(h33)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxProject) , m_dirty(TxProject)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -186,8 +185,7 @@ private:
{ {
} }
inline QTransform(bool) inline QTransform(bool)
: affine(true) : m_matrix{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1} }
, m_13(0), m_23(0), m_33(1)
, m_type(TxNone) , m_type(TxNone)
, m_dirty(TxNone) , m_dirty(TxNone)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
@ -196,10 +194,7 @@ private:
{ {
} }
inline TransformationType inline_type() const; inline TransformationType inline_type() const;
QMatrix affine; qreal m_matrix[3][3];
qreal m_13;
qreal m_23;
qreal m_33;
mutable uint m_type : 5; mutable uint m_type : 5;
mutable uint m_dirty : 5; mutable uint m_dirty : 5;
@ -250,8 +245,9 @@ inline bool QTransform::isTranslating() const
inline qreal QTransform::determinant() const inline qreal QTransform::determinant() const
{ {
return affine._m11*(m_33*affine._m22-affine._dy*m_23) - return m_matrix[0][0] * (m_matrix[2][2] * m_matrix[1][1] - m_matrix[2][1] * m_matrix[1][2]) -
affine._m21*(m_33*affine._m12-affine._dy*m_13)+affine._dx*(m_23*affine._m12-affine._m22*m_13); m_matrix[1][0] * (m_matrix[2][2] * m_matrix[0][1] - m_matrix[2][1] * m_matrix[0][2]) +
m_matrix[2][0] * (m_matrix[1][2] * m_matrix[0][1] - m_matrix[1][1] * m_matrix[0][2]);
} }
#if QT_DEPRECATED_SINCE(5, 13) #if QT_DEPRECATED_SINCE(5, 13)
inline qreal QTransform::det() const inline qreal QTransform::det() const
@ -261,47 +257,47 @@ inline qreal QTransform::det() const
#endif #endif
inline qreal QTransform::m11() const inline qreal QTransform::m11() const
{ {
return affine._m11; return m_matrix[0][0];
} }
inline qreal QTransform::m12() const inline qreal QTransform::m12() const
{ {
return affine._m12; return m_matrix[0][1];
} }
inline qreal QTransform::m13() const inline qreal QTransform::m13() const
{ {
return m_13; return m_matrix[0][2];
} }
inline qreal QTransform::m21() const inline qreal QTransform::m21() const
{ {
return affine._m21; return m_matrix[1][0];
} }
inline qreal QTransform::m22() const inline qreal QTransform::m22() const
{ {
return affine._m22; return m_matrix[1][1];
} }
inline qreal QTransform::m23() const inline qreal QTransform::m23() const
{ {
return m_23; return m_matrix[1][2];
} }
inline qreal QTransform::m31() const inline qreal QTransform::m31() const
{ {
return affine._dx; return m_matrix[2][0];
} }
inline qreal QTransform::m32() const inline qreal QTransform::m32() const
{ {
return affine._dy; return m_matrix[2][1];
} }
inline qreal QTransform::m33() const inline qreal QTransform::m33() const
{ {
return m_33; return m_matrix[2][2];
} }
inline qreal QTransform::dx() const inline qreal QTransform::dx() const
{ {
return affine._dx; return m_matrix[2][0];
} }
inline qreal QTransform::dy() const inline qreal QTransform::dy() const
{ {
return affine._dy; return m_matrix[2][1];
} }
QT_WARNING_PUSH QT_WARNING_PUSH
@ -313,15 +309,15 @@ inline QTransform &QTransform::operator*=(qreal num)
{ {
if (num == 1.) if (num == 1.)
return *this; return *this;
affine._m11 *= num; m_matrix[0][0] *= num;
affine._m12 *= num; m_matrix[0][1] *= num;
m_13 *= num; m_matrix[0][2] *= num;
affine._m21 *= num; m_matrix[1][0] *= num;
affine._m22 *= num; m_matrix[1][1] *= num;
m_23 *= num; m_matrix[1][2] *= num;
affine._dx *= num; m_matrix[2][0] *= num;
affine._dy *= num; m_matrix[2][1] *= num;
m_33 *= num; m_matrix[2][2] *= num;
if (m_dirty < TxScale) if (m_dirty < TxScale)
m_dirty = TxScale; m_dirty = TxScale;
return *this; return *this;
@ -337,15 +333,15 @@ inline QTransform &QTransform::operator+=(qreal num)
{ {
if (num == 0) if (num == 0)
return *this; return *this;
affine._m11 += num; m_matrix[0][0] += num;
affine._m12 += num; m_matrix[0][1] += num;
m_13 += num; m_matrix[0][2] += num;
affine._m21 += num; m_matrix[1][0] += num;
affine._m22 += num; m_matrix[1][1] += num;
m_23 += num; m_matrix[1][2] += num;
affine._dx += num; m_matrix[2][0] += num;
affine._dy += num; m_matrix[2][1] += num;
m_33 += num; m_matrix[2][2] += num;
m_dirty = TxProject; m_dirty = TxProject;
return *this; return *this;
} }
@ -353,15 +349,15 @@ inline QTransform &QTransform::operator-=(qreal num)
{ {
if (num == 0) if (num == 0)
return *this; return *this;
affine._m11 -= num; m_matrix[0][0] -= num;
affine._m12 -= num; m_matrix[0][1] -= num;
m_13 -= num; m_matrix[0][2] -= num;
affine._m21 -= num; m_matrix[1][0] -= num;
affine._m22 -= num; m_matrix[1][1] -= num;
m_23 -= num; m_matrix[1][2] -= num;
affine._dx -= num; m_matrix[2][0] -= num;
affine._dy -= num; m_matrix[2][1] -= num;
m_33 -= num; m_matrix[2][2] -= num;
m_dirty = TxProject; m_dirty = TxProject;
return *this; return *this;
} }

View File

@ -46,8 +46,6 @@ private slots:
void qhash(); void qhash();
void translate(); void translate();
void scale(); void scale();
void matrix();
void testOffset();
void types(); void types();
void types2_data(); void types2_data();
void types2(); void types2();
@ -372,67 +370,6 @@ void tst_QTransform::scale()
QVERIFY( QTransform::fromScale( 1, 1 ) == QTransform()); QVERIFY( QTransform::fromScale( 1, 1 ) == QTransform());
} }
#if QT_DEPRECATED_SINCE(5, 15)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
void tst_QTransform::matrix()
{
QMatrix mat1;
mat1.scale(0.3, 0.7);
mat1.translate(53.3, 94.4);
mat1.rotate(45);
QMatrix mat2;
mat2.rotate(33);
mat2.scale(0.6, 0.6);
mat2.translate(13.333, 7.777);
QTransform tran1(mat1);
QTransform tran2(mat2);
QTransform dummy;
dummy.setMatrix(mat1.m11(), mat1.m12(), 0,
mat1.m21(), mat1.m22(), 0,
mat1.dx(), mat1.dy(), 1);
QCOMPARE(tran1, dummy);
QCOMPARE(tran1.inverted(), dummy.inverted());
QCOMPARE(tran1.inverted(), QTransform(mat1.inverted()));
QCOMPARE(tran2.inverted(), QTransform(mat2.inverted()));
QMatrix mat3 = mat1 * mat2;
QTransform tran3 = tran1 * tran2;
QCOMPARE(QTransform(mat3), tran3);
/* QMatrix::operator==() doesn't use qFuzzyCompare(), which
* on win32-g++ results in a failure. So we work around it by
* calling QTranform::operator==(), which performs a fuzzy compare. */
QCOMPARE(QTransform(mat3), QTransform(tran3.toAffine()));
QTransform tranInv = tran1.inverted();
QMatrix matInv = mat1.inverted();
QRect rect(43, 70, 200, 200);
QPoint pt(43, 66);
QCOMPARE(tranInv.mapRect(rect), matInv.mapRect(rect));
QCOMPARE(tranInv.map(pt), matInv.map(pt));
QPainterPath path;
path.moveTo(55, 60);
path.lineTo(110, 110);
path.quadTo(220, 50, 10, 20);
path.closeSubpath();
QCOMPARE(tranInv.map(path), matInv.map(path));
}
void tst_QTransform::testOffset()
{
QTransform trans;
const QMatrix &aff = trans.toAffine();
QCOMPARE((void*)(&aff), (void*)(&trans));
}
QT_WARNING_POP
#endif
void tst_QTransform::types() void tst_QTransform::types()
{ {
QTransform m1; QTransform m1;