fix lookup of ComparableQPoint keys in QMap
QMap::value() failed to find existing keys in some edge cases. Which lead to problems when translating points using a QMap.
This commit improves the operator<() to fix that.
This shows the bug in action and how the fix fixes it: brainpower/spectacle$1457
One can see that the order of the elements of the map is stable in the second case, and rather random in the first case (depending a bit on insertion order). For a map to work correctly, the order must be stable and always the same.
The change makes the ordering of the Points stable, which is what QMap needs to work correctly.
The Ordering was broken because before this fix both a < b
and b < a
evaluated true
in cases like the one below,
thus defining no order between a and b and that broke QMap,
because it assumes that different values order differently (I'm sure there's a name for that):
ComparableQPoint a(QPoint{1680,0});
ComparableQPoint b(QPoint{0, 195});
qDebug() << " a < b == " << (a < b);
qDebug() << " b < a == " << (b < a);
a < b == true
b < a == true