[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/containments/desktop
From:       Ambroz Bizjak <ambrop7 () gmail ! com>
Date:       2009-02-09 21:26:07
Message-ID: 1234214767.242473.2450.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 924004 by abizjak:

Fix an infinite loop in the positioning algorithm which happened
because QRectF::intersects() is incorrectly documented and sometimes
returns true even if the rectangles only touch.


 M  +15 -8     itemspace.cpp  


--- trunk/KDE/kdebase/workspace/plasma/containments/desktop/itemspace.cpp \
#924003:924004 @@ -13,6 +13,17 @@
 
 #include "itemspace.h"
 
+// Contrary to QRectF::intersects(), this function requires the
+// rectangles to truly intersect, not just touch on one side
+bool __intersects (const QRectF &a, const QRectF &b)
+{
+    if (!(a.bottom() > b.top())) return false;
+    if (!(a.top() < b.bottom())) return false;
+    if (!(a.right() > b.left())) return false;
+    if (!(a.left() < b.right())) return false;
+    return true;
+}
+
 ItemSpace::ItemSpace()
   : spaceAlignment(Qt::AlignTop|Qt::AlignLeft),
     workingGeom(QSizeF()),
@@ -253,8 +264,6 @@
                 break;
             }
 
-            Q_ASSERT( ((align & Qt::AlignTop) && a.bottom() > y) || ((align & \
                Qt::AlignBottom) && a.y() - size.height() < y) );
-
             y = ((align & Qt::AlignTop) ? a.bottom() : a.y() - size.height());
         }
 
@@ -279,8 +288,6 @@
             break;
         }
 
-        Q_ASSERT( ((align & Qt::AlignLeft) && a.right() > x) || ((align & \
                Qt::AlignRight) && a.x() - size.width() < x) );
-
         x = ((align & Qt::AlignLeft) ? a.right() : a.x() - size.width());
     }
 
@@ -302,7 +309,7 @@
               continue;
             }
             qreal cl = item.lastGeometry.y();
-            if (item.lastGeometry.intersects(region) && cl < l) {
+            if (__intersects(item.lastGeometry, region) && cl < l) {
                 ret = item.lastGeometry;
                 l = cl;
             }
@@ -326,7 +333,7 @@
               continue;
             }
             qreal cl = item.lastGeometry.y() + item.lastGeometry.height();
-            if (item.lastGeometry.intersects(region) && cl > l) {
+            if (__intersects(item.lastGeometry, region) && cl > l) {
                 ret = item.lastGeometry;
                 l = cl;
             }
@@ -350,7 +357,7 @@
               continue;
             }
             qreal cl = item.lastGeometry.x() + item.lastGeometry.width();
-            if (item.lastGeometry.intersects(region) && cl < l) {
+            if (__intersects(item.lastGeometry, region) && cl < l) {
                 ret = item.lastGeometry;
                 l = cl;
             }
@@ -374,7 +381,7 @@
               continue;
             }
             qreal cl = item.lastGeometry.x();
-            if (item.lastGeometry.intersects(region) && cl > l) {
+            if (__intersects(item.lastGeometry, region) && cl > l) {
                 ret = item.lastGeometry;
                 l = cl;
             }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic