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

QPainterPath::intersected still fails in some cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • Some future release
    • 4.8.5, 5.1.0
    • GUI: Painting
    • Mac OS X 10.6
      gcc 4.2.1
      qt-everywhere-opensource-src-4.7.0 (Built from sources)

    Description

      QpainterPath::intersected function does not function properly in some rare cases. The experiencing behavior is not well defined: in the application I'm working on the function returns an empty QPainterPath, while in the standalone test case it just returns a wrong value. This discrepancy might be caused by the rounding errors.

      The test case consists of two QPainterPaths: p1 and p2. They are intersected like this:
      p1.intersected(p2) and p2.intersected(p1). The results should be equal, while they are not.

      #include <QtGui>
      
      #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
      #include <QtWidgets>
      #endif
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QGraphicsView view;
          view.resize(1000, 800);
          view.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, view.size(), qApp->desktop()->availableGeometry()));
          view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
          QGraphicsScene *scene = new QGraphicsScene;
          view.setScene(scene);
          view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
          view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      
      //#define SHOW_BUG
      #ifdef SHOW_BUG
          // Doesn't work
          QPainterPath p1;
          p1.moveTo(256.0000000000000000, 135.8384137532701743);
          p1.lineTo(50.9999999999999715, 107.9999999999999857);
          p1.lineTo(233.5425474228109123, 205.3560252921671462);
          p1.lineTo(191.7771366877784373, 318.0257074407572304);
          p1.lineTo(-48.2616272048215151, 229.0459803737862216);
          p1.lineTo(0.0000000000000000, 98.8515898136580801);
          p1.lineTo(0.0000000000000000, 0.0000000000000000);
          p1.lineTo(256.0000000000000000, 0.0000000000000000);
          p1.lineTo(256.0000000000000000, 135.8384137532701743);
      
          QPainterPath p2;
          p2.moveTo(1516.2703263523442274, 306.9795200262722119);
          p2.lineTo(-1296.8426224886295585, -75.0331736542986931);
          p2.lineTo(-1678.8553161692004778, 2738.0797751866753060);
          p2.lineTo(1134.2576326717733081, 3120.0924688672457705);
          p2.lineTo(1516.2703263523442274, 306.9795200262722119);
      #else
          // Works
          QPainterPath p1 = QPainterPath();
          p1.moveTo(256.00000000, 135.83841375);
          p1.lineTo(50.99999999, 107.99999999);
          p1.lineTo(233.54254742, 205.35602529);
          p1.lineTo(191.77713668, 318.02570744);
          p1.lineTo(-48.26162720, 229.04598037);
          p1.lineTo(0.00000000, 98.85158981);
          p1.lineTo(0.00000000, 0.00000000);
          p1.lineTo(256.00000000, 0.00000000);
          p1.lineTo(256.00000000, 135.83841375);
      
          QPainterPath p2 = QPainterPath();
          p2.moveTo(1516.27032635, 306.97952002);
          p2.lineTo(-1296.84262248, -75.03317365);
          p2.lineTo(-1678.85531616, 2738.07977518);
          p2.lineTo(1134.25763267, 3120.09246886);
          p2.lineTo(1516.27032635, 306.97952002);
      #endif
          QPainterPath i1 = p1.intersected(p2);
          QPainterPath i2 = p2.intersected(p1);
          qDebug() << i1 << i2;
      
          scene->addPath(p1, QPen(Qt::red));
          scene->addPath(p2, QPen(Qt::blue));
          view.fitInView(scene->itemsBoundingRect().adjusted(600, 600, -600, -600), Qt::KeepAspectRatio);
          view.show();
          return app.exec();
      }
      

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            akhodakivskiy Anton Khodakivskiy
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes