summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-11-03 09:36:52 (GMT)
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-11-06 16:45:51 (GMT)
commit676780d515cedca85829ae962e4f501c5e5b6581 (patch)
treeb2994f82bf34031ae4b23ed9eb3a078e3c2a1e39 /src/gui/painting
parent03b19519768b504e5c7f5fd3923a14591e58b365 (diff)
downloadQt-676780d515cedca85829ae962e4f501c5e5b6581.zip
Qt-676780d515cedca85829ae962e4f501c5e5b6581.tar.gz
Qt-676780d515cedca85829ae962e4f501c5e5b6581.tar.bz2
Using qreal more consistently in code (prevent misuse of double)
We want to force use of qreal where possible. This can lead to better performance on platforms where qreal -> float (i.e. ARM). To achieve this we: 1. changed from 'double' to 'qreal', where justified 2. using qreal() to intialize constants, where justified 3. adding helper functions that are overloaded for qreal like qAtan2(), qAcos(), qFabs() ... 4. defining QT_USE_MATH_H_FLOATS for Symbian platform In addtion we used opportunity to improve code with some small things 5. converting divisions to multiplications (i.e. '/ 2.0' -> '* qreal(0.5)') 6. defining new constants (i.e. 'Q_PI / 180.0' -> 'Q_PI180') 7. declaring variables as 'const', where justified Reviewed-by: Andreas Aardal Hanssen Reviewed-by: Gunnar Sletta Reviewed-by: Jan-Arve Reviewed-by: Kim Motoyoshi Kalland Reviewed-by: Alessandro Portale Reviewed-by: Janne Koskinen
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qbezier.cpp104
-rw-r--r--src/gui/painting/qbezier_p.h45
-rw-r--r--src/gui/painting/qblendfunctions.cpp18
-rw-r--r--src/gui/painting/qbrush.cpp2
-rw-r--r--src/gui/painting/qcolor.cpp89
-rw-r--r--src/gui/painting/qdrawhelper.cpp111
-rw-r--r--src/gui/painting/qdrawutil.cpp70
-rw-r--r--src/gui/painting/qmath_p.h5
-rw-r--r--src/gui/painting/qpaintbuffer.cpp2
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp32
-rw-r--r--src/gui/painting/qpaintengineex.cpp13
-rw-r--r--src/gui/painting/qpainter.cpp27
-rw-r--r--src/gui/painting/qpainterpath.cpp27
-rw-r--r--src/gui/painting/qpainterpath_p.h2
-rw-r--r--src/gui/painting/qpathclipper.cpp18
-rw-r--r--src/gui/painting/qrasterizer.cpp32
-rw-r--r--src/gui/painting/qstroker.cpp25
-rw-r--r--src/gui/painting/qstroker_p.h2
-rw-r--r--src/gui/painting/qtransform.cpp27
19 files changed, 338 insertions, 313 deletions
diff --git a/src/gui/painting/qbezier.cpp b/src/gui/painting/qbezier.cpp
index a6b4cef..c49086b 100644
--- a/src/gui/painting/qbezier.cpp
+++ b/src/gui/painting/qbezier.cpp
@@ -62,10 +62,10 @@ QT_BEGIN_NAMESPACE
#endif
#ifndef M_SQRT2
-#define M_SQRT2 1.41421356237309504880
+#define M_SQRT2 qreal(1.41421356237309504880)
#endif
-#define log2(x) (qLn(x)/qLn(2.))
+#define log2(x) (qLn(qreal(x))/qLn(qreal(2.)))
static inline qreal log4(qreal x)
{
@@ -132,7 +132,7 @@ static inline void flattenBezierWithoutInflections(QBezier &bez,
qreal d = qAbs(dx * (bez.y3 - bez.y2) - dy * (bez.x3 - bez.x2));
- qreal t = qSqrt(4. / 3. * normalized * flatness / d);
+ qreal t = qSqrt(qreal(4.) / qreal(3.) * normalized * flatness / d);
if (t > 1 || qFuzzyIsNull(t - (qreal)1.))
break;
bez.parameterSplitLeft(t, &left);
@@ -267,7 +267,7 @@ void QBezier::addToPolygonMixed(QPolygonF *polygon) const
qAbs(b->x1 - b->x3) + qAbs(b->y1 - b->y3);
l = 1.;
}
- if (d < .5*l || b == beziers + 31) {
+ if (d < qreal(.5)*l || b == beziers + 31) {
// good enough, we pop it off and add the endpoint
polygon->append(QPointF(b->x4, b->y4));
--b;
@@ -327,8 +327,8 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse
const qreal o2 = offset*offset;
const qreal max_dist_line = threshold*offset*offset;
const qreal max_dist_normal = threshold*offset;
- const qreal spacing = 0.25;
- for (qreal i = spacing; i < 0.99; i += spacing) {
+ const qreal spacing = qreal(0.25);
+ for (qreal i = spacing; i < qreal(0.99); i += spacing) {
QPointF p1 = b1->pointAt(i);
QPointF p2 = b2->pointAt(i);
qreal d = (p1.x() - p2.x())*(p1.x() - p2.x()) + (p1.y() - p2.y())*(p1.y() - p2.y());
@@ -337,7 +337,7 @@ static ShiftResult good_offset(const QBezier *b1, const QBezier *b2, qreal offse
QPointF normalPoint = b1->normalVector(i);
qreal l = qAbs(normalPoint.x()) + qAbs(normalPoint.y());
- if (l != 0.) {
+ if (l != qreal(0.)) {
d = qAbs( normalPoint.x()*(p1.y() - p2.y()) - normalPoint.y()*(p1.x() - p2.x()) ) / l;
if (d > max_dist_normal)
return Split;
@@ -418,14 +418,14 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr
}
QRectF b = orig->bounds();
- if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) {
+ if (np == 4 && b.width() < qreal(.1)*offset && b.height() < qreal(.1)*offset) {
qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) +
(orig->y1 - orig->y2)*(orig->y1 - orig->y1) *
(orig->x3 - orig->x4)*(orig->x3 - orig->x4) +
(orig->y3 - orig->y4)*(orig->y3 - orig->y4);
qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) +
(orig->y1 - orig->y2)*(orig->y3 - orig->y4);
- if (dot < 0 && dot*dot < 0.8*l)
+ if (dot < 0 && dot*dot < qreal(0.8)*l)
// the points are close and reverse dirction. Approximate the whole
// thing by a semi circle
return Circle;
@@ -444,7 +444,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr
QPointF normal_sum = prev_normal + next_normal;
- qreal r = 1.0 + prev_normal.x() * next_normal.x()
+ qreal r = qreal(1.0) + prev_normal.x() * next_normal.x()
+ prev_normal.y() * next_normal.y();
if (qFuzzyIsNull(r)) {
@@ -468,7 +468,7 @@ static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qr
// This value is used to determine the length of control point vectors
// when approximating arc segments as curves. The factor is multiplied
// with the radius of the circle.
-#define KAPPA 0.5522847498
+#define KAPPA qreal(0.5522847498)
static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
@@ -490,32 +490,32 @@ static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y());
qreal angles[2];
- qreal sign = 1.;
+ qreal sign = qreal(1.);
for (int i = 0; i < 2; ++i) {
qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y();
- if (cos_a > 1.)
- cos_a = 1.;
- if (cos_a < -1.)
+ if (cos_a > qreal(1.))
+ cos_a = qreal(1.);
+ if (cos_a < qreal(-1.))
cos_a = -1;
- angles[i] = acos(cos_a)/Q_PI;
+ angles[i] = qAcos(cos_a)/Q_PI;
}
- if (angles[0] + angles[1] > 1.) {
+ if (angles[0] + angles[1] > qreal(1.)) {
// more than 180 degrees
normals[1] = -normals[1];
- angles[0] = 1. - angles[0];
- angles[1] = 1. - angles[1];
- sign = -1.;
+ angles[0] = qreal(1.) - angles[0];
+ angles[1] = qreal(1.) - angles[1];
+ sign = qreal(-1.);
}
QPointF circle[3];
circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset;
- circle[1] = QPointF(0.5*(b->x1 + b->x4), 0.5*(b->y1 + b->y4)) + normals[1]*offset;
+ circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset;
circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset;
for (int i = 0; i < 2; ++i) {
- qreal kappa = 2.*KAPPA * sign * offset * angles[i];
+ qreal kappa = qreal(2.)*KAPPA * sign * offset * angles[i];
o->x1 = circle[i].x();
o->y1 = circle[i].y();
@@ -695,7 +695,7 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth
if (deptha > 0) {
QBezier A[2];
a.split(&A[0], &A[1]);
- qreal tmid = (t0+t1)*0.5;
+ qreal tmid = (t0+t1)*qreal(0.5);
//qDebug()<<"\t1)"<<A[0];
//qDebug()<<"\t2)"<<A[1];
deptha--;
@@ -704,7 +704,7 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth
b.split(&B[0], &B[1]);
//qDebug()<<"\t3)"<<B[0];
//qDebug()<<"\t4)"<<B[1];
- qreal umid = (u0+u1)*0.5;
+ qreal umid = (u0+u1)*qreal(0.5);
depthb--;
if (IntersectBB(A[0], B[0])) {
//fprintf(stderr, "\t 1 from %d\n", currentD);
@@ -756,7 +756,7 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth
if (depthb > 0) {
QBezier B[2];
b.split(&B[0], &B[1]);
- qreal umid = (u0 + u1)*0.5;
+ qreal umid = (u0 + u1)*qreal(0.5);
depthb--;
if (IntersectBB(a, B[0])) {
//fprintf(stderr, "\t 7 from %d\n", currentD);
@@ -783,13 +783,13 @@ static bool RecursivelyIntersect(const QBezier &a, qreal t0, qreal t1, int depth
qreal xmk = b.x1 - a.x1;
qreal ymk = b.y1 - a.y1;
qreal det = xnm * ylk - ynm * xlk;
- if (1.0 + det == 1.0) {
+ if (qreal(1.0) + det == qreal(1.0)) {
return false;
} else {
qreal detinv = 1.0 / det;
qreal rs = (xnm * ymk - ynm *xmk) * detinv;
qreal rt = (xlk * ymk - ylk * xmk) * detinv;
- if ((rs < 0.0) || (rs > 1.0) || (rt < 0.0) || (rt > 1.0))
+ if ((rs < qreal(0.0)) || (rs > qreal(1.0)) || (rt < qreal(0.0)) || (rt > qreal(1.0)))
return false;
if (t) {
@@ -816,17 +816,17 @@ bool QBezier::findIntersections(const QBezier &a, const QBezier &b,
QVector<QPair<qreal, qreal> > *t)
{
if (IntersectBB(a, b)) {
- QPointF la1(fabs((a.x3 - a.x2) - (a.x2 - a.x1)),
- fabs((a.y3 - a.y2) - (a.y2 - a.y1)));
- QPointF la2(fabs((a.x4 - a.x3) - (a.x3 - a.x2)),
- fabs((a.y4 - a.y3) - (a.y3 - a.y2)));
+ QPointF la1(qFabs((a.x3 - a.x2) - (a.x2 - a.x1)),
+ qFabs((a.y3 - a.y2) - (a.y2 - a.y1)));
+ QPointF la2(qFabs((a.x4 - a.x3) - (a.x3 - a.x2)),
+ qFabs((a.y4 - a.y3) - (a.y3 - a.y2)));
QPointF la;
if (la1.x() > la2.x()) la.setX(la1.x()); else la.setX(la2.x());
if (la1.y() > la2.y()) la.setY(la1.y()); else la.setY(la2.y());
- QPointF lb1(fabs((b.x3 - b.x2) - (b.x2 - b.x1)),
- fabs((b.y3 - b.y2) - (b.y2 - b.y1)));
- QPointF lb2(fabs((b.x4 - b.x3) - (b.x3 - b.x2)),
- fabs((b.y4 - b.y3) - (b.y3 - b.y2)));
+ QPointF lb1(qFabs((b.x3 - b.x2) - (b.x2 - b.x1)),
+ qFabs((b.y3 - b.y2) - (b.y2 - b.y1)));
+ QPointF lb2(qFabs((b.x4 - b.x3) - (b.x3 - b.x2)),
+ qFabs((b.y4 - b.y3) - (b.y3 - b.y2)));
QPointF lb;
if (lb1.x() > lb2.x()) lb.setX(lb1.x()); else lb.setX(lb2.x());
if (lb1.y() > lb2.y()) lb.setY(lb1.y()); else lb.setY(lb2.y());
@@ -836,27 +836,27 @@ bool QBezier::findIntersections(const QBezier &a, const QBezier &b,
else
l0 = la.y();
int ra;
- if (l0 * 0.75 * M_SQRT2 + 1.0 == 1.0)
+ if (l0 * qreal(0.75) * M_SQRT2 + qreal(1.0) == qreal(1.0))
ra = 0;
else
- ra = qCeil(log4(M_SQRT2 * 6.0 / 8.0 * INV_EPS * l0));
+ ra = qCeil(log4(M_SQRT2 * qreal(6.0) / qreal(8.0) * INV_EPS * l0));
if (lb.x() > lb.y())
l0 = lb.x();
else
l0 = lb.y();
int rb;
- if (l0 * 0.75 * M_SQRT2 + 1.0 == 1.0)
+ if (l0 * qreal(0.75) * M_SQRT2 + qreal(1.0) == qreal(1.0))
rb = 0;
else
- rb = qCeil(log4(M_SQRT2 * 6.0 / 8.0 * INV_EPS * l0));
+ rb = qCeil(log4(M_SQRT2 * qreal(6.0) / qreal(8.0) * INV_EPS * l0));
// if qreal is float then halve the number of subdivisions
if (sizeof(qreal) == 4) {
- ra /= 2;
- rb /= 2;
+ ra *= qreal(0.5);
+ rb *= qreal(0.5);
}
- return RecursivelyIntersect(a, 0., 1., ra, b, 0., 1., rb, t);
+ return RecursivelyIntersect(a, qreal(0.), qreal(1.), ra, b, qreal(0.), qreal(1.), rb, t);
}
//Don't sort here because it breaks the orders of corresponding
@@ -934,7 +934,7 @@ QVector< QList<QBezier> > QBezier::splitAtIntersections(QBezier &b)
qreal QBezier::length(qreal error) const
{
- qreal length = 0.0;
+ qreal length = qreal(0.0);
addIfClose(&length, error);
@@ -945,7 +945,7 @@ void QBezier::addIfClose(qreal *length, qreal error) const
{
QBezier left, right; /* bez poly splits */
- qreal len = 0.0; /* arc length */
+ qreal len = qreal(0.0); /* arc length */
qreal chord; /* chord length */
len = len + QLineF(QPointF(x1, y1),QPointF(x2, y2)).length();
@@ -988,7 +988,7 @@ qreal QBezier::tForY(qreal t0, qreal t1, qreal y) const
qreal lt = t0;
qreal dt;
do {
- qreal t = 0.5 * (t0 + t1);
+ qreal t = qreal(0.5) * (t0 + t1);
qreal a, b, c, d;
QBezier::coefficients(t, a, b, c, d);
@@ -1054,15 +1054,15 @@ int QBezier::stationaryYPoints(qreal &t0, qreal &t1) const
qreal QBezier::tAtLength(qreal l) const
{
qreal len = length();
- qreal t = 1.0;
- const qreal error = (qreal)0.01;
+ qreal t = qreal(1.0);
+ const qreal error = qreal(0.01);
if (l > len || qFuzzyCompare(l, len))
return t;
- t *= 0.5;
+ t *= qreal(0.5);
//int iters = 0;
//qDebug()<<"LEN is "<<l<<len;
- qreal lastBigger = 1.;
+ qreal lastBigger = qreal(1.);
while (1) {
//qDebug()<<"\tt is "<<t;
QBezier right = *this;
@@ -1073,10 +1073,10 @@ qreal QBezier::tAtLength(qreal l) const
break;
if (lLen < l) {
- t += (lastBigger - t)*.5;
+ t += (lastBigger - t)*qreal(.5);
} else {
lastBigger = t;
- t -= t*.5;
+ t -= t*qreal(.5);
}
//++iters;
}
@@ -1120,7 +1120,7 @@ static inline void bindInflectionPoint(const QBezier &bez, const qreal t,
qreal ey = 3 * (right.y2 - right.y3);
qreal s4 = qAbs(6 * (ey * ax - ex * ay) / qSqrt(ex * ex + ey * ey)) + 0.00001f;
- qreal tf = pow(qreal(9 * flatness / s4), qreal(1./3.));
+ qreal tf = qPow(qreal(9 * flatness / s4), qreal(1.)/qreal(3.));
*tMinus = t - (1 - t) * tf;
*tPlus = t + (1 - t) * tf;
}
diff --git a/src/gui/painting/qbezier_p.h b/src/gui/painting/qbezier_p.h
index 7dbd0c2..4cdb0c8 100644
--- a/src/gui/painting/qbezier_p.h
+++ b/src/gui/painting/qbezier_p.h
@@ -83,7 +83,7 @@ public:
void addToPolygonIterative(QPolygonF *p) const;
void addToPolygonMixed(QPolygonF *p) const;
QRectF bounds() const;
- qreal length(qreal error = 0.01) const;
+ qreal length(qreal error = qreal(0.01)) const;
void addIfClose(qreal *length, qreal error) const;
qreal tAtLength(qreal len) const;
@@ -122,13 +122,14 @@ public:
inline QPointF QBezier::midPoint() const
{
- return QPointF((x1 + x4 + 3*(x2 + x3))/8., (y1 + y4 + 3*(y2 + y3))/8.);
+ const qreal inv_8 = 1 / qreal(8.);
+ return QPointF((x1 + x4 + 3*(x2 + x3))*inv_8, (y1 + y4 + 3*(y2 + y3))*inv_8);
}
inline QLineF QBezier::midTangent() const
{
QPointF mid = midPoint();
- QLineF dir(QLineF(x1, y1, x2, y2).pointAt(0.5), QLineF(x3, y3, x4, y4).pointAt(0.5));
+ QLineF dir(QLineF(x1, y1, x2, y2).pointAt(qreal(0.5)), QLineF(x3, y3, x4, y4).pointAt(qreal(0.5)));
return QLineF(mid.x() - dir.dx(), mid.y() - dir.dy(),
mid.x() + dir.dx(), mid.y() + dir.dy());
}
@@ -155,13 +156,13 @@ inline QLineF QBezier::endTangent() const
inline void QBezier::coefficients(qreal t, qreal &a, qreal &b, qreal &c, qreal &d)
{
- qreal m_t = 1. - t;
+ qreal m_t = qreal(1.) - t;
b = m_t * m_t;
c = t * t;
d = c * t;
a = b * m_t;
- b *= 3. * t;
- c *= 3. * m_t;
+ b *= qreal(3.) * t;
+ c *= qreal(3.) * m_t;
}
inline QPointF QBezier::pointAt(qreal t) const
@@ -174,7 +175,7 @@ inline QPointF QBezier::pointAt(qreal t) const
return QPointF(a*x1 + b*x2 + c*x3 + d*x4, a*y1 + b*y2 + c*y3 + d*y4);
#else
// numerically more stable:
- qreal m_t = 1. - t;
+ qreal m_t = qreal(1.) - t;
qreal a = x1*m_t + x2*t;
qreal b = x2*m_t + x3*t;
qreal c = x3*m_t + x4*t;
@@ -193,7 +194,7 @@ inline QPointF QBezier::pointAt(qreal t) const
inline QPointF QBezier::normalVector(qreal t) const
{
- qreal m_t = 1. - t;
+ qreal m_t = qreal(1.) - t;
qreal a = m_t * m_t;
qreal b = t * m_t;
qreal c = t * t;
@@ -205,7 +206,7 @@ inline QPointF QBezier::derivedAt(qreal t) const
{
// p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 * t^2) * p2 + t^2 * p3)
- qreal m_t = 1. - t;
+ qreal m_t = qreal(1.) - t;
qreal d = t * t;
qreal a = -m_t * m_t;
@@ -218,7 +219,7 @@ inline QPointF QBezier::derivedAt(qreal t) const
inline QPointF QBezier::secondDerivedAt(qreal t) const
{
- qreal a = 2. - 2. * t;
+ qreal a = qreal(2.) - qreal(2.) * t;
qreal b = -4 + 6 * t;
qreal c = 2 - 6 * t;
qreal d = 2 * t;
@@ -232,23 +233,23 @@ inline void QBezier::split(QBezier *firstHalf, QBezier *secondHalf) const
Q_ASSERT(firstHalf);
Q_ASSERT(secondHalf);
- qreal c = (x2 + x3)*.5;
- firstHalf->x2 = (x1 + x2)*.5;
- secondHalf->x3 = (x3 + x4)*.5;
+ qreal c = (x2 + x3)*qreal(.5);
+ firstHalf->x2 = (x1 + x2)*qreal(.5);
+ secondHalf->x3 = (x3 + x4)*qreal(.5);
firstHalf->x1 = x1;
secondHalf->x4 = x4;
- firstHalf->x3 = (firstHalf->x2 + c)*.5;
- secondHalf->x2 = (secondHalf->x3 + c)*.5;
- firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2)*.5;
+ firstHalf->x3 = (firstHalf->x2 + c)*qreal(.5);
+ secondHalf->x2 = (secondHalf->x3 + c)*qreal(.5);
+ firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2)*qreal(.5);
- c = (y2 + y3)/2;
- firstHalf->y2 = (y1 + y2)*.5;
- secondHalf->y3 = (y3 + y4)*.5;
+ c = (y2 + y3)*qreal(.5);
+ firstHalf->y2 = (y1 + y2)*qreal(.5);
+ secondHalf->y3 = (y3 + y4)*qreal(.5);
firstHalf->y1 = y1;
secondHalf->y4 = y4;
- firstHalf->y3 = (firstHalf->y2 + c)*.5;
- secondHalf->y2 = (secondHalf->y3 + c)*.5;
- firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*.5;
+ firstHalf->y3 = (firstHalf->y2 + c)*qreal(.5);
+ secondHalf->y2 = (secondHalf->y3 + c)*qreal(.5);
+ firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2)*qreal(.5);
}
inline void QBezier::parameterSplitLeft(qreal t, QBezier *left)
diff --git a/src/gui/painting/qblendfunctions.cpp b/src/gui/painting/qblendfunctions.cpp
index f8dd424..76d50db 100644
--- a/src/gui/painting/qblendfunctions.cpp
+++ b/src/gui/painting/qblendfunctions.cpp
@@ -223,8 +223,8 @@ void qt_scale_image_16bit(uchar *destPixels, int dbpl,
int h = ty2 - ty1;
int w = tx2 - tx1;
- const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1;
- const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1;
+ const int dstx = qCeil((tx1 + qreal(0.5) - qMin(targetRect.left(), targetRect.right())) * ix) - 1;
+ const int dsty = qCeil((ty1 + qreal(0.5) - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1;
quint32 basex = quint32((sx < 0 ? srcRect.right() : srcRect.left()) * 65536) + dstx;
quint32 srcy = quint32((sy < 0 ? srcRect.bottom() : srcRect.top()) * 65536) + dsty;
@@ -723,8 +723,8 @@ template <typename T> void qt_scale_image_32bit(uchar *destPixels, int dbpl,
int h = ty2 - ty1;
int w = tx2 - tx1;
- const int dstx = qCeil((tx1 + 0.5 - qMin(targetRect.left(), targetRect.right())) * ix) - 1;
- const int dsty = qCeil((ty1 + 0.5 - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1;
+ const int dstx = qCeil((tx1 + qreal(0.5) - qMin(targetRect.left(), targetRect.right())) * ix) - 1;
+ const int dsty = qCeil((ty1 + qreal(0.5) - qMin(targetRect.top(), targetRect.bottom())) * iy) - 1;
quint32 basex = quint32((sx < 0 ? srcRect.right() : srcRect.left()) * 65536) + dstx;
quint32 srcy = quint32((sy < 0 ? srcRect.bottom() : srcRect.top()) * 65536) + dsty;
@@ -818,8 +818,8 @@ void qt_transform_image_rasterize(DestT *destPixels, int dbpl,
qreal rightSlope = (bottomRight.x - topRight.x) / (bottomRight.y - topRight.y);
int dx_l = int(leftSlope * 0x10000);
int dx_r = int(rightSlope * 0x10000);
- int x_l = int((topLeft.x + (0.5 + fromY - topLeft.y) * leftSlope + 0.5) * 0x10000);
- int x_r = int((topRight.x + (0.5 + fromY - topRight.y) * rightSlope + 0.5) * 0x10000);
+ int x_l = int((topLeft.x + (qreal(0.5) + fromY - topLeft.y) * leftSlope + qreal(0.5)) * 0x10000);
+ int x_r = int((topRight.x + (qreal(0.5) + fromY - topRight.y) * rightSlope + qreal(0.5)) * 0x10000);
int fromX, toX, x1, x2, u, v, i, ii;
DestT *line;
@@ -996,7 +996,7 @@ void qt_transform_image(DestT *destPixels, int dbpl,
if (det == 0)
return;
- qreal invDet = 1.0 / det;
+ qreal invDet = qreal(1.0) / det;
qreal m11, m12, m21, m22, mdx, mdy;
m11 = (u.u * w.y - u.y * w.u) * invDet;
@@ -1010,8 +1010,8 @@ void qt_transform_image(DestT *destPixels, int dbpl,
int dvdx = int(m21 * 0x10000);
int dudy = int(m12 * 0x10000);
int dvdy = int(m22 * 0x10000);
- int u0 = qCeil((0.5 * m11 + 0.5 * m12 + mdx) * 0x10000) - 1;
- int v0 = qCeil((0.5 * m21 + 0.5 * m22 + mdy) * 0x10000) - 1;
+ int u0 = qCeil((qreal(0.5) * m11 + qreal(0.5) * m12 + mdx) * 0x10000) - 1;
+ int v0 = qCeil((qreal(0.5) * m21 + qreal(0.5) * m22 + mdy) * 0x10000) - 1;
int x1 = qFloor(sourceRect.left());
int y1 = qFloor(sourceRect.top());
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index cbfbba6..6982f22 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -1752,7 +1752,7 @@ static QPointF qt_radial_gradient_adapt_focal_point(const QPointF &center,
// We have a one pixel buffer zone to avoid numerical instability on the
// circle border
//### this is hacky because technically we should adjust based on current matrix
- const qreal compensated_radius = radius - radius * 0.001;
+ const qreal compensated_radius = radius - radius * qreal(0.001);
QLineF line(center, focalPoint);
if (line.length() > (compensated_radius))
line.setLength(compensated_radius);
diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp
index 4da993b..acbad3e 100644
--- a/src/gui/painting/qcolor.cpp
+++ b/src/gui/painting/qcolor.cpp
@@ -604,12 +604,13 @@ void QColor::getHsvF(qreal *h, qreal *s, qreal *v, qreal *a) const
return;
}
- *h = ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;
- *s = ct.ahsv.saturation / qreal(USHRT_MAX);
- *v = ct.ahsv.value / qreal(USHRT_MAX);
+ const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX);
+ *h = ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
+ *s = ct.ahsv.saturation * inv_USHRT_MAX;
+ *v = ct.ahsv.value * inv_USHRT_MAX;
if (a)
- *a = ct.ahsv.alpha / qreal(USHRT_MAX);
+ *a = ct.ahsv.alpha * inv_USHRT_MAX;
}
/*!
@@ -715,12 +716,13 @@ void QColor::getHslF(qreal *h, qreal *s, qreal *l, qreal *a) const
return;
}
- *h = ct.ahsl.hue == USHRT_MAX ? -1.0 : ct.ahsl.hue / 36000.0;
- *s = ct.ahsl.saturation / qreal(USHRT_MAX);
- *l = ct.ahsl.lightness / qreal(USHRT_MAX);
+ const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX);
+ *h = ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
+ *s = ct.ahsl.saturation * inv_USHRT_MAX;
+ *l = ct.ahsl.lightness * inv_USHRT_MAX;
if (a)
- *a = ct.ahsl.alpha / qreal(USHRT_MAX);
+ *a = ct.ahsl.alpha * inv_USHRT_MAX;
}
/*!
@@ -1300,7 +1302,7 @@ qreal QColor::hsvHueF() const
{
if (cspec != Invalid && cspec != Hsv)
return toHsv().hueF();
- return ct.ahsv.hue == USHRT_MAX ? -1.0 : ct.ahsv.hue / 36000.0;
+ return ct.ahsv.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsv.hue / qreal(36000.0);
}
/*!
@@ -1396,7 +1398,7 @@ qreal QColor::hslHueF() const
{
if (cspec != Invalid && cspec != Hsl)
return toHsl().hslHueF();
- return ct.ahsl.hue == USHRT_MAX ? -1.0 : ct.ahsl.hue / 36000.0;
+ return ct.ahsl.hue == USHRT_MAX ? qreal(-1.0) : ct.ahsl.hue / qreal(36000.0);
}
/*!
@@ -1547,6 +1549,8 @@ QColor QColor::toRgb() const
color.ct.argb.alpha = ct.argb.alpha;
color.ct.argb.pad = 0;
+ const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX);
+
switch (cspec) {
case Hsv:
{
@@ -1557,15 +1561,15 @@ QColor QColor::toRgb() const
}
// chromatic case
- const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / 6000.;
- const qreal s = ct.ahsv.saturation / qreal(USHRT_MAX);
- const qreal v = ct.ahsv.value / qreal(USHRT_MAX);
+ const qreal h = ct.ahsv.hue == 36000 ? 0 : ct.ahsv.hue / qreal(6000.);
+ const qreal s = ct.ahsv.saturation * inv_USHRT_MAX;
+ const qreal v = ct.ahsv.value * inv_USHRT_MAX;
const int i = int(h);
const qreal f = h - i;
- const qreal p = v * (1.0 - s);
+ const qreal p = v * (qreal(1.0) - s);
if (i & 1) {
- const qreal q = v * (1.0 - (s * f));
+ const qreal q = v * (qreal(1.0) - (s * f));
switch (i) {
case 1:
@@ -1585,7 +1589,7 @@ QColor QColor::toRgb() const
break;
}
} else {
- const qreal t = v * (1.0 - (s * (1.0 - f)));
+ const qreal t = v * (qreal(1.0) - (s * (qreal(1.0) - f)));
switch (i) {
case 0:
@@ -1617,9 +1621,9 @@ QColor QColor::toRgb() const
color.ct.argb.red = color.ct.argb.green = color.ct.argb.blue = 0;
} else {
// chromatic case
- const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / 36000.;
- const qreal s = ct.ahsl.saturation / qreal(USHRT_MAX);
- const qreal l = ct.ahsl.lightness / qreal(USHRT_MAX);
+ const qreal h = ct.ahsl.hue == 36000 ? 0 : ct.ahsl.hue / qreal(36000.);
+ const qreal s = ct.ahsl.saturation * inv_USHRT_MAX;
+ const qreal l = ct.ahsl.lightness * inv_USHRT_MAX;
qreal temp2;
if (l < qreal(0.5))
@@ -1656,14 +1660,14 @@ QColor QColor::toRgb() const
}
case Cmyk:
{
- const qreal c = ct.acmyk.cyan / qreal(USHRT_MAX);
- const qreal m = ct.acmyk.magenta / qreal(USHRT_MAX);
- const qreal y = ct.acmyk.yellow / qreal(USHRT_MAX);
- const qreal k = ct.acmyk.black / qreal(USHRT_MAX);
-
- color.ct.argb.red = qRound((1.0 - (c * (1.0 - k) + k)) * USHRT_MAX);
- color.ct.argb.green = qRound((1.0 - (m * (1.0 - k) + k)) * USHRT_MAX);
- color.ct.argb.blue = qRound((1.0 - (y * (1.0 - k) + k)) * USHRT_MAX);
+ const qreal c = ct.acmyk.cyan * inv_USHRT_MAX;
+ const qreal m = ct.acmyk.magenta * inv_USHRT_MAX;
+ const qreal y = ct.acmyk.yellow * inv_USHRT_MAX;
+ const qreal k = ct.acmyk.black * inv_USHRT_MAX;
+
+ color.ct.argb.red = qRound((qreal(1.0) - (c * (qreal(1.0) - k) + k)) * USHRT_MAX);
+ color.ct.argb.green = qRound((qreal(1.0) - (m * (qreal(1.0) - k) + k)) * USHRT_MAX);
+ color.ct.argb.blue = qRound((qreal(1.0) - (y * (qreal(1.0) - k) + k)) * USHRT_MAX);
break;
}
default:
@@ -1697,9 +1701,10 @@ QColor QColor::toHsv() const
color.ct.ahsv.alpha = ct.argb.alpha;
color.ct.ahsv.pad = 0;
- const qreal r = ct.argb.red / qreal(USHRT_MAX);
- const qreal g = ct.argb.green / qreal(USHRT_MAX);
- const qreal b = ct.argb.blue / qreal(USHRT_MAX);
+ const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX);
+ const qreal r = ct.argb.red * inv_USHRT_MAX;
+ const qreal g = ct.argb.green * inv_USHRT_MAX;
+ const qreal b = ct.argb.blue * inv_USHRT_MAX;
const qreal max = Q_MAX_3(r, g, b);
const qreal min = Q_MIN_3(r, g, b);
const qreal delta = max - min;
@@ -1715,15 +1720,15 @@ QColor QColor::toHsv() const
if (qFuzzyCompare(r, max)) {
hue = ((g - b) /delta);
} else if (qFuzzyCompare(g, max)) {
- hue = (2.0 + (b - r) / delta);
+ hue = (qreal(2.0) + (b - r) / delta);
} else if (qFuzzyCompare(b, max)) {
- hue = (4.0 + (r - g) / delta);
+ hue = (qreal(4.0) + (r - g) / delta);
} else {
Q_ASSERT_X(false, "QColor::toHsv", "internal error");
}
- hue *= 60.0;
- if (hue < 0.0)
- hue += 360.0;
+ hue *= qreal(60.0);
+ if (hue < qreal(0.0))
+ hue += qreal(360.0);
color.ct.ahsv.hue = qRound(hue * 100);
}
@@ -1804,9 +1809,10 @@ QColor QColor::toCmyk() const
color.ct.acmyk.alpha = ct.argb.alpha;
// rgb -> cmy
- const qreal r = ct.argb.red / qreal(USHRT_MAX);
- const qreal g = ct.argb.green / qreal(USHRT_MAX);
- const qreal b = ct.argb.blue / qreal(USHRT_MAX);
+ const qreal inv_USHRT_MAX = 1 / qreal(USHRT_MAX);
+ const qreal r = ct.argb.red * inv_USHRT_MAX;
+ const qreal g = ct.argb.green * inv_USHRT_MAX;
+ const qreal b = ct.argb.blue * inv_USHRT_MAX;
qreal c = 1.0 - r;
qreal m = 1.0 - g;
qreal y = 1.0 - b;
@@ -1815,9 +1821,10 @@ QColor QColor::toCmyk() const
const qreal k = qMin(c, qMin(m, y));
if (!qFuzzyIsNull(k - 1)) {
- c = (c - k) / (1.0 - k);
- m = (m - k) / (1.0 - k);
- y = (y - k) / (1.0 - k);
+ const qreal div_by_one_minus_k = 1 / (qreal(1.0) - k);
+ c = (c - k) * div_by_one_minus_k;
+ m = (m - k) * div_by_one_minus_k;
+ y = (y - k) * div_by_one_minus_k;
}
color.ct.acmyk.cyan = qRound(c * USHRT_MAX);
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index 41602a1..b9f439e 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -565,8 +565,8 @@ const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const
int image_width = data->texture.width;
int image_height = data->texture.height;
- const qreal cx = x + 0.5;
- const qreal cy = y + 0.5;
+ const qreal cx = x + qreal(0.5);
+ const qreal cy = y + qreal(0.5);
const uint *end = buffer + length;
uint *b = buffer;
@@ -670,8 +670,8 @@ const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *
int image_width = data->texture.width;
int image_height = data->texture.height;
- const qreal cx = x + 0.5;
- const qreal cy = y + 0.5;
+ const qreal cx = x + qreal(0.5);
+ const qreal cy = y + qreal(0.5);
const uint *end = buffer + length;
uint *b = buffer;
@@ -747,8 +747,8 @@ const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *
while (b < end) {
const qreal iw = fw == 0 ? 1 : 1 / fw;
- const qreal px = fx * iw - 0.5;
- const qreal py = fy * iw - 0.5;
+ const qreal px = fx * iw - qreal(0.5);
+ const qreal py = fy * iw - qreal(0.5);
int x1 = int(px) - (px < 0);
int x2 = x1 + 1;
@@ -927,7 +927,7 @@ static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = {
static inline uint qt_gradient_pixel(const QGradientData *data, qreal pos)
{
- int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + 0.5);
+ int ipos = int(pos * (GRADIENT_STOPTABLE_SIZE - 1) + qreal(0.5));
// calculate the actual offset.
if (ipos < 0 || ipos >= GRADIENT_STOPTABLE_SIZE) {
@@ -1008,8 +1008,8 @@ static const uint * QT_FASTCALL fetchLinearGradient(uint *buffer, const Operator
if (op->linear.l == 0) {
t = inc = 0;
} else {
- rx = data->m21 * (y + 0.5) + data->m11 * (x + 0.5) + data->dx;
- ry = data->m22 * (y + 0.5) + data->m12 * (x + 0.5) + data->dy;
+ rx = data->m21 * (y + qreal(0.5)) + data->m11 * (x + qreal(0.5)) + data->dx;
+ ry = data->m22 * (y + qreal(0.5)) + data->m12 * (x + qreal(0.5)) + data->dy;
t = op->linear.dx*rx + op->linear.dy*ry + op->linear.off;
inc = op->linear.dx * data->m11 + op->linear.dy * data->m12;
affine = !data->m13 && !data->m23;
@@ -1045,7 +1045,7 @@ static const uint * QT_FASTCALL fetchLinearGradient(uint *buffer, const Operator
}
}
} else { // fall back to float math here as well
- qreal rw = data->m23 * (y + 0.5) + data->m13 * (x + 0.5) + data->m33;
+ qreal rw = data->m23 * (y + qreal(0.5)) + data->m13 * (x + qreal(0.5)) + data->m33;
while (buffer < end) {
qreal x = rx/rw;
qreal y = ry/rw;
@@ -1092,10 +1092,10 @@ static const uint * QT_FASTCALL fetchRadialGradient(uint *buffer, const Operator
int y, int x, int length)
{
const uint *b = buffer;
- qreal rx = data->m21 * (y + 0.5)
- + data->dx + data->m11 * (x + 0.5);
- qreal ry = data->m22 * (y + 0.5)
- + data->dy + data->m12 * (x + 0.5);
+ qreal rx = data->m21 * (y + qreal(0.5))
+ + data->dx + data->m11 * (x + qreal(0.5));
+ qreal ry = data->m22 * (y + qreal(0.5))
+ + data->dy + data->m12 * (x + qreal(0.5));
bool affine = !data->m13 && !data->m23;
//qreal r = data->gradient.radial.radius;
@@ -1141,8 +1141,8 @@ static const uint * QT_FASTCALL fetchRadialGradient(uint *buffer, const Operator
++buffer;
}
} else {
- qreal rw = data->m23 * (y + 0.5)
- + data->m33 + data->m13 * (x + 0.5);
+ qreal rw = data->m23 * (y + qreal(0.5))
+ + data->m33 + data->m13 * (x + qreal(0.5));
if (!rw)
rw = 1;
while (buffer < end) {
@@ -1171,10 +1171,10 @@ static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operato
int y, int x, int length)
{
const uint *b = buffer;
- qreal rx = data->m21 * (y + 0.5)
- + data->dx + data->m11 * (x + 0.5);
- qreal ry = data->m22 * (y + 0.5)
- + data->dy + data->m12 * (x + 0.5);
+ qreal rx = data->m21 * (y + qreal(0.5))
+ + data->dx + data->m11 * (x + qreal(0.5));
+ qreal ry = data->m22 * (y + qreal(0.5))
+ + data->dy + data->m12 * (x + qreal(0.5));
bool affine = !data->m13 && !data->m23;
const uint *end = buffer + length;
@@ -1182,25 +1182,25 @@ static const uint * QT_FASTCALL fetchConicalGradient(uint *buffer, const Operato
rx -= data->gradient.conical.center.x;
ry -= data->gradient.conical.center.y;
while (buffer < end) {
- qreal angle = atan2(ry, rx) + data->gradient.conical.angle;
+ qreal angle = qAtan2(ry, rx) + data->gradient.conical.angle;
- *buffer = qt_gradient_pixel(&data->gradient, 1 - angle / (2*Q_PI));
+ *buffer = qt_gradient_pixel(&data->gradient, 1 - angle / Q_2PI);
rx += data->m11;
ry += data->m12;
++buffer;
}
} else {
- qreal rw = data->m23 * (y + 0.5)
- + data->m33 + data->m13 * (x + 0.5);
+ qreal rw = data->m23 * (y + qreal(0.5))
+ + data->m33 + data->m13 * (x + qreal(0.5));
if (!rw)
rw = 1;
while (buffer < end) {
- qreal angle = atan2(ry/rw - data->gradient.conical.center.x,
+ qreal angle = qAtan2(ry/rw - data->gradient.conical.center.x,
rx/rw - data->gradient.conical.center.y)
+ data->gradient.conical.angle;
- *buffer = qt_gradient_pixel(&data->gradient, 1. - angle / (2*Q_PI));
+ *buffer = qt_gradient_pixel(&data->gradient, qreal(1.) - angle / Q_2PI);
rx += data->m11;
ry += data->m12;
@@ -5168,8 +5168,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
int x = int((data->m21 * cy
+ data->m11 * cx + data->dx) * fixed_scale) - half_point;
@@ -5243,8 +5243,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
qreal x = data->m21 * cy + data->m11 * cx + data->dx;
qreal y = data->m22 * cy + data->m12 * cx + data->dy;
@@ -5258,8 +5258,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const
uint *b = buffer;
while (b < end) {
const qreal iw = w == 0 ? 1 : 1 / w;
- const qreal px = x * iw - 0.5;
- const qreal py = y * iw - 0.5;
+ const qreal px = x * iw - qreal(0.5);
+ const qreal py = y * iw - qreal(0.5);
int x1 = int(px) - (px < 0);
int x2 = x1 + 1;
@@ -5670,8 +5670,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count,
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
int x = int((data->m21 * cy
+ data->m11 * cx + data->dx) * fixed_scale) - half_point;
@@ -5753,8 +5753,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count,
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
qreal x = data->m21 * cy + data->m11 * cx + data->dx;
qreal y = data->m22 * cy + data->m12 * cx + data->dy;
@@ -5768,8 +5768,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count,
uint *b = buffer;
while (b < end) {
const qreal iw = w == 0 ? 1 : 1 / w;
- const qreal px = x * iw - 0.5;
- const qreal py = y * iw - 0.5;
+ const qreal px = x * iw - qreal(0.5);
+ const qreal py = y * iw - qreal(0.5);
int x1 = int(px) - (px < 0);
int x2 = x1 + 1;
@@ -5861,8 +5861,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *s
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
int x = int((data->m21 * cy
+ data->m11 * cx + data->dx) * fixed_scale);
@@ -5909,8 +5909,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *s
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
qreal x = data->m21 * cy + data->m11 * cx + data->dx;
qreal y = data->m22 * cy + data->m12 * cx + data->dy;
@@ -6261,8 +6261,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QS
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
int x = int((data->m21 * cy
+ data->m11 * cx + data->dx) * fixed_scale);
@@ -6313,8 +6313,8 @@ Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QS
uint *target = ((uint *)t) + spans->x;
uint *image_bits = (uint *)data->texture.imageData;
- const qreal cx = spans->x + 0.5;
- const qreal cy = spans->y + 0.5;
+ const qreal cx = spans->x + qreal(0.5);
+ const qreal cy = spans->y + qreal(0.5);
qreal x = data->m21 * cy + data->m11 * cx + data->dx;
qreal y = data->m22 * cy + data->m12 * cx + data->dy;
@@ -6998,7 +6998,7 @@ static void qt_gradient_quint32(int count, const QSpan *spans, void *userData)
*/
const int gss = GRADIENT_STOPTABLE_SIZE - 1;
int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE);
- int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE));
+ int off = int((((linear.dy * (data->m22 * qreal(0.5) + data->dy) + linear.off) * gss) * FIXPT_SIZE));
while (count--) {
int y = spans->y;
@@ -7046,7 +7046,7 @@ static void qt_gradient_quint16(int count, const QSpan *spans, void *userData)
*/
const int gss = GRADIENT_STOPTABLE_SIZE - 1;
int yinc = int((linear.dy * data->m22 * gss) * FIXPT_SIZE);
- int off = int((((linear.dy * (data->m22 * 0.5 + data->dy) + linear.off) * gss) * FIXPT_SIZE));
+ int off = int((((linear.dy * (data->m22 * qreal(0.5) + data->dy) + linear.off) * gss) * FIXPT_SIZE));
uint oldColor = data->solid.color;
while (count--) {
@@ -7125,13 +7125,13 @@ void qt_build_pow_tables() {
#ifdef Q_WS_MAC
// decided by testing a few things on an iMac, should probably get this from the
// system...
- smoothing = 2.0;
+ smoothing = qreal(2.0);
#endif
#ifdef Q_WS_WIN
int winSmooth;
if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0))
- smoothing = winSmooth / 1000.0;
+ smoothing = winSmooth / qreal(1000.0);
#endif
#ifdef Q_WS_X11
@@ -7141,18 +7141,19 @@ void qt_build_pow_tables() {
qt_pow_rgb_invgamma[i] = uchar(i);
}
#else
+ const qreal inv_255 = 1 / qreal(255.0);
for (int i=0; i<256; ++i) {
- qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / qreal(255.0), smoothing) * 255));
- qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / qreal(255.), 1 / smoothing) * 255));
+ qt_pow_rgb_gamma[i] = uchar(qRound(qPow(i * inv_255, smoothing) * 255));
+ qt_pow_rgb_invgamma[i] = uchar(qRound(qPow(i * inv_255, 1 / smoothing) * 255));
}
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- const qreal gray_gamma = 2.31;
+ const qreal gray_gamma = qreal(2.31);
for (int i=0; i<256; ++i)
- qt_pow_gamma[i] = uint(qRound(pow(i / qreal(255.), gray_gamma) * 2047));
+ qt_pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047));
for (int i=0; i<2048; ++i)
- qt_pow_invgamma[i] = uchar(qRound(pow(i / 2047.0, 1 / gray_gamma) * 255));
+ qt_pow_invgamma[i] = uchar(qRound(qPow(i / qreal(2047.0), 1 / gray_gamma) * 255));
#endif
}
diff --git a/src/gui/painting/qdrawutil.cpp b/src/gui/painting/qdrawutil.cpp
index 1182b9a..be9061f 100644
--- a/src/gui/painting/qdrawutil.cpp
+++ b/src/gui/painting/qdrawutil.cpp
@@ -1180,46 +1180,48 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
for (int i = 2; i < rows - 1; ++i)
yTarget[i] = yTarget[i - 1] + dy;
+ const qreal inv_d_source_width = 1 / (qreal)d.source.width();
+ const qreal inv_d_source_height = 1 / (qreal)d.source.height();
// corners
if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { // top left
d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
d.source = QRectF(sourceRect.left(), sourceRect.top(), sourceMargins.left(), sourceMargins.top());
- d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
- d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width;
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height;
if (hints & QDrawBorderPixmap::OpaqueTopLeft)
opaqueData.append(d);
else
translucentData.append(d);
}
if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { // top right
- d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
- d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
+ d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1]));
+ d.point.setY(qreal(0.5) * (yTarget[1] + yTarget[0]));
d.source = QRectF(sourceCenterRight, sourceRect.top(), sourceMargins.right(), sourceMargins.top());
- d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
- d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width;
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height;
if (hints & QDrawBorderPixmap::OpaqueTopRight)
opaqueData.append(d);
else
translucentData.append(d);
}
if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { // bottom left
- d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
- d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
+ d.point.setX(qreal(0.5) * (xTarget[1] + xTarget[0]));
+ d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1]));
d.source = QRectF(sourceRect.left(), sourceCenterBottom, sourceMargins.left(), sourceMargins.bottom());
- d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
- d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width;
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height;
if (hints & QDrawBorderPixmap::OpaqueBottomLeft)
opaqueData.append(d);
else
translucentData.append(d);
}
if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { // bottom right
- d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
- d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
+ d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1]));
+ d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1]));
d.source = QRectF(sourceCenterRight, sourceCenterBottom, sourceMargins.right(), sourceMargins.bottom());
- d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
- d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width;
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height;
if (hints & QDrawBorderPixmap::OpaqueBottomRight)
opaqueData.append(d);
else
@@ -1231,11 +1233,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
if (targetMargins.top() > 0 && sourceMargins.top() > 0) { // top
QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData;
d.source = QRectF(sourceCenterLeft, sourceRect.top(), sourceCenterWidth, sourceMargins.top());
- d.point.setY(0.5 * (yTarget[1] + yTarget[0]));
- d.scaleX = dx / d.source.width();
- d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.source.height();
+ d.point.setY(qreal(0.5) * (yTarget[1] + yTarget[0]));
+ d.scaleX = dx * inv_d_source_width;
+ d.scaleY = qreal(yTarget[1] - yTarget[0]) * inv_d_source_height;
for (int i = 1; i < columns - 1; ++i) {
- d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i]));
data.append(d);
}
if (rules.horizontal == Qt::RepeatTile)
@@ -1244,11 +1246,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { // bottom
QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData;
d.source = QRectF(sourceCenterLeft, sourceCenterBottom, sourceCenterWidth, sourceMargins.bottom());;
- d.point.setY(0.5 * (yTarget[rows] + yTarget[rows - 1]));
- d.scaleX = dx / d.source.width();
- d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.source.height();
+ d.point.setY(qreal(0.5) * (yTarget[rows] + yTarget[rows - 1]));
+ d.scaleX = dx * inv_d_source_width;
+ d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) * inv_d_source_height;
for (int i = 1; i < columns - 1; ++i) {
- d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i]));
data.append(d);
}
if (rules.horizontal == Qt::RepeatTile)
@@ -1261,11 +1263,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
if (targetMargins.left() > 0 && sourceMargins.left() > 0) { // left
QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData;
d.source = QRectF(sourceRect.left(), sourceCenterTop, sourceMargins.left(), sourceCenterHeight);
- d.point.setX(0.5 * (xTarget[1] + xTarget[0]));
- d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.source.width();
- d.scaleY = dy / d.source.height();
+ d.point.setX(qreal(0.5) * (xTarget[1] + xTarget[0]));
+ d.scaleX = qreal(xTarget[1] - xTarget[0]) * inv_d_source_width;
+ d.scaleY = dy * inv_d_source_height;
for (int i = 1; i < rows - 1; ++i) {
- d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));
+ d.point.setY(qreal(0.5) * (yTarget[i + 1] + yTarget[i]));
data.append(d);
}
if (rules.vertical == Qt::RepeatTile)
@@ -1274,11 +1276,11 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
if (targetMargins.right() > 0 && sourceMargins.right() > 0) { // right
QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData;
d.source = QRectF(sourceCenterRight, sourceCenterTop, sourceMargins.right(), sourceCenterHeight);
- d.point.setX(0.5 * (xTarget[columns] + xTarget[columns - 1]));
- d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.source.width();
- d.scaleY = dy / d.source.height();
+ d.point.setX(qreal(0.5) * (xTarget[columns] + xTarget[columns - 1]));
+ d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) * inv_d_source_width;
+ d.scaleY = dy * inv_d_source_height;
for (int i = 1; i < rows - 1; ++i) {
- d.point.setY(0.5 * (yTarget[i + 1] + yTarget[i]));
+ d.point.setY(qreal(0.5) * (yTarget[i + 1] + yTarget[i]));
data.append(d);
}
if (rules.vertical == Qt::RepeatTile)
@@ -1290,16 +1292,16 @@ void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargin
if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) {
QDrawPixmapsDataArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData;
d.source = QRectF(sourceCenterLeft, sourceCenterTop, sourceCenterWidth, sourceCenterHeight);
- d.scaleX = dx / d.source.width();
- d.scaleY = dy / d.source.height();
+ d.scaleX = dx * inv_d_source_width;
+ d.scaleY = dy * inv_d_source_height;
qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX;
qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY;
for (int j = 1; j < rows - 1; ++j) {
- d.point.setY(0.5 * (yTarget[j + 1] + yTarget[j]));
+ d.point.setY(qreal(0.5) * (yTarget[j + 1] + yTarget[j]));
for (int i = 1; i < columns - 1; ++i) {
- d.point.setX(0.5 * (xTarget[i + 1] + xTarget[i]));
+ d.point.setX(qreal(0.5) * (xTarget[i + 1] + xTarget[i]));
data.append(d);
}
if (rules.horizontal == Qt::RepeatTile)
diff --git a/src/gui/painting/qmath_p.h b/src/gui/painting/qmath_p.h
index f4a3982..53ed8ab 100644
--- a/src/gui/painting/qmath_p.h
+++ b/src/gui/painting/qmath_p.h
@@ -54,13 +54,10 @@
//
#include <math.h>
+#include <private/qnumeric_p.h>
QT_BEGIN_NAMESPACE
-static const qreal Q_PI = qreal(3.14159265358979323846); // pi
-static const qreal Q_2PI = qreal(6.28318530717958647693); // 2*pi
-static const qreal Q_PI2 = qreal(1.57079632679489661923); // pi/2
-
QT_END_NAMESPACE
#endif // QMATH_P_H
diff --git a/src/gui/painting/qpaintbuffer.cpp b/src/gui/painting/qpaintbuffer.cpp
index 6b9d77c..a323a43 100644
--- a/src/gui/painting/qpaintbuffer.cpp
+++ b/src/gui/painting/qpaintbuffer.cpp
@@ -424,7 +424,7 @@ void QPaintBufferEngine::penChanged()
QPointF transformedWidth(penWidth, penWidth);
if (!pen.isCosmetic())
transformedWidth = painter()->transform().map(transformedWidth);
- buffer->penWidthAdjustment = transformedWidth.x() / 2.0;
+ buffer->penWidthAdjustment = transformedWidth.x() * qreal(0.5);
}
}
buffer->addCommand(QPaintBufferPrivate::Cmd_SetPen, pen);
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 8d0b961..e3c4fe5 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -126,7 +126,7 @@ void dumpClip(int width, int height, const QClipData *clip);
#define int_dim(pos, dim) (int(pos+dim) - int(pos))
// use the same rounding as in qrasterizer.cpp (6 bit fixed point)
-static const qreal aliasedCoordinateDelta = 0.5 - 0.015625;
+static const qreal aliasedCoordinateDelta = qreal(0.5) - qreal(0.015625);
#ifdef Q_WS_WIN
extern bool qt_cleartype_enabled;
@@ -1743,8 +1743,8 @@ void QRasterPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
if (lines[i].p1() == lines[i].p2()) {
if (s->lastPen.capStyle() != Qt::FlatCap) {
QPointF p = lines[i].p1();
- QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*0.5, p.y()),
- QPointF(p.x() + width*0.5, p.y())));
+ QLineF line = s->matrix.map(QLineF(QPointF(p.x() - width*qreal(0.5), p.y()),
+ QPointF(p.x() + width*qreal(0.5), p.y())));
d->rasterizer->rasterizeLine(line.p1(), line.p2(), 1);
}
continue;
@@ -1958,8 +1958,9 @@ static bool splitPolygon(const QPointF *points, int pointCount, QVector<QPointF>
QVector<const QPointF *> sorted;
sorted.reserve(pointCount);
- upper->reserve(pointCount * 3 / 4);
- lower->reserve(pointCount * 3 / 4);
+ const qreal three_quarters = qreal(3) / qreal(4);
+ upper->reserve(pointCount * three_quarters);
+ lower->reserve(pointCount * three_quarters);
for (int i = 0; i < pointCount; ++i)
sorted << points + i;
@@ -2336,13 +2337,13 @@ void QRasterPaintEngine::strokePolygonCosmetic(const QPoint *points, int pointCo
int x1 = points[pointCount-1].x() * m11 + dx;
int y1 = points[pointCount-1].y() * m22 + dy;
- qreal w = m13*points[pointCount-1].x() + m23*points[pointCount-1].y() + 1.;
+ qreal w = m13*points[pointCount-1].x() + m23*points[pointCount-1].y() + qreal(1.);
w = 1/w;
x1 = int(x1*w);
y1 = int(y1*w);
int x2 = points[0].x() * m11 + dx;
int y2 = points[0].y() * m22 + dy;
- w = m13*points[0].x() + m23*points[0].y() + 1.;
+ w = m13*points[0].x() + m23*points[0].y() + qreal(1.);
w = 1/w;
x2 = int(x2 * w);
y2 = int(y2 * w);
@@ -4867,7 +4868,7 @@ void QGradientCache::generateGradientColorTable(const QGradient& gradient, uint
uint next_color;
qreal incr = 1 / qreal(size); // the double increment.
- qreal dpos = 1.5 * incr; // current position in gradient stop list (0 to 1)
+ qreal dpos = qreal(1.5) * incr; // current position in gradient stop list (0 to 1)
// Up to first point
colorTable[pos++] = PREMUL(current_color);
@@ -5041,7 +5042,7 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
QPointF center = g->center();
conicalData.center.x = center.x();
conicalData.center.y = center.y();
- conicalData.angle = g->angle() * 2 * Q_PI / 360.0;
+ conicalData.angle = g->angle() * Q_2PI / qreal(360.0);
}
break;
@@ -5140,7 +5141,8 @@ void QSpanData::setupMatrix(const QTransform &matrix, int bilin)
{
QTransform delta;
// make sure we round off correctly in qdrawhelper.cpp
- delta.translate(1.0 / 65536, 1.0 / 65536);
+ const qreal inv_65536 = qreal(1.0) / 65536;
+ delta.translate(inv_65536, inv_65536);
QTransform inv = (delta * matrix).inverted();
m11 = inv.m11();
@@ -6049,9 +6051,9 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip,
const QFixed b = QFixed(rect.height()) >> 1;
QFixed d = b*b - (a*a*b) + ((a*a) >> 2);
#else
- const qreal a = qreal(rect.width()) / 2;
- const qreal b = qreal(rect.height()) / 2;
- qreal d = b*b - (a*a*b) + 0.25*a*a;
+ const qreal a = qreal(rect.width()) * qreal(0.5);
+ const qreal b = qreal(rect.height()) * qreal(0.5);
+ qreal d = b*b - (a*a*b) + qreal(0.25)*a*a;
#endif
int x = 0;
@@ -6079,7 +6081,7 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip,
d = b*b*(x + (QFixed(1) >> 1))*(x + (QFixed(1) >> 1))
+ a*a*((y - 1)*(y - 1) - b*b);
#else
- d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b);
+ d = b*b*(x + qreal(0.5))*(x + qreal(0.5)) + a*a*(qreal(y - 1)*qreal(y - 1) - b*b);
#endif
const int miny = rect.height() & 0x1;
while (y > miny) {
@@ -6150,4 +6152,4 @@ void dumpClip(int width, int height, const QClipData *clip)
#endif
-QT_END_NAMESPACE
+QT_END_NAMESPACE \ No newline at end of file
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp
index 9e21182..b3d7f08 100644
--- a/src/gui/painting/qpaintengineex.cpp
+++ b/src/gui/painting/qpaintengineex.cpp
@@ -727,8 +727,9 @@ void QPaintEngineEx::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yR
qreal y2 = rect.bottom();
if (mode == Qt::RelativeSize) {
- xRadius = xRadius * rect.width() / 200.;
- yRadius = yRadius * rect.height() / 200.;
+ const qreal inv_200 = 1 / qreal(200.);
+ xRadius = xRadius * rect.width() * inv_200;
+ yRadius = yRadius * rect.height() * inv_200;
}
xRadius = qMin(xRadius, rect.width() / 2);
@@ -842,7 +843,7 @@ void QPaintEngineEx::drawPoints(const QPointF *points, int pointCount)
for (int i=0; i<count; ++i) {
pts[++oset] = points[i].x();
pts[++oset] = points[i].y();
- pts[++oset] = points[i].x() + 0.001;
+ pts[++oset] = points[i].x() + qreal(0.001);
pts[++oset] = points[i].y();
}
QVectorPath path(pts, count * 2, qpaintengineex_line_types_16, QVectorPath::LinesHint);
@@ -852,7 +853,7 @@ void QPaintEngineEx::drawPoints(const QPointF *points, int pointCount)
}
} else {
for (int i=0; i<pointCount; ++i) {
- qreal pts[] = { points[i].x(), points[i].y(), points[i].x() + 0.001, points[i].y() };
+ qreal pts[] = { points[i].x(), points[i].y(), points[i].x() + qreal(0.001), points[i].y() };
QVectorPath path(pts, 2, 0);
stroke(path, pen);
}
@@ -873,7 +874,7 @@ void QPaintEngineEx::drawPoints(const QPoint *points, int pointCount)
for (int i=0; i<count; ++i) {
pts[++oset] = points[i].x();
pts[++oset] = points[i].y();
- pts[++oset] = points[i].x() + 0.001;
+ pts[++oset] = points[i].x() + qreal(0.001);
pts[++oset] = points[i].y();
}
QVectorPath path(pts, count * 2, qpaintengineex_line_types_16, QVectorPath::LinesHint);
@@ -883,7 +884,7 @@ void QPaintEngineEx::drawPoints(const QPoint *points, int pointCount)
}
} else {
for (int i=0; i<pointCount; ++i) {
- qreal pts[] = { points[i].x(), points[i].y(), points[i].x() + 0.001, points[i].y() };
+ qreal pts[] = { points[i].x(), points[i].y(), points[i].x() + qreal(0.001), points[i].y() };
QVectorPath path(pts, 2, 0);
stroke(path, pen);
}
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 09a4563..0cbdfbd 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -383,8 +383,8 @@ void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperatio
QPainterPath stroke = stroker.createStroke(originalPath);
strokeBounds = (stroke * state->matrix).boundingRect();
} else {
- strokeOffsetX = qAbs(penWidth * state->matrix.m11() / 2.0);
- strokeOffsetY = qAbs(penWidth * state->matrix.m22() / 2.0);
+ strokeOffsetX = qAbs(penWidth * state->matrix.m11() * qreal(0.5));
+ strokeOffsetY = qAbs(penWidth * state->matrix.m22() * qreal(0.5));
}
}
}
@@ -467,7 +467,7 @@ void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperatio
pt.end();
p.resetTransform();
p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
- p.setOpacity(0.5);
+ p.setOpacity(qreal(0.5));
p.fillRect(0, 0, image.width(), image.height(), QBrush(block));
}
#endif
@@ -3565,7 +3565,7 @@ void QPainter::drawPoints(const QPointF *points, int pointCount)
QPainterPath path;
for (int i=0; i<pointCount; ++i) {
path.moveTo(points[i].x(), points[i].y());
- path.lineTo(points[i].x() + 0.0001, points[i].y());
+ path.lineTo(points[i].x() + qreal(0.0001), points[i].y());
}
d->draw_helper(path, QPainterPrivate::StrokeDraw);
if (flat_pen)
@@ -3627,7 +3627,7 @@ void QPainter::drawPoints(const QPoint *points, int pointCount)
QPainterPath path;
for (int i=0; i<pointCount; ++i) {
path.moveTo(points[i].x(), points[i].y());
- path.lineTo(points[i].x() + 0.0001, points[i].y());
+ path.lineTo(points[i].x() + qreal(0.0001), points[i].y());
}
d->draw_helper(path, QPainterPrivate::StrokeDraw);
if (flat_pen)
@@ -4291,8 +4291,9 @@ void QPainter::drawArc(const QRectF &r, int a, int alen)
QRectF rect = r.normalized();
QPainterPath path;
- path.arcMoveTo(rect, a/16.0);
- path.arcTo(rect, a/16.0, alen/16.0);
+ const qreal inv_16 = 1 / qreal(16.0);
+ path.arcMoveTo(rect, a * inv_16);
+ path.arcTo(rect, a * inv_16, alen * inv_16);
strokePath(path, d->state->pen);
}
@@ -4361,8 +4362,9 @@ void QPainter::drawPie(const QRectF &r, int a, int alen)
QRectF rect = r.normalized();
QPainterPath path;
+ const qreal inv_16 = 1 / qreal(16.0);
path.moveTo(rect.center());
- path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/16.0, alen/16.0);
+ path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a * inv_16, alen * inv_16);
path.closeSubpath();
drawPath(path);
@@ -4423,8 +4425,9 @@ void QPainter::drawChord(const QRectF &r, int a, int alen)
QRectF rect = r.normalized();
QPainterPath path;
- path.arcMoveTo(rect, a/16.0);
- path.arcTo(rect, a/16.0, alen/16.0);
+ const qreal inv_16 = 1 / qreal(16.0);
+ path.arcMoveTo(rect, a * inv_16);
+ path.arcTo(rect, a * inv_16, alen * inv_16);
path.closeSubpath();
drawPath(path);
}
@@ -5926,7 +5929,7 @@ static QPainterPath generateWavyPath(qreal minWidth, qreal maxRadius, QPaintDevi
QPainterPath path;
bool up = true;
- const qreal radius = qMax(qreal(.5), qMin(qreal(1.25 * device->logicalDpiY() / qt_defaultDpi()), maxRadius));
+ const qreal radius = qMax(qreal(.5), qMin(qreal(1.25) * device->logicalDpiY() / qt_defaultDpi(), maxRadius));
qreal xs, ys;
int i = 0;
path.moveTo(0, radius);
@@ -6006,7 +6009,7 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
if (ti.flags & QTextItem::StrikeOut) {
QLineF strikeOutLine = line;
- strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
+ strikeOutLine.translate(qreal(0.), - fe->ascent().toReal() / qreal(3.));
painter->setPen(pen);
painter->drawLine(strikeOutLine);
}
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index 8133793..0f31cca 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -799,8 +799,9 @@ void QPainterPath::quadTo(const QPointF &c, const QPointF &e)
if (prev == c && c == e)
return;
- QPointF c1((prev.x() + 2*c.x()) / 3, (prev.y() + 2*c.y()) / 3);
- QPointF c2((e.x() + 2*c.x()) / 3, (e.y() + 2*c.y()) / 3);
+ const qreal inv_3 = 1 / qreal(3);
+ QPointF c1((prev.x() + 2*c.x()) * inv_3, (prev.y() + 2*c.y()) * inv_3);
+ QPointF c2((e.x() + 2*c.x()) * inv_3, (e.y() + 2*c.y()) * inv_3);
cubicTo(c1, c2, e);
}
@@ -1804,22 +1805,24 @@ static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y
return false;
if (p1 | p2) {
- qreal dx = x2 - x1;
- qreal dy = y2 - y1;
+ const qreal dx = x2 - x1;
+ const qreal dy = y2 - y1;
+ const qreal dx_dy_ratio = dx / dy;
+ const qreal dy_dx_ratio = dy / dx;
// clip x coordinates
if (x1 < left) {
- y1 += dy/dx * (left - x1);
+ y1 += dy_dx_ratio * (left - x1);
x1 = left;
} else if (x1 > right) {
- y1 -= dy/dx * (x1 - right);
+ y1 -= dy_dx_ratio * (x1 - right);
x1 = right;
}
if (x2 < left) {
- y2 += dy/dx * (left - x2);
+ y2 += dy_dx_ratio * (left - x2);
x2 = left;
} else if (x2 > right) {
- y2 -= dy/dx * (x2 - right);
+ y2 -= dy_dx_ratio * (x2 - right);
x2 = right;
}
@@ -1833,17 +1836,17 @@ static bool qt_painterpath_isect_line_rect(qreal x1, qreal y1, qreal x2, qreal y
// clip y coordinates
if (y1 < top) {
- x1 += dx/dy * (top - y1);
+ x1 += dx_dy_ratio * (top - y1);
y1 = top;
} else if (y1 > bottom) {
- x1 -= dx/dy * (y1 - bottom);
+ x1 -= dx_dy_ratio * (y1 - bottom);
y1 = bottom;
}
if (y2 < top) {
- x2 += dx/dy * (top - y2);
+ x2 += dx_dy_ratio * (top - y2);
y2 = top;
} else if (y2 > bottom) {
- x2 -= dx/dy * (y2 - bottom);
+ x2 -= dx_dy_ratio * (y2 - bottom);
y2 = bottom;
}
diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h
index 54b9392..a2bc905 100644
--- a/src/gui/painting/qpainterpath_p.h
+++ b/src/gui/painting/qpainterpath_p.h
@@ -258,7 +258,7 @@ inline void QPainterPathData::maybeMoveTo()
}
}
-#define KAPPA 0.5522847498
+#define KAPPA qreal(0.5522847498)
QT_END_NAMESPACE
diff --git a/src/gui/painting/qpathclipper.cpp b/src/gui/painting/qpathclipper.cpp
index ab2dc33..1568ad8 100644
--- a/src/gui/painting/qpathclipper.cpp
+++ b/src/gui/painting/qpathclipper.cpp
@@ -321,11 +321,11 @@ void QIntersectionFinder::intersectLines(const QLineF &a, const QLineF &b, QData
if (p1_equals_q1 || p1_equals_q2 || p2_equals_q1 || p2_equals_q2)
return;
-
+ const qreal inv_par = 1 / qreal(par);
const qreal tp = (qDelta.y() * (q1.x() - p1.x()) -
- qDelta.x() * (q1.y() - p1.y())) / par;
+ qDelta.x() * (q1.y() - p1.y())) * inv_par;
const qreal tq = (pDelta.y() * (q1.x() - p1.x()) -
- pDelta.x() * (q1.y() - p1.y())) / par;
+ pDelta.x() * (q1.y() - p1.y())) * inv_par;
if (tp<0 || tp>1 || tq<0 || tq>1)
return;
@@ -1192,24 +1192,24 @@ static qreal computeAngle(const QPointF &v)
{
#if 1
if (v.x() == 0) {
- return v.y() <= 0 ? 0 : 64.;
+ return v.y() <= 0 ? 0 : qreal(64.);
} else if (v.y() == 0) {
- return v.x() <= 0 ? 32. : 96.;
+ return v.x() <= 0 ? qreal(32.) : qreal(96.);
}
QPointF nv = normalize(v);
if (nv.y() < 0) {
if (nv.x() < 0) { // 0 - 32
- return -32. * nv.x();
+ return qreal(-32.) * nv.x();
} else { // 96 - 128
- return 128. - 32. * nv.x();
+ return qreal(128.) - qreal(32.) * nv.x();
}
} else { // 32 - 96
- return 64. + 32 * nv.x();
+ return qreal(64.) + 32 * nv.x();
}
#else
// doesn't seem to be robust enough
- return atan2(v.x(), v.y()) + Q_PI;
+ return qAtan2(v.x(), v.y()) + Q_PI;
#endif
}
diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp
index b602690..ba5eda6 100644
--- a/src/gui/painting/qrasterizer.cpp
+++ b/src/gui/painting/qrasterizer.cpp
@@ -44,6 +44,7 @@
#include <QPoint>
#include <QRect>
+#include <qmath.h>
#include <private/qmath_p.h>
#include <private/qdatabuffer_p.h>
#include <private/qdrawhelper_p.h>
@@ -51,8 +52,8 @@
QT_BEGIN_NAMESPACE
typedef int Q16Dot16;
-#define Q16Dot16ToFloat(i) ((i)/65536.)
-#define FloatToQ16Dot16(i) (int)((i) * 65536.)
+#define Q16Dot16ToFloat(i) ((i)/qreal(65536.))
+#define FloatToQ16Dot16(i) (int)((i) * qreal(65536.))
#define IntToQ16Dot16(i) ((i) << 16)
#define Q16Dot16ToInt(i) ((i) >> 16)
#define Q16Dot16Factor 65536
@@ -707,12 +708,12 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
if (a == b || width == 0 || d->clipRect.isEmpty())
return;
- Q_ASSERT(width > 0.0);
+ Q_ASSERT(width > qreal(0.0));
QPointF pa = a;
QPointF pb = b;
- QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * 0.5;
+ QPointF offs = QPointF(qAbs(b.y() - a.y()), qAbs(b.x() - a.x())) * width * qreal(0.5);
if (squareCap)
offs += QPointF(offs.y(), offs.x());
const QRectF clip(d->clipRect.topLeft() - offs, d->clipRect.bottomRight() + QPoint(1, 1) + offs);
@@ -750,10 +751,12 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
}
if (!d->antialiased) {
- pa.rx() += (COORD_OFFSET - COORD_ROUNDING)/64.;
- pa.ry() += (COORD_OFFSET - COORD_ROUNDING)/64.;
- pb.rx() += (COORD_OFFSET - COORD_ROUNDING)/64.;
- pb.ry() += (COORD_OFFSET - COORD_ROUNDING)/64.;
+ const qreal inv_64 = 1 / qreal(64.);
+ const qreal delta = (COORD_OFFSET - COORD_ROUNDING) * inv_64;
+ pa.rx() += delta;
+ pa.ry() += delta;
+ pb.rx() += delta;
+ pb.ry() += delta;
}
{
@@ -778,7 +781,7 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
return;
// adjust width which is given relative to |b - a|
- width *= sqrt(w0 / w);
+ width *= qSqrt(w0 / w);
}
QSpanBuffer buffer(d->blend, d->data, d->clipRect);
@@ -793,10 +796,11 @@ void QRasterizer::rasterizeLine(const QPointF &a, const QPointF &b, qreal width,
pa = QPointF(x, y - dy);
pb = QPointF(x, y + dy);
+ const qreal inv_width = 1 / width;
if (squareCap)
- width = 1 / width + 1.0f;
+ width = inv_width + 1.0f;
else
- width = 1 / width;
+ width = inv_width;
squareCap = false;
}
@@ -1192,8 +1196,10 @@ void QRasterizer::rasterize(const QPainterPath &path, Qt::FillRule fillRule)
QRectF bounds = path.controlPointRect();
- int iTopBound = qMax(d->clipRect.top(), int(bounds.top() + 0.5 + (COORD_OFFSET - COORD_ROUNDING)/64.));
- int iBottomBound = qMin(d->clipRect.bottom(), int(bounds.bottom() - 0.5 + (COORD_OFFSET - COORD_ROUNDING)/64.));
+ const qreal inv_64 = 1 / qreal(64.);
+ const qreal delta = (COORD_OFFSET - COORD_ROUNDING) * inv_64 ;
+ int iTopBound = qMax(d->clipRect.top(), int(bounds.top() + qreal(0.5) + delta));
+ int iBottomBound = qMin(d->clipRect.bottom(), int(bounds.bottom() - qreal(0.5) + delta));
if (iTopBound > iBottomBound)
return;
diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp
index 228a6b1..b33d86b 100644
--- a/src/gui/painting/qstroker.cpp
+++ b/src/gui/painting/qstroker.cpp
@@ -788,12 +788,12 @@ qreal qt_t_for_arc_angle(qreal angle)
if (qFuzzyCompare(angle, qreal(90)))
return 1;
- qreal radians = Q_PI * angle / 180;
+ qreal radians = Q_PI180 * angle;
qreal cosAngle = qCos(radians);
qreal sinAngle = qSin(radians);
// initial guess
- qreal tc = angle / 90;
+ qreal tc = angle / qreal(90);
// do some iterations of newton's method to approximate cosAngle
// finds the zero of the function b.pointAt(tc).x() - cosAngle
tc -= ((((2-3*QT_PATH_KAPPA) * tc + 3*(QT_PATH_KAPPA-1)) * tc) * tc + 1 - cosAngle) // value
@@ -812,7 +812,7 @@ qreal qt_t_for_arc_angle(qreal angle)
// use the average of the t that best approximates cosAngle
// and the t that best approximates sinAngle
- qreal t = 0.5 * (tc + ts);
+ qreal t = qreal(0.5) * (tc + ts);
#if 0
printf("angle: %f, t: %f\n", angle, t);
@@ -861,11 +861,11 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt
qreal y = rect.y();
qreal w = rect.width();
- qreal w2 = rect.width() / 2;
+ qreal w2 = rect.width() * qreal(0.5);
qreal w2k = w2 * QT_PATH_KAPPA;
qreal h = rect.height();
- qreal h2 = rect.height() / 2;
+ qreal h2 = rect.height() * qreal(0.5);
qreal h2k = h2 * QT_PATH_KAPPA;
QPointF points[16] =
@@ -898,23 +898,24 @@ QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLengt
else if (sweepLength < -360) sweepLength = -360;
// Special case fast paths
- if (startAngle == 0.0) {
- if (sweepLength == 360.0) {
+ if (startAngle == qreal(0.0)) {
+ if (sweepLength == qreal(360.0)) {
for (int i = 11; i >= 0; --i)
curves[(*point_count)++] = points[i];
return points[12];
- } else if (sweepLength == -360.0) {
+ } else if (sweepLength == qreal(-360.0)) {
for (int i = 1; i <= 12; ++i)
curves[(*point_count)++] = points[i];
return points[0];
}
}
- int startSegment = int(floor(startAngle / 90));
- int endSegment = int(floor((startAngle + sweepLength) / 90));
+ qreal inv_90 = qreal(1) / qreal(90);
+ int startSegment = int(floor(startAngle * inv_90));
+ int endSegment = int(floor((startAngle + sweepLength) * inv_90));
- qreal startT = (startAngle - startSegment * 90) / 90;
- qreal endT = (startAngle + sweepLength - endSegment * 90) / 90;
+ qreal startT = (startAngle - startSegment * 90) * inv_90;
+ qreal endT = (startAngle + sweepLength - endSegment * 90) * inv_90;
int delta = sweepLength > 0 ? 1 : -1;
if (delta < 0) {
diff --git a/src/gui/painting/qstroker_p.h b/src/gui/painting/qstroker_p.h
index a10ebd9..5ff9d87 100644
--- a/src/gui/painting/qstroker_p.h
+++ b/src/gui/painting/qstroker_p.h
@@ -110,7 +110,7 @@ struct qfixed2d
};
#endif
-#define QT_PATH_KAPPA 0.5522847498
+#define QT_PATH_KAPPA qreal(0.5522847498)
QPointF qt_curves_for_arc(const QRectF &rect, qreal startAngle, qreal sweepLength,
QPointF *controlPoints, int *point_count);
diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp
index 8118450..4732278 100644
--- a/src/gui/painting/qtransform.cpp
+++ b/src/gui/painting/qtransform.cpp
@@ -52,7 +52,7 @@
QT_BEGIN_NAMESPACE
-#define Q_NEAR_CLIP (sizeof(qreal) == sizeof(double) ? 0.000001 : 0.0001)
+#define Q_NEAR_CLIP (sizeof(qreal) == sizeof(double) ? qreal(0.000001) : qreal(0.0001))
#ifdef MAP
# undef MAP
@@ -82,7 +82,7 @@ QT_BEGIN_NAMESPACE
if (t == TxProject) { \
qreal w = (m_13 * FX_ + m_23 * FY_ + m_33); \
if (w < qreal(Q_NEAR_CLIP)) w = qreal(Q_NEAR_CLIP); \
- w = 1./w; \
+ w = qreal(1.)/w; \
nx *= w; \
ny *= w; \
} \
@@ -369,8 +369,8 @@ QTransform QTransform::inverted(bool *invertible) const
inv = !qFuzzyIsNull(affine._m11);
inv &= !qFuzzyIsNull(affine._m22);
if (inv) {
- invert.affine._m11 = 1. / affine._m11;
- invert.affine._m22 = 1. / affine._m22;
+ invert.affine._m11 = qreal(1.) / affine._m11;
+ invert.affine._m22 = qreal(1.) / affine._m22;
invert.affine._dx = -affine._dx * invert.affine._m11;
invert.affine._dy = -affine._dy * invert.affine._m22;
}
@@ -1087,7 +1087,7 @@ QPoint QTransform::map(const QPoint &p) const
x = affine._m11 * fx + affine._m21 * fy + affine._dx;
y = affine._m12 * fx + affine._m22 * fy + affine._dy;
if (t == TxProject) {
- qreal w = 1./(m_13 * fx + m_23 * fy + m_33);
+ qreal w = qreal(1.)/(m_13 * fx + m_23 * fy + m_33);
x *= w;
y *= w;
}
@@ -1138,7 +1138,7 @@ QPointF QTransform::map(const QPointF &p) const
x = affine._m11 * fx + affine._m21 * fy + affine._dx;
y = affine._m12 * fx + affine._m22 * fy + affine._dy;
if (t == TxProject) {
- qreal w = 1./(m_13 * fx + m_23 * fy + m_33);
+ qreal w = qreal(1.)/(m_13 * fx + m_23 * fy + m_33);
x *= w;
y *= w;
}
@@ -1217,10 +1217,10 @@ QLine QTransform::map(const QLine &l) const
x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx;
y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy;
if (t == TxProject) {
- qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33);
+ qreal w = qreal(1.)/(m_13 * fx1 + m_23 * fy1 + m_33);
x1 *= w;
y1 *= w;
- w = 1./(m_13 * fx2 + m_23 * fy2 + m_33);
+ w = qreal(1.)/(m_13 * fx2 + m_23 * fy2 + m_33);
x2 *= w;
y2 *= w;
}
@@ -1276,10 +1276,10 @@ QLineF QTransform::map(const QLineF &l) const
x2 = affine._m11 * fx2 + affine._m21 * fy2 + affine._dx;
y2 = affine._m12 * fx2 + affine._m22 * fy2 + affine._dy;
if (t == TxProject) {
- qreal w = 1./(m_13 * fx1 + m_23 * fy1 + m_33);
+ qreal w = qreal(1.)/(m_13 * fx1 + m_23 * fy1 + m_33);
x1 *= w;
y1 *= w;
- w = 1./(m_13 * fx2 + m_23 * fy2 + m_33);
+ w = qreal(1.)/(m_13 * fx2 + m_23 * fy2 + m_33);
x2 *= w;
y2 *= w;
}
@@ -1438,7 +1438,7 @@ struct QHomogeneousCoordinate
QHomogeneousCoordinate(qreal x_, qreal y_, qreal w_) : x(x_), y(y_), w(w_) {}
const QPointF toPoint() const {
- qreal iw = 1. / w;
+ qreal iw = qreal(1.) / w;
return QPointF(x * iw, y * iw);
}
};
@@ -1695,8 +1695,9 @@ bool QTransform::squareToQuad(const QPolygonF &quad, QTransform &trans)
if (!bottom)
return false;
- g = gtop/bottom;
- h = htop/bottom;
+ double inv_bottom = 1 / bottom;
+ g = gtop * inv_bottom;
+ h = htop * inv_bottom;
a = dx1 - dx0 + g * dx1;
b = dx3 - dx0 + h * dx3;