dimanche 6 janvier 2019

How to find the some value in vector of points

I need to find some point from this vector of points that is greater than 100+previous x-axis of the new vector of points.

old vector

[0, 299;
0, 506;
77, 284;
297, 253;
332, 250;
351, 250;
384, 252;
424, 255;
570, 266;
593, 268;
759, 324;
759, 506]

to the new vector of point

[0, 299;
 297, 253;
 424, 255;
 593, 268;
 759, 324]

I've tried to find the smallest first, and iterate to find the next value. But it seems something went wrong.

the result is this

[0, 299;
 297, 253;
 424, 255;
 570, 266;
 759, 324;
 37734976, 0;
 570, 266;
 759, 324;
 37734976, 0;
 297, 253;
 424, 255]

Here is my code:

        bool sort_smallest(const Point& lhs, const Point &rhs)
        {
            if(lhs.x <= rhs.x)
            {
                if(lhs.y <= rhs.y)
                    return true;
                else return false;
            }
            else return (lhs.x < rhs.x);
        }

        bool equalPoint(const Point& lhs, const Point &rhs)
        {
             if((lhs.x == rhs.x) && (lhs.y == rhs.y))
             return true;
             else return false;
        }

        //find smallest x
        auto min_x = std::min_element(field_ConvexHullPoints.begin(), field_ConvexHullPoints.end(), sort_smallest);
        Point c = *min_x;
        temp_point.push_back(*min_x);

        Point big_val = c;
        for(int i = 0; i < field_ConvexHullPoints.size(); i++)
        {
            auto big_ = std::find_if(temp_point.begin(),temp_point.end(), [&big_val](Point& p){return ((p.x > big_val.x+100));});
            Point big = *big_;
            auto it = std::find_if(field_ConvexHullPoints.begin(),field_ConvexHullPoints.end(), [&big](Point& p){return ((p.x > big.x+100));});
            Point pant = *it;
            temp_point.push_back(pant);
            big_val = big;
        }

        sort(temp_point.begin(), temp_point.end(), sort_smallest);
        auto unique_end = std::unique(temp_point.begin(), temp_point.end(), equalPoint);
        temp_point.erase(unique_end, temp_point.end());

Aucun commentaire:

Enregistrer un commentaire