mercredi 28 juin 2017

How to sort Vector of Points based on specific two segment line

schema of point & segment line

actually I try to use tie for sorting from top left to bottom right order & it works:

std::sort(VectorCoord.begin(), VectorCoord.end(), [] (const Point2f& sr, const Point2f& sl)
                      {

                              return std::tie(sr.x, sr.y) > std::tie(sl.x, sl.y);


                      });

but if I try to insert some condition my compiler send my an error (these is not a solution for my problem, just a test to get the result) . Ex:

std::sort(VectorCoord.begin(), VectorCoord.end(), [] (const Point2f& sr, const Point2f& sl)
                      {

                              if(sr.y > 0){
                                 return std::tie(sr.x, sr.y) > std::tie(sl.x, sl.y);}
                              else{                   
                                   return std::tie(sr.x, sr.y) < std::tie(sl.x, sl.y);}


                      });

What do I do wrong? In what might be the best system to get the sort I need?

giorgio

Aucun commentaire:

Enregistrer un commentaire