[QGIS Commit] r11308 - branches/symbology-ng-branch/src/core/pal

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Aug 9 07:25:41 EDT 2009


Author: wonder
Date: 2009-08-09 07:25:41 -0400 (Sun, 09 Aug 2009)
New Revision: 11308

Modified:
   branches/symbology-ng-branch/src/core/pal/labelposition.cpp
   branches/symbology-ng-branch/src/core/pal/labelposition.h
Log:
Changed my insanely expensive conflict check for multipart labels with something actually usable.


Modified: branches/symbology-ng-branch/src/core/pal/labelposition.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-08-09 11:25:13 UTC (rev 11307)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-08-09 11:25:41 UTC (rev 11308)
@@ -149,29 +149,35 @@
 
   bool LabelPosition::isInConflict( LabelPosition *lp )
   {
-    int i, i2, j;
-    int d1, d2;
-
     if ( this->probFeat == lp->probFeat ) // bugfix #1
       return false; // always overlaping itself !
 
+    if (nextPart == NULL && lp->nextPart == NULL)
+      return isInConflictSinglePart(lp);
+    else
+      return isInConflictMultiPart(lp);
+  }
+
+  bool LabelPosition::isInConflictSinglePart( LabelPosition* lp )
+  {
+    // TODO: add bounding box test to possibly avoid cross product calculation
+
+    int i, i2, j;
+    int d1, d2;
     double cp1, cp2;
 
-
-    //std::cout << "Check intersect" << std::endl;
     for ( i = 0;i < 4;i++ )
     {
       i2 = ( i + 1 ) % 4;
       d1 = -1;
       d2 = -1;
-      //std::cout << "new seg..." << std::endl;
+
       for ( j = 0;j < 4;j++ )
       {
         cp1 = cross_product( x[i], y[i], x[i2], y[i2], lp->x[j], lp->y[j] );
         if ( cp1 > 0 )
         {
           d1 = 1;
-          //std::cout << "    cp1: " << cp1 << std::endl;
         }
         cp2 = cross_product( lp->x[i], lp->y[i],
                              lp->x[i2], lp->y[i2],
@@ -180,25 +186,33 @@
         if ( cp2 > 0 )
         {
           d2 = 1;
-          //std::cout << "     cp2 " << cp2 << std::endl;
         }
       }
 
       if ( d1 == -1 || d2 == -1 ) // disjoint
+        return false;
+    }
+    return true;
+  }
+
+  bool LabelPosition::isInConflictMultiPart( LabelPosition* lp )
+  {
+    // check all parts against all parts of other one
+    LabelPosition* tmp1 = this;
+    while (tmp1)
+    {
+      // check tmp1 against parts of other label
+      LabelPosition* tmp2 = lp;
+      while (tmp2)
       {
-        if ( lp->getNextPart() )
-        {
-          if ( isInConflict(lp->getNextPart()) )
-            return true;
-        }
+        if (tmp1->isInConflictSinglePart(tmp2))
+          return true;
+        tmp2 = tmp2->nextPart;
+      }
 
-        if (nextPart)
-          return nextPart->isInConflict( lp );
-        else
-          return false;
-      }
+      tmp1 = tmp1->nextPart;
     }
-    return true;
+    return false; // no conflict found
   }
 
   int LabelPosition::getId() const

Modified: branches/symbology-ng-branch/src/core/pal/labelposition.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-08-09 11:25:13 UTC (rev 11307)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-08-09 11:25:41 UTC (rev 11308)
@@ -74,6 +74,9 @@
       LabelPosition* nextPart;
       int partId;
 
+      bool isInConflictSinglePart( LabelPosition* lp );
+      bool isInConflictMultiPart( LabelPosition* lp );
+
     public:
       /**
        * \brief create a new LabelPosition



More information about the QGIS-commit mailing list