summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qbezier_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-08-14 09:41:18 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-08-22 09:39:07 +0000
commitd1b099c3e3cfcbf86353b53e205c0ebf84cf5592 (patch)
tree3cb4d80328fad7b7a6034616f563555627954929 /src/gui/painting/qbezier_p.h
parent5b2dfbc649a7c20a93223cd4c274a4b0fe847df8 (diff)
QBezier: replace out parameters by return-by-value in split()
At least QBezier itself is calling the old function with *this aliased to one of the arguments. Consequently, the implementation looks rather ... shuffled, to avoid writing into members that it will read once more later. Fix by returning a std::pair<QBezier, QBezier> instead. This simplifies the code that doesn't actually pass existing objects in, and avoids aliasing problems cropping up under seemingly innocuous reorderings of statements in the implementation going forward. While I'm usually vehemently against use std::pair or std::tuple in APIs, preferring simple structs with aptly-named members instead, this is one case where the .first and .second actually fit, and pair allows us to use std::tie, which was handy in qbezier.cpp. This patch preserves the body of the function as much as possible. A follow-up patch will clean it up. Change-Id: I017dfee4a0e69a2e171ce21b89ba04654772c33d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/gui/painting/qbezier_p.h')
-rw-r--r--src/gui/painting/qbezier_p.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/gui/painting/qbezier_p.h b/src/gui/painting/qbezier_p.h
index f88e3b35b3..02b29c5ba7 100644
--- a/src/gui/painting/qbezier_p.h
+++ b/src/gui/painting/qbezier_p.h
@@ -107,7 +107,7 @@ public:
inline QLineF endTangent() const;
inline void parameterSplitLeft(qreal t, QBezier *left);
- inline void split(QBezier *firstHalf, QBezier *secondHalf) const;
+ inline std::pair<QBezier, QBezier> split() const;
int shifted(QBezier *curveSegments, int maxSegmets,
qreal offset, float threshold) const;
@@ -223,10 +223,11 @@ inline QPointF QBezier::secondDerivedAt(qreal t) const
a * y1 + b * y2 + c * y3 + d * y4);
}
-inline void QBezier::split(QBezier *firstHalf, QBezier *secondHalf) const
+std::pair<QBezier, QBezier> QBezier::split() const
{
- Q_ASSERT(firstHalf);
- Q_ASSERT(secondHalf);
+ std::pair<QBezier, QBezier> r;
+ auto firstHalf = &r.first;
+ auto secondHalf = &r.second;
qreal c = (x2 + x3)*.5;
firstHalf->x2 = (x1 + x2)*.5;
@@ -245,6 +246,8 @@ inline void QBezier::split(QBezier *firstHalf, QBezier *secondHalf) const
firstHalf->y3 = (firstHalf->y2 + c)*.5;
secondHalf->y2 = (secondHalf->y3 + c)*.5;
firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*.5;
+
+ return r;
}
inline void QBezier::parameterSplitLeft(qreal t, QBezier *left)