From 4334d07f52dfc1d7fce6ebbad6e9f377ef33dedb Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 2 Aug 2011 11:26:24 +1000 Subject: Use more numerically robust algorithm to compute QBezier::pointAt(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QBezier::pointAt() could potentially return values outside the bezier's bounds, even when the bezier was a straight horizontal line. For example, with y = 0.5, it would produce y=0.5 or y=0.49999999999999 for different values of t, which when rounded cause jittering in a QML PathView. Task-number: QTBUG-17007 Task-number: QTBUG-18133 Cherry-pick-of: 8b66982ec7b4b5d2071931c288973dce73dc9875 Change-Id: I4ecac7b9085aaaaaaaaaaaaaaaaaaaaaa7d7b0bc Reviewed-on: http://codereview.qt.nokia.com/2467 Reviewed-by: Samuel Rødal --- src/gui/painting/qbezier_p.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qbezier_p.h b/src/gui/painting/qbezier_p.h index 399dd89140..f1f7eb155a 100644 --- a/src/gui/painting/qbezier_p.h +++ b/src/gui/painting/qbezier_p.h @@ -162,27 +162,27 @@ inline void QBezier::coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal & inline QPointF QBezier::pointAt(qreal t) const { -#if 1 - qreal a, b, c, d; - coefficients(t, a, b, c, d); - return QPointF(a*x1 + b*x2 + c*x3 + d*x4, a*y1 + b*y2 + c*y3 + d*y4); -#else // numerically more stable: + qreal x, y; + qreal m_t = 1. - t; - qreal a = x1*m_t + x2*t; - qreal b = x2*m_t + x3*t; - qreal c = x3*m_t + x4*t; - a = a*m_t + b*t; - b = b*m_t + c*t; - qreal x = a*m_t + b*t; - qreal a = y1*m_t + y2*t; - qreal b = y2*m_t + y3*t; - qreal c = y3*m_t + y4*t; - a = a*m_t + b*t; - b = b*m_t + c*t; - qreal y = a*m_t + b*t; + { + qreal a = x1*m_t + x2*t; + qreal b = x2*m_t + x3*t; + qreal c = x3*m_t + x4*t; + a = a*m_t + b*t; + b = b*m_t + c*t; + x = a*m_t + b*t; + } + { + qreal a = y1*m_t + y2*t; + qreal b = y2*m_t + y3*t; + qreal c = y3*m_t + y4*t; + a = a*m_t + b*t; + b = b*m_t + c*t; + y = a*m_t + b*t; + } return QPointF(x, y); -#endif } inline QPointF QBezier::normalVector(qreal t) const -- cgit v1.2.3 From ad9f5c7e938b1d80b455acdfd0809448f2b5e1db Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Tue, 9 Aug 2011 11:30:03 +0200 Subject: Remove all non-const operator== We had to leave the non-const operator== for binary compatibility. Remove them all, just leave the const version in there. 100% source compatible. Change-Id: Ib7a70fb441fe51d5164d9cbf495cbeda0f48fafe Reviewed-on: http://codereview.qt.nokia.com/2773 Reviewed-by: Qt Sanity Bot Reviewed-by: Robert Griebl --- src/gui/painting/qbrush.cpp | 8 -------- src/gui/painting/qbrush.h | 2 -- 2 files changed, 10 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 97ea4dbc15..742a4ea071 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -1567,14 +1567,6 @@ bool QGradient::operator==(const QGradient &gradient) const return stops() == gradient.stops(); } -/*! - \internal -*/ -bool QGradient::operator==(const QGradient &gradient) -{ - return const_cast(this)->operator==(gradient); -} - /*! \class QLinearGradient \ingroup painting diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 4a0bfcc8e4..edf99924a3 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -249,8 +249,6 @@ public: inline bool operator!=(const QGradient &other) const { return !operator==(other); } - bool operator==(const QGradient &gradient); // ### Qt 5: remove - private: friend class QLinearGradient; friend class QRadialGradient; -- cgit v1.2.3