summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qpoint.h
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-12-01 14:07:26 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-02-04 17:18:51 +0100
commit7a738daa97436478a21b5dd31ba2312b2cb2df41 (patch)
tree9e4a536302e2c0b212f99031bb017dfb7961effe /src/corelib/tools/qpoint.h
parent96ef1769c18d90053e48176c22a594e03f1d6e38 (diff)
Make explicit that we expect co-ordinates to be finite
The various spatial-vector, line, point, region and margin types have all long taken for granted that their co-ordinates are finite and, in particular, not NaN. Make this expectation explicit in the documentation. Added assertions where (chiefly) noexcept and (where the assertion would be a simple qIsFinite() call) constexpr didn't preclude doing so. Also assert against zero divisors that would lead to non-finite results. Make minor clean-ups to docs in the process. QMarginsF had several methods whose declaration, definition and docs weren't consistent in their parameter names. Task-number: QTBUG-89010 Change-Id: I601a830959d13a73dcb17ce31a1202a1486c8f7f Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/tools/qpoint.h')
-rw-r--r--src/corelib/tools/qpoint.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index 118d837d69..b886ce3801 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.h
@@ -295,7 +295,10 @@ public:
friend constexpr inline QPointF operator-(const QPointF &p)
{ return QPointF(-p.xp, -p.yp); }
friend constexpr inline QPointF operator/(const QPointF &p, qreal divisor)
- { return QPointF(p.xp / divisor, p.yp / divisor); }
+ {
+ Q_ASSERT(divisor < 0 || divisor > 0);
+ return QPointF(p.xp / divisor, p.yp / divisor);
+ }
constexpr QPoint toPoint() const;
@@ -406,6 +409,7 @@ constexpr inline QPointF &QPointF::operator*=(qreal c)
constexpr inline QPointF &QPointF::operator/=(qreal divisor)
{
+ Q_ASSERT(divisor > 0 || divisor < 0);
xp /= divisor;
yp /= divisor;
return *this;