Details
-
Bug
-
Resolution: Out of scope
-
P4: Low
-
4.4.3
-
None
Description
QPolygon::subtracted() does not always give the expected result, if there is a same pixel connection then it will not work correctly
Example:
#include <QtGui>
int main(int argc, char** argv)
{
QCoreApplication app(argc,argv);
qDebug() << "1. Testcase";
QPolygon rect( QRect( 0, 0, 200, 200 ) );
QPolygon polygon;
polygon << QPoint(50, 10)
<< QPoint(10, 10)
<< QPoint(10, 50)
<< QPoint(50, 50) //--> from 50/50 to 100/100
<< QPoint(100, 100)
<< QPoint(100, 150)
<< QPoint(150, 150)
<< QPoint(150, 100)
<< QPoint(100, 100) //--> and back to the first rectangle
<< QPoint(50, 50)
<< QPoint(50, 10);
QPolygon pTemp = rect.subtracted( polygon );
QPolygon result = rect.subtracted( pTemp );
if ( result == polygon )
{ qDebug() << "OK, the resulting poylgon is equal"; } else { qDebug() << "The resulting poylgon is not equal"; qDebug() << result; }// Testcase 2, the two connecting lines are not equal
qDebug() << "2. Testcase";
QPolygon polygon2;
polygon2 << QPoint(50, 10)
<< QPoint(10, 10)
<< QPoint(10, 50)
<< QPoint(50, 50) //--> from 50/50 to 100/100
<< QPoint(100, 100)
<< QPoint(100, 150)
<< QPoint(150, 150)
<< QPoint(150, 100)
<< QPoint(101, 100) //--> and back to the first rectangle, but now 1 pixel shifted
<< QPoint(51, 50)
<< QPoint(50, 10);
pTemp = rect.subtracted( polygon2 );
result = rect.subtracted( pTemp );
if ( result == polygon2 ) { qDebug() << "OK, the resulting poylgon is equal"; }
else
{ qDebug() << "The resulting poylgon is not equal"; qDebug() << result; }}