Fix QTransform::quadToQuad() to work with QRectF

A typical usage for mapping a 4-point polygon to a rectangle might be

  QTransform transform;
  bool ok = QTransform::quadToQuad(polygon, polygon->boundingRect(),
                                   transform);

It works because the QPolygonF(QRectF) ctor is implicitly called on
the second argument; but that ctor turns it into a 5-point polygon.
So it should be legal for QTransform functions to work with 5-point
closed paths.

Fixes: QTBUG-21329
Change-Id: Iae249012e14b8a3e8d3b0dfa35da8f9759359832
Pick-to: 6.8 6.5 5.15
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit 48b1af941c50ab28cc92f9ea65a8a74a32eaf2bc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Shawn Rutledge 2024-12-28 10:57:04 +01:00 committed by Qt Cherry-pick Bot
parent ff596bfac8
commit 5ead2a3d63
2 changed files with 10 additions and 1 deletions

View File

@ -1609,7 +1609,7 @@ QPolygon QTransform::mapToPolygon(const QRect &rect) const
*/ */
bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans) bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans)
{ {
if (quad.size() != 4) if (quad.size() != (quad.isClosed() ? 5 : 4))
return false; return false;
qreal dx0 = quad[0].x(); qreal dx0 = quad[0].x();

View File

@ -35,6 +35,7 @@ private slots:
void mapInt(); void mapInt();
void mapPathWithPoint(); void mapPathWithPoint();
void mapRectToPolygon(); // QTBUG-127723 void mapRectToPolygon(); // QTBUG-127723
void quadToQuad(); // QTBUG-21329
private: private:
void mapping_data(); void mapping_data();
@ -714,6 +715,14 @@ void tst_QTransform::mapRectToPolygon()
QCOMPARE(polygon1, polygon2); QCOMPARE(polygon1, polygon2);
} }
void tst_QTransform::quadToQuad() // QTBUG-21329
{
QTransform result;
QVERIFY(QTransform::quadToQuad(QRectF(0, 0, 1, 1), QRectF(0, 0, 1, 1), result));
QPolygonF trapezoid({{0, 0}, {10, 0}, {11, 11}, {0, 10}});
QVERIFY(QTransform::quadToQuad(trapezoid, trapezoid.boundingRect(), result));
}
QTEST_APPLESS_MAIN(tst_QTransform) QTEST_APPLESS_MAIN(tst_QTransform)