Przeglądaj źródła

Simplification du code dans StrengthLine

Rémi Synave 2 lat temu
rodzic
commit
bca346ea8f
3 zmienionych plików z 38 dodań i 157 usunięć
  1. 25 154
      StrengthLine/StrengthLine.cpp
  2. 12 3
      clf/WorkArea.cpp
  3. 1 0
      clf/clf.pro

+ 25 - 154
StrengthLine/StrengthLine.cpp

@@ -139,167 +139,38 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (int imgWidth, i
   float
     b = std::get < 1 > (eq);
 
-  if(a>0)
+  QPoint *p1 = new QPoint(0, b);
+  QPoint *p2 = new QPoint(imgWidth, imgWidth * a + b);
+
+  // Si le point de gauche est trop bas
+  if(b < 0)
+    {
+      p1->setX(-b/a);
+      p1->setY(0);
+    }
+  // Si le point de gauche est trop haut
+  if(b > imgHeight)
     {
-      if(b<0)
-	{
-	  if((a*imgWidth+b) > imgHeight)
-	    {
-	      // |------------------------------------------|
-	      // |           *                              |
-	      // |           *                              |
-	      // |            *                             |
-	      // |            *                             |
-	      // |             *                            |
-	      // |             *                            |
-	      // |              *                           |
-	      // |              *                           |
-	      // |               *                          |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint (-1*(b/a), 0),
-				     new QPoint ((imgHeight-b)/a, imgHeight));
-	    }
-	  else
-	    {
-	      // |------------------------------------------|
-	      // |                           ***            |
-	      // |                              ***         |
-	      // |                                 ***      |
-	      // |                                    ***   |
-	      // |                                       ***|
-	      // |                                          |
-	      // |                                          |
-	      // |                                          |
-	      // |                                          |
-	      // |------------------------------------------|
-
-	      return std::make_pair (new QPoint (-1*(b/a), 0),
-				     new QPoint (imgWidth, a * imgWidth + b));
-	    }
-	}
-      else // a>0 and b>0
-	{
-	  
-	  if((a*imgWidth+b) > imgHeight)
-	    {
-	      // |------------------------------------------|
-	      // |                                          |
-	      // |                                          |
-	      // |*                                         |
-	      // | *                                        |
-	      // |  *                                       |
-	      // |   *                                      |
-	      // |    *                                     |
-	      // |     *                                    |
-	      // |      *                                   |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint (0, b),
-				     new QPoint ((imgHeight -b )/a, imgHeight));
-	    }
-	  else
-	    {
-	      // |------------------------------------------|
-	      // |                                          |
-	      // |********                                  |
-	      // |        ********                          |
-	      // |                ********                  |
-	      // |                        ********          |
-	      // |                                ********  |
-	      // |                                        **|
-	      // |                                          |
-	      // |                                          |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint (0, b),
-				     new QPoint (imgWidth, a*imgWidth+b));
-	    }
-	}
+      p1->setX((imgHeight-b)/a);
+      p1->setY(imgHeight);
     }
-  else // a<0
+  // Si le point de droite est trop bas
+  if((imgWidth * a + b) < 0)
     {
-      if((a*imgWidth+b)>0)
-	{
-	  if(b > imgHeight)
-	    {
-	      // |------------------------------------------|
-	      // |                                          |
-	      // |                                          |
-	      // |                                        * |
-	      // |                                      *   |
-	      // |                                    *     |
-	      // |                                  *       |
-	      // |                                *         |
-	      // |                              *           |
-	      // |                            *             |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint ((imgHeight-b)/a, imgHeight),
-				     new QPoint (imgWidth, a*imgWidth+b));
-	    }
-	  else
-	    {
-	      // |------------------------------------------|
-	      // |                                          |
-	      // |                                          |
-	      // |                                        **|
-	      // |                                ********  |
-	      // |                        ********          |
-	      // |                ********                  |
-	      // |        ********                          |
-	      // |********                                  |
-	      // |                                          |
-	      // |------------------------------------------|
-
-	      return std::make_pair (new QPoint (0, b),
-				     new QPoint (imgWidth, a * imgWidth + b));
-	    }
-	}
-      else // a>0 and (a*imgWidth+b) < 0
-	{
-	  
-	  if(b > imgHeight)
-	    {
-	      // |------------------------------------------|
-	      // |               *                          |
-	      // |               *                          |
-	      // |               *                          |
-	      // |              *                           |
-	      // |              *                           |
-	      // |              *                           |
-	      // |             *                            |
-	      // |             *                            |
-	      // |             *                            |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint (-1*(b/a), 0),
-				     new QPoint ((imgHeight-b)/a, imgHeight));
-	    }
-	  else
-	    {
-	      // |------------------------------------------|
-	      // |        *                                 |
-	      // |      *                                   |
-	      // |    *                                     |
-	      // |  *                                       |
-	      // |*                                         |
-	      // |                                          |
-	      // |                                          |
-	      // |                                          |
-	      // |                                          |
-	      // |------------------------------------------|
-	      
-	      return std::make_pair (new QPoint (0, b),
-				     new QPoint (-1*(b/a), 0));
-	    }
-	}
+      p2->setX(-b/a);
+      p2->setY(0);
+    }
+  // Si le point de droite est trop haut
+  if((imgWidth * a + b) > imgHeight)
+    {
+      p2->setX((imgHeight-b)/a);
+      p2->setY(imgHeight);
     }
   
-  return std::make_pair (new QPoint (*p1),
-			 new QPoint (*p2));
+  return std::make_pair (p1, p2);
 }
 
+
 float StrengthLine::ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const
 {
   std::srand(static_cast<unsigned int>(std::time(nullptr)+std::rand()));

+ 12 - 3
clf/WorkArea.cpp

@@ -96,9 +96,18 @@ WorkArea::paint (QPainter & painter)
 	{
 	  painter.setPen (QPen (Qt::red, epaisseurLigne));
 	  std::pair < QPoint *, QPoint * >endPoints =
-	    StrengthLine (liste_points[i - 1], liste_points[i]).toDraw (this->screenSizeX, this->screenSizeY);
-	  painter.drawLine (*(std::get < 0 > (endPoints)),
-			    *(std::get < 1 > (endPoints)));
+	    StrengthLine (liste_points[i - 1], liste_points[i]).interpolateToEdge (this->screenSizeX, this->screenSizeY);
+	  QPoint *first = std::get < 0 > (endPoints);
+	  QPoint *last = std::get < 1 > (endPoints);
+	  painter.drawLine (*first,
+			    *last);
+
+	  painter.setBrush (QBrush (Qt::blue));
+	  painter.setPen (QPen (Qt::blue));
+	  painter.drawEllipse (*first,
+			       taillePoint, taillePoint);
+	  painter.drawEllipse (*last,
+			       taillePoint, taillePoint);
 	}
 
     }

+ 1 - 0
clf/clf.pro

@@ -33,6 +33,7 @@ SOURCES = ../StrengthLine/StrengthLine.cpp \
           WorkArea.cpp \
           MainWindow.cpp \
           main.cpp
+
                     
 # install
 target.path = $$[QT_INSTALL_EXAMPLES]/clf