795{
796 QTransform t(t0);
797
798 QTransform projMatrix;
799
800 if (t.m33() == 0.0 || t0.determinant() == 0.0) {
801 qWarning() << "Cannot decompose matrix!" << t;
803 return;
804 }
805
806 if (t.type() == QTransform::TxProject) {
807 QTransform affineTransform(
808 t.m11(), t.m12(), 0,
809 t.m21(), t.m22(), 0,
810 t.m31(), t.m32(), 1
811 );
812 projMatrix = affineTransform.inverted() * t;
813
814 t = affineTransform;
815 proj[0] = projMatrix.m13();
816 proj[1] = projMatrix.m23();
817 proj[2] = projMatrix.m33();
818 }
819
820
821 std::array<Eigen::Vector3d, 3> rows;
822
823
824
825 rows[0] = Eigen::Vector3d(t.m11(), t.m12(), t.m13());
826 rows[1] = Eigen::Vector3d(t.m21(), t.m22(), t.m23());
827 rows[2] = Eigen::Vector3d(t.m31(), t.m32(), t.m33());
828
830 const qreal invM33 = 1.0 / t.m33();
831
832 for (auto &row : rows) {
833 row *= invM33;
834 }
835 }
836
839
840 rows[2] = Eigen::Vector3d(0,0,1);
841
842
845
846 shearXY = rows[0].dot(rows[1]);
847 rows[1] = rows[1] -
shearXY * rows[0];
848
852
853
854 qreal determinant = rows[0].x() * rows[1].y() - rows[0].y() * rows[1].x();
855 if (determinant < 0) {
856
857 if (rows[0].
x() < rows[1].
y()) {
859 rows[0] = -rows[0];
860 } else {
862 rows[1] = -rows[1];
863 }
865 }
866
868
870
871
872
873
874 qreal sn = -rows[0].y();
875 qreal cs = rows[0].x();
876 qreal m11 = rows[0].x();
877 qreal m12 = rows[0].y();
878 qreal m21 = rows[1].x();
879 qreal m22 = rows[1].y();
880 rows[0][0] = (cs * m11 + sn * m21);
881 rows[0][1] = (cs * m12 + sn * m22);
882 rows[1][0] = (-sn * m11 + cs * m21);
883 rows[1][1] = (-sn * m12 + cs * m22);
884 }
885
886 QTransform leftOver(
887 rows[0].
x(), rows[0].
y(), rows[0].z(),
888 rows[1].
x(), rows[1].
y(), rows[1].z(),
889 rows[2].
x(), rows[2].
y(), rows[2].z());
890
892
899 Eigen::Matrix3d mat3 = mat2 - mat1;
903
904 }
905
906
909}
static bool qFuzzyCompare(half p1, half p2)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
T kisRadiansToDegrees(T radians)
bool fuzzyMatrixCompare(const QTransform &t1, const QTransform &t2, qreal delta)
Eigen::Matrix3d fromQTransformStraight(const QTransform &t)