Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPolygonF error
Forum Updated to NodeBB v4.3 + New Features

QPolygonF error

Scheduled Pinned Locked Moved Unsolved General and Desktop
34 Posts 5 Posters 7.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Christian EhrlicherC Christian Ehrlicher

    @Daniil-S said in QPolygonF error:

    don't understand what else is needed

    If you want us to take a look on the problem then

    • create two QPolygonF with your points
    • call unite() on them
    • tells us what's wrong

    Noone will step through your code above, especially when the input is unknown.

    D Offline
    D Offline
    Daniil S.
    wrote on last edited by
    #13

    @Christian-Ehrlicher what you need or a smaller example?

    JonBJ 1 Reply Last reply
    0
    • D Daniil S.

      @Christian-Ehrlicher what you need or a smaller example?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #14

      @Daniil-S said in QPolygonF error:

      or a smaller example?

      Do you really need about 100 lines of code to draw a polygon to illustrate whatever your problem is? Have you reduced this to some minimum which exemplifies the problem? Any example to illustrate a point which is longer than about 20 lines is suspect....

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #15

        I will not debug your code, as @JonB said (and also me some time ago) a simple list with the polygons as input and the (wrong) and correct output is the way to go.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • D Offline
          D Offline
          Daniil S.
          wrote on last edited by Daniil S.
          #16
            QVector<QPointF> high, low;
            high << QPointF(293,0) << QPointF(406.102, 225) << QPointF(556,0);
            low << QPointF(79,-1) << QPointF(182.303, 57) << QPointF(673,-1);
          
            qDebug() << HtpType(HtpType(low, high), high);
          
            QVector<QPointF> high1, low1;
            high1 << QPointF(293,0) << QPointF(406.102, 225) << QPointF(556,0);
            low1 << QPointF(79,-1) << QPointF(182.303, 60) << QPointF(673,-1);
          
            qDebug() << HtpType(HtpType(low1, high1), high1);
          

          first qDebug() (second point of low Y = 57) bad result

          QVector(QPointF(79,-1), QPointF(182.303,57), QPointF(293,44), QPointF(293,0), QPointF(293,44), QPointF(313.881,41.5388), QPointF(293,0), QPointF(313.881,41.5388), QPointF(406.102,225), QPointF(546.601,14.1078), QPointF(556,13), QPointF(556,0), QPointF(406.102,225), QPointF(313.881,41.5388), QPointF(556,-1), QPointF(673,-1))

          second qDebug() (second point of low Y = 60) right result

          QVector(QPointF(79,-1), QPointF(182.303,60), QPointF(293,46), QPointF(314.79,43.3487), QPointF(406.102,225), QPointF(545.85,15.2349), QPointF(556,14), QPointF(556,-1), QPointF(673,-1))

          to combine two plots, I need to use this method, because graphs has flags that cannot be changed during combine, so the intersection is first searched and it is combined to the top

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #17

            This is a testcase similar to what we want to see:

            int main(int argc, char **argv)
            {
              QCoreApplication app(argc, argv);
            
              QPolygonF p1 = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}});
              QPolygonF p2 = QVector<QPointF>({{2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}});
              QPolygonF united = p1.united(p2);
              QPolygonF expected = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}, {1., 0.}, {2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}, {2., 2.}, {1., 0.}});
              qDebug() << (united == expected);
              qDebug() << united;
              qDebug() << expected;
            
              return 0;
            }
            

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            D 2 Replies Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              This is a testcase similar to what we want to see:

              int main(int argc, char **argv)
              {
                QCoreApplication app(argc, argv);
              
                QPolygonF p1 = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}});
                QPolygonF p2 = QVector<QPointF>({{2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}});
                QPolygonF united = p1.united(p2);
                QPolygonF expected = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}, {1., 0.}, {2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}, {2., 2.}, {1., 0.}});
                qDebug() << (united == expected);
                qDebug() << united;
                qDebug() << expected;
              
                return 0;
              }
              
              D Offline
              D Offline
              Daniil S.
              wrote on last edited by
              #18

              @Christian-Ehrlicher

              int main(int argc, char *argv[])
              {
                QPolygonF high, low;
                high << QPointF(293, 0) << QPointF(406.102, 225) << QPointF(556, 0);
                low << QPointF(79, -1) << QPointF(182.303, 60) << QPointF(673, -1);
              
              
              
                QPolygonF low1(low.united(high).united(high))
                    , expected({ QPointF(79,-1), QPointF(182.303,60), QPointF(314.876,43.5194), QPointF(406.102,225), QPointF(546.162,14.7677), QPointF(673,-1), QPointF(79,-1) });
              
                qDebug() << low1;
                qDebug() << expected;
                qDebug() << (expected == low1);
              
                return 0;
              }
              

              qDebug()

              QPolygonF(QPointF(79,-1)QPointF(182.303,60)QPointF(314.876,43.5194)QPointF(293,0)QPointF(556,0)QPointF(406.102,225)QPointF(314.876,43.5194)QPointF(182.303,60)QPointF(79,-1)QPointF(314.876,43.5194)QPointF(406.102,225)QPointF(546.162,14.7677)QPointF(673,-1)QPointF(79,-1)QPointF(182.303,60)QPointF(314.876,43.5194)QPointF(293,0)QPointF(556,0)QPointF(406.102,225)QPointF(314.876,43.5194)QPointF(79,-1))
              
              QPolygonF(QPointF(79,-1)QPointF(182.303,60)QPointF(314.876,43.5194)QPointF(406.102,225)QPointF(546.162,14.7677)QPointF(673,-1)QPointF(79,-1))
              
              false
              
              1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                This is a testcase similar to what we want to see:

                int main(int argc, char **argv)
                {
                  QCoreApplication app(argc, argv);
                
                  QPolygonF p1 = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}});
                  QPolygonF p2 = QVector<QPointF>({{2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}});
                  QPolygonF united = p1.united(p2);
                  QPolygonF expected = QVector<QPointF>({{1., 0.}, {2., 1.}, {3., 1.}, {4., 1.}, {1., 0.}, {2., 2.}, {3., 2.}, {4., 5.}, {3., 2.}, {2., 2.}, {1., 0.}});
                  qDebug() << (united == expected);
                  qDebug() << united;
                  qDebug() << expected;
                
                  return 0;
                }
                
                D Offline
                D Offline
                Daniil S.
                wrote on last edited by
                #19

                @Christian-Ehrlicher still not what you need?

                kshegunovK 1 Reply Last reply
                0
                • D Daniil S.

                  @Christian-Ehrlicher still not what you need?

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #20

                  low.united(high).united(high)?

                  Why the second call? What does calling it only once produce?

                  Read and abide by the Qt Code of Conduct

                  D 1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    low.united(high).united(high)?

                    Why the second call? What does calling it only once produce?

                    D Offline
                    D Offline
                    Daniil S.
                    wrote on last edited by Daniil S.
                    #21

                    @kshegunov I have an application that combines graphs of changing values, nothing prevents different "scenes" with same graphs that can combined more times. now I have 3 scenes, on 3 lines, the top two scenes have exactly the same graph, and if i combine them all, this leads to this error

                    kshegunovK 1 Reply Last reply
                    0
                    • D Daniil S.

                      @kshegunov I have an application that combines graphs of changing values, nothing prevents different "scenes" with same graphs that can combined more times. now I have 3 scenes, on 3 lines, the top two scenes have exactly the same graph, and if i combine them all, this leads to this error

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #22

                      Okay, this answers the first question, what about the second? Does calling .union only once produce the correct result?

                      Read and abide by the Qt Code of Conduct

                      Christian EhrlicherC D 2 Replies Last reply
                      0
                      • kshegunovK kshegunov

                        Okay, this answers the first question, what about the second? Does calling .union only once produce the correct result?

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #23

                        @kshegunov said in QPolygonF error:

                        Does calling .union only once produce the correct result?

                        Yes, but with slightly different numbers (not visible in a plain debug output). I would guess somewhere in the clipping logic a rounding error triggers this bug (e.g. 314.87615740 / 43.51943745 <-> 314.87600000 / 43.51940000)

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        kshegunovK 1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          Okay, this answers the first question, what about the second? Does calling .union only once produce the correct result?

                          D Offline
                          D Offline
                          Daniil S.
                          wrote on last edited by Daniil S.
                          #24

                          @kshegunov yes, but I cant check top polygons are equal, because they must be combined in order in the loop and can have different overlay types, and checking high by points before united is not entirely correct, because a polygon can contain a point, but not a union

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @kshegunov said in QPolygonF error:

                            Does calling .union only once produce the correct result?

                            Yes, but with slightly different numbers (not visible in a plain debug output). I would guess somewhere in the clipping logic a rounding error triggers this bug (e.g. 314.87615740 / 43.51943745 <-> 314.87600000 / 43.51940000)

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by kshegunov
                            #25

                            @Christian-Ehrlicher said in QPolygonF error:

                            Yes, but with slightly different numbers (not visible in a plain debug output). I would guess somewhere in the clipping logic a rounding error triggers this bug (e.g. 314.87615740 / 43.51943745 <-> 314.87600000 / 43.51940000)

                            Looks truncated more than a rounding error.

                            @Daniil-S said in QPolygonF error:

                            yes, but I cant check top polygons are equal, because they must be combined in order in the loop and can have different overlay types, and checking high by points before united is not entirely correct, because a polygon can contain a point, but not a union

                            I was asking to discern whether the problem is that the two unions apply the same polygon only, there's a lot of edge cases whenever you're dealing with lines which are almost parallel (e.g. https://codereview.qt-project.org/c/qt/qtbase/+/292807).

                            Please search the tracker and if this isn't reported, do so. Attach the minimal code to reproduce as well. Whenever I finish with that QLineF thing, given time I'll take a look.

                            Read and abide by the Qt Code of Conduct

                            Christian EhrlicherC D 2 Replies Last reply
                            0
                            • kshegunovK kshegunov

                              @Christian-Ehrlicher said in QPolygonF error:

                              Yes, but with slightly different numbers (not visible in a plain debug output). I would guess somewhere in the clipping logic a rounding error triggers this bug (e.g. 314.87615740 / 43.51943745 <-> 314.87600000 / 43.51940000)

                              Looks truncated more than a rounding error.

                              @Daniil-S said in QPolygonF error:

                              yes, but I cant check top polygons are equal, because they must be combined in order in the loop and can have different overlay types, and checking high by points before united is not entirely correct, because a polygon can contain a point, but not a union

                              I was asking to discern whether the problem is that the two unions apply the same polygon only, there's a lot of edge cases whenever you're dealing with lines which are almost parallel (e.g. https://codereview.qt-project.org/c/qt/qtbase/+/292807).

                              Please search the tracker and if this isn't reported, do so. Attach the minimal code to reproduce as well. Whenever I finish with that QLineF thing, given time I'll take a look.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #26

                              @kshegunov said in QPolygonF error:

                              Looks truncated more than a rounding error.

                              No error - qDebug() prints not the complete double value, I guess the values are taken from there. Mine are the exact ones :)

                              So basically a polygon is united with a polygon which nearly matches parts of the first polygon which fails sometimes.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              kshegunovK 1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                @kshegunov said in QPolygonF error:

                                Looks truncated more than a rounding error.

                                No error - qDebug() prints not the complete double value, I guess the values are taken from there. Mine are the exact ones :)

                                So basically a polygon is united with a polygon which nearly matches parts of the first polygon which fails sometimes.

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by
                                #27

                                @Christian-Ehrlicher said in QPolygonF error:

                                So basically a polygon is united with a polygon which nearly matches parts of the first polygon which fails sometimes.

                                Yes, what I imagine happens. Probably somewhere in the clip/intersection code there's some numerical instability that breaks it silently.

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                0
                                • kshegunovK kshegunov

                                  @Christian-Ehrlicher said in QPolygonF error:

                                  Yes, but with slightly different numbers (not visible in a plain debug output). I would guess somewhere in the clipping logic a rounding error triggers this bug (e.g. 314.87615740 / 43.51943745 <-> 314.87600000 / 43.51940000)

                                  Looks truncated more than a rounding error.

                                  @Daniil-S said in QPolygonF error:

                                  yes, but I cant check top polygons are equal, because they must be combined in order in the loop and can have different overlay types, and checking high by points before united is not entirely correct, because a polygon can contain a point, but not a union

                                  I was asking to discern whether the problem is that the two unions apply the same polygon only, there's a lot of edge cases whenever you're dealing with lines which are almost parallel (e.g. https://codereview.qt-project.org/c/qt/qtbase/+/292807).

                                  Please search the tracker and if this isn't reported, do so. Attach the minimal code to reproduce as well. Whenever I finish with that QLineF thing, given time I'll take a look.

                                  D Offline
                                  D Offline
                                  Daniil S.
                                  wrote on last edited by Daniil S.
                                  #28

                                  @kshegunov yes, it only happens if two identical polygons are combine.
                                  here i think, is what is needed

                                  kshegunovK 1 Reply Last reply
                                  1
                                  • D Daniil S.

                                    @kshegunov yes, it only happens if two identical polygons are combine.
                                    here i think, is what is needed

                                    kshegunovK Offline
                                    kshegunovK Offline
                                    kshegunov
                                    Moderators
                                    wrote on last edited by kshegunov
                                    #29

                                    lol. "Out of scope" ... what can I say ...

                                    I suggest you open a new one, attach the reproducing code (the minimal one that @Christian-Ehrlicher insisted on), and put in the:
                                    "Relates to ..." field in JIRA QTBUG-38037, as it does indeed seem related.

                                    Read and abide by the Qt Code of Conduct

                                    1 Reply Last reply
                                    2
                                    • D Offline
                                      D Offline
                                      Daniil S.
                                      wrote on last edited by
                                      #30

                                      https://bugreports.qt.io/browse/QTBUG-100172

                                      1 Reply Last reply
                                      3
                                      • kshegunovK Offline
                                        kshegunovK Offline
                                        kshegunov
                                        Moderators
                                        wrote on last edited by kshegunov
                                        #31

                                        As I was looking into this, I also opened:

                                        https://bugreports.qt.io/browse/QTBUG-100302

                                        Read and abide by the Qt Code of Conduct

                                        D 2 Replies Last reply
                                        2
                                        • kshegunovK kshegunov

                                          As I was looking into this, I also opened:

                                          https://bugreports.qt.io/browse/QTBUG-100302

                                          D Offline
                                          D Offline
                                          Daniil S.
                                          wrote on last edited by
                                          #32

                                          @kshegunov I noticed it, but thought that I did something wrong

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved