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

add translate() and translated() methods to QPoint and QPointF for readability, purity and consistency

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.0.0
    • Core: Other
    • None
    • All

    Description

      It would be nice to have translate(int, int), translated(int, int), translate(QPoint), translated(QPoint) methods to QPoint and translate(qreal, qreal), translated(qreal, qreal), translate(QPointF), translated(QPointF) for QPointF.

      Why I feel this would be useful:

      1) Assume I want to translate point by vector (dx, dy). The only way seems to be to use operator QPoint x(4,3); x += QPoint(dx, dy); Though this works fine, it is not correct from mathematical purity point of view. Adding a point to a point is just two points. Of course QPoint can represent a 2D vector and you can add a vector to a point to get a translated point. Anyway translating by adding two {{QPoint}}s together is not mathematically correct.

      2) Another reason is to have consistency between QRect and QPoint. Imagine refactoring of piece of code from QRect to QPoint, e.g. because I am not interested in the QSize component of the geometry element any more. In that case I must rewite all QRect::translate() and QRect::translated() calls to += operators. Could be tedious. For consistency reason it would be nice to have also QPoint::translate(QPoint) and QPoint::translated(QPoint).

      3) And the most important reason is readability. Reading translate(dy, dy) or translated(dx, dy) is so obvious to understand what is happening here with the point coordinates. Operator + is not that readable.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes