summaryrefslogtreecommitdiffstats
path: root/examples/corelib/threads/mandelbrot/renderthread.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-01-14 08:31:02 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-03-10 08:15:15 +0100
commit9aa293270155f1c50870f0119932629e31ab0713 (patch)
tree6efaee76db8c67861ee811c824cd2d3309514988 /examples/corelib/threads/mandelbrot/renderthread.cpp
parenta8ae9718b01e68c5c0367941f7999c59b6da84d4 (diff)
Polish the Mandelbrot Example
Fix warnings about float constants and comparison. Use member or constructor initialization. Introduce some const for clarity. Use Qt_CONFIG. Task-number: QTBUG-81254 Change-Id: I71a6ebfba397c0f8e1dd2e61167233c8e5c137af Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/corelib/threads/mandelbrot/renderthread.cpp')
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp
index eee44c7242..22ce81c32d 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.cpp
+++ b/examples/corelib/threads/mandelbrot/renderthread.cpp
@@ -57,9 +57,6 @@
RenderThread::RenderThread(QObject *parent)
: QThread(parent)
{
- restart = false;
- abort = false;
-
for (int i = 0; i < ColormapSize; ++i)
colormap[i] = rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize));
}
@@ -102,10 +99,10 @@ void RenderThread::run()
{
forever {
mutex.lock();
- QSize resultSize = this->resultSize;
- double scaleFactor = this->scaleFactor;
- double centerX = this->centerX;
- double centerY = this->centerY;
+ const QSize resultSize = this->resultSize;
+ const double scaleFactor = this->scaleFactor;
+ const double centerX = this->centerX;
+ const double centerY = this->centerY;
mutex.unlock();
//! [3]
@@ -128,20 +125,20 @@ void RenderThread::run()
if (abort)
return;
- uint *scanLine =
+ auto scanLine =
reinterpret_cast<uint *>(image.scanLine(y + halfHeight));
- double ay = centerY + (y * scaleFactor);
+ const double ay = centerY + (y * scaleFactor);
for (int x = -halfWidth; x < halfWidth; ++x) {
- double ax = centerX + (x * scaleFactor);
+ const double ax = centerX + (x * scaleFactor);
double a1 = ax;
double b1 = ay;
int numIterations = 0;
do {
++numIterations;
- double a2 = (a1 * a1) - (b1 * b1) + ax;
- double b2 = (2 * a1 * b1) + ay;
+ const double a2 = (a1 * a1) - (b1 * b1) + ax;
+ const double b2 = (2 * a1 * b1) + ay;
if ((a2 * a2) + (b2 * b2) > Limit)
break;
@@ -187,9 +184,9 @@ void RenderThread::run()
//! [10]
uint RenderThread::rgbFromWaveLength(double wave)
{
- double r = 0.0;
- double g = 0.0;
- double b = 0.0;
+ double r = 0;
+ double g = 0;
+ double b = 0;
if (wave >= 380.0 && wave <= 440.0) {
r = -1.0 * (wave - 440.0) / (440.0 - 380.0);