Tighter bounding box check
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 22 Sep 2011 03:42:21 +0000 (13:42 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 22 Sep 2011 05:22:09 +0000 (07:22 +0200)
Because the gernic check works on floats and how .toPoint rounds, we
need to redo the bounds checking inside Turbulence

Task-number: QTBUG-21564
Change-Id: Ib56a8d420d9abf8035360b7908e89e28938799a8
Reviewed-on: http://codereview.qt-project.org/5343
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/declarative/particles/qsgturbulence.cpp

index aa5dfeb..ac1306b 100644 (file)
@@ -136,7 +136,9 @@ void QSGTurbulenceAffector::initializeGrid()
     for (int i=0; i<m_gridSize; i++)
         m_vectorField[i] = (QPointF*)malloc(m_gridSize * sizeof(QPointF));
 
-    QImage image = QImage(m_noiseSource.toLocalFile()).scaled(QSize(m_gridSize, m_gridSize));
+    QImage image;
+    if (!m_noiseSource.isEmpty())
+        image = QImage(m_noiseSource.toLocalFile()).scaled(QSize(m_gridSize, m_gridSize));
     if (image.isNull())
         image = QImage(":defaultshaders/noise.png").scaled(QSize(m_gridSize, m_gridSize));
 
@@ -177,9 +179,12 @@ void QSGTurbulenceAffector::affectSystem(qreal dt)
     if (!m_system || !m_enabled)
         return;
     ensureInit();
+    if (!m_gridSize)
+        return;
+
     updateOffsets();//### Needed if an ancestor is transformed.
 
-    QRectF boundsRect(0, 0, width()-1, height()-1);
+    QRect boundsRect(0,0,m_gridSize,m_gridSize);
     foreach (QSGParticleGroupData *gd, m_system->m_groupData){
         if (!activeGroup(m_system->m_groupData.key(gd)))
             continue;
@@ -187,6 +192,8 @@ void QSGTurbulenceAffector::affectSystem(qreal dt)
             if (!shouldAffect(d))
                 continue;
             QPoint pos = (QPointF(d->curX(), d->curY()) - m_offset).toPoint();
+            if (!boundsRect.contains(pos,true))//Need to redo bounds checking due to quantization.
+                continue;
             qreal fx = 0.0;
             qreal fy = 0.0;
             fx += m_vectorField[pos.x()][pos.y()].x() * m_strength;