QVector2D, QSizeF and QPointF : they all hold 2 floating point values
-
In this topic I would like to question some Qt design decisions:
1- QVector2D holds 2 private variables, x and y. If instead it would hold an array with size two ( m_data[ 2 ] ) then we could implement the operator[] and access x and y using indexes (integers), which is more convenient than x() and y() in many situations.
2- Because QVector2D, QSizeF and QPointF all store 2 floating point values, why not have QPointF and QSizeF derived from QVector2D so that we could convert between types using the operator=.
3- If QVector2D was templated it could be used as base class both for QSize, QSizeF, QPoint and QPointF.
Does any of these make sense?
-
would be nice to do QPointF + QSizeF = QPointF
-
I think maintainability is more important than you avoiding an if statement. It is hard to understand what piece of data is where if you use an array to store them. That may lead to bugs in Qt in the future. So please, don't.
Adding a convenience function that implements operator is fine by me, but the implementation would basically look like FrankZ's proposal.
I am not sure if adding a size to a point should yield another point, but perhaps it should. That would be easy to implement. You might want to supply a merge request containing the patch and a use case and/or other argumentation why this is needed.