diff --git a/cvutils.cpp b/cvutils.cpp index 9216fa8..5640246 100644 --- a/cvutils.cpp +++ b/cvutils.cpp @@ -22,8 +22,8 @@ unsigned* max2_distance(std::vector hull) for(auto p: hull) { std::cout << p << " "; } -#endif std::cout << std::endl; +#endif unsigned *idx = (unsigned*) calloc(2, sizeof(int)); double distance[2] = {0}; for( unsigned i=0; hull.size()>i; i++ ) @@ -126,11 +126,11 @@ find_longest_line(std::vector hull, unsigned begin, unsigned end) //t thisline.push_back(hull[(begin+1)%hull.size()]); for(unsigned i=(begin+2)%hull.size(); i!=end; i++) { - assert(2<=thisline.size()); + assert(2<=thisline.size()); if(i==hull.size()) { i=0; - } - assert(i < hull.size()); + } + assert(i < hull.size()); if(similar_fit(thisline, hull[i])) { thisline.push_back(hull[i]); } else { // considering if the just-finished line is the best @@ -145,9 +145,10 @@ find_longest_line(std::vector hull, unsigned begin, unsigned end) //t thisline.push_back(hull[i]); }; } - if(bestline.size()==0) { // this is the case only when the first line is the best line - assert(0==bestdistance); + double thisdistance = dist(thisline[0],thisline[thisline.size()-1]); + if(thisdistance>bestdistance) { // this is relevant if the best line ends at the last point bestline = thisline; + bestdistance = thisdistance; } assert(bestline.size()>=2); return bestline;