Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3800

QPolygon::subtracted() does not always give the expected result

    XMLWordPrintable

Details

    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; }

      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sletta Gunnar Sletta
            anshaw Andy Shaw (closed Nokia identity) (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes