From fdd843d5a76f2bba5c4ebdd5813c97f5105c5765 Mon Sep 17 00:00:00 2001 From: Balazs Domjan Date: Thu, 22 Aug 2013 15:37:17 +0200 Subject: Fix transform (rotation matrix) uniform scale testing. The rotation matrix is different according to the order of scale and rotate operations. The fix takes into account this. Task-number: QTBUG-31822 Change-Id: Ia1c9068e54966ec083af9c165af29caa87c510f6 Reviewed-by: Gunnar Sletta --- src/gui/painting/qtransform.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 5088e9cdc8..a07b5def5d 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -2293,13 +2293,30 @@ bool qt_scaleForTransform(const QTransform &transform, qreal *scale) return qFuzzyCompare(xScale, yScale); } - const qreal xScale = transform.m11() * transform.m11() + // rotate then scale: compare columns + const qreal xScale1 = transform.m11() * transform.m11() + transform.m21() * transform.m21(); - const qreal yScale = transform.m12() * transform.m12() + const qreal yScale1 = transform.m12() * transform.m12() + transform.m22() * transform.m22(); - if (scale) - *scale = qSqrt(qMax(xScale, yScale)); - return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale); + + // scale then rotate: compare rows + const qreal xScale2 = transform.m11() * transform.m11() + + transform.m12() * transform.m12(); + const qreal yScale2 = transform.m21() * transform.m21() + + transform.m22() * transform.m22(); + + // decide the order of rotate and scale operations + if (qAbs(xScale1 - yScale1) > qAbs(xScale2 - yScale2)) { + if (scale) + *scale = qSqrt(qMax(xScale1, yScale1)); + + return type == QTransform::TxRotate && qFuzzyCompare(xScale1, yScale1); + } else { + if (scale) + *scale = qSqrt(qMax(xScale2, yScale2)); + + return type == QTransform::TxRotate && qFuzzyCompare(xScale2, yScale2); + } } QT_END_NAMESPACE -- cgit v1.2.3