Skip to content

Commit

Permalink
Fix QTransform::quadToQuad() to work with QRectF
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 48b1af9)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
ec1oud authored and Qt Cherry-pick Bot committed Jan 2, 2025
1 parent ff596bf commit 5ead2a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/painting/qtransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ QPolygon QTransform::mapToPolygon(const QRect &rect) const
*/
bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans)
{
if (quad.size() != 4)
if (quad.size() != (quad.isClosed() ? 5 : 4))
return false;

qreal dx0 = quad[0].x();
Expand Down
9 changes: 9 additions & 0 deletions tests/auto/gui/painting/qtransform/tst_qtransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private slots:
void mapInt();
void mapPathWithPoint();
void mapRectToPolygon(); // QTBUG-127723
void quadToQuad(); // QTBUG-21329

private:
void mapping_data();
Expand Down Expand Up @@ -714,6 +715,14 @@ void tst_QTransform::mapRectToPolygon()
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)


Expand Down

0 comments on commit 5ead2a3

Please sign in to comment.