2525#include < cmath>
2626#include < cstdlib>
2727#include < cstring>
28- #include < iosfwd>
2928#include < limits>
30- # include < memory>
29+ // IWYU pragma: no_include <memory>
3130#include < stdexcept>
3231#include < utility>
3332
5049 if (JOIN_DEBUG) qDebug (__VA_ARGS__); \
5150} while (0 )
5251
53- using namespace std ;
5452
5553namespace cove {
5654const int Polygons::NPOINTS_MAX = 350 ;
@@ -379,9 +377,12 @@ Polygons::decomposeImageIntoPaths(const QImage& sourceImage,
379377 bool cancel = false ;
380378 while (!cancel && findNextPixel (image, x, y))
381379 {
382- Path pathFound = recordPath (image, x, y);
383- removePathFromImage (image, pathFound);
384- if (pathFound.size () > specklesize) pathList.push_back (pathFound);
380+ {
381+ auto pathFound = recordPath (image, x, y);
382+ removePathFromImage (image, pathFound);
383+ if (pathFound.size () > specklesize)
384+ pathList.push_back (std::move (pathFound));
385+ }
385386 if (progressObserver && !(y % progressHowOften))
386387 {
387388 // FIXME hardcoded value 25!!!
@@ -390,7 +391,10 @@ Polygons::decomposeImageIntoPaths(const QImage& sourceImage,
390391 }
391392 }
392393
393- return !cancel ? pathList : PathList ();
394+ if (cancel)
395+ pathList.clear ();
396+
397+ return pathList;
394398}
395399
396400/* ! Identifies straight segments of path and returns them as list of vertices
@@ -418,7 +422,7 @@ Polygons::getPathPolygons(const Polygons::PathList& constpaths,
418422 p = path_new ();
419423 if (!p || !pt)
420424 {
421- throw runtime_error (" memory allocation failed" );
425+ throw std:: runtime_error (" memory allocation failed" );
422426 }
423427 privpath_t * pp = p->priv ;
424428 pp->pt = pt;
@@ -656,21 +660,19 @@ bool Polygons::splitlist(JOINENDPOINTLIST& pl, JOINOPLIST& ops,
656660 if (vertical)
657661 {
658662 double x1bound = max1.x + maxdist / 2 , x2bound = min2.x - maxdist / 2 ;
659- for (JOINENDPOINTLIST::const_iterator i = pl.begin (); i != pl.end ();
660- ++i)
663+ for (const auto & p : pl)
661664 {
662- if (i-> coords .x <= x1bound) pl1.push_back (*i );
663- if (i-> coords .x >= x2bound) pl2.push_back (*i );
665+ if (p. coords .x <= x1bound) pl1.push_back (p );
666+ if (p. coords .x >= x2bound) pl2.push_back (p );
664667 }
665668 }
666669 else
667670 {
668671 double y1bound = max1.y + maxdist / 2 , y2bound = min2.y - maxdist / 2 ;
669- for (JOINENDPOINTLIST::const_iterator i = pl.begin (); i != pl.end ();
670- ++i)
672+ for (const auto & p : pl)
671673 {
672- if (i-> coords .y <= y1bound) pl1.push_back (*i );
673- if (i-> coords .y >= y2bound) pl2.push_back (*i );
674+ if (p. coords .y <= y1bound) pl1.push_back (p );
675+ if (p. coords .y >= y2bound) pl2.push_back (p );
674676 }
675677 }
676678
@@ -707,8 +709,8 @@ bool Polygons::compdists(JOINENDPOINTLIST& pl, JOINOPLIST& ops,
707709 else
708710 {
709711 double maxDistSqr = maxdist * maxdist;
710- vector<bool > alreadyUsed (npoints, false );
711- vector<bool >::iterator ai = alreadyUsed.begin (), aj;
712+ std:: vector<bool > alreadyUsed (npoints, false );
713+ std:: vector<bool >::iterator ai = alreadyUsed.begin (), aj;
712714
713715 JOIN_DEBUG_PRINT (" computing set of %d points" , npoints);
714716 for (JOINENDPOINTLIST::const_iterator i = pl.begin ();
@@ -745,7 +747,7 @@ bool Polygons::compdists(JOINENDPOINTLIST& pl, JOINOPLIST& ops,
745747 a = b - 1 ;
746748 break ;
747749 default :
748- throw logic_error (" NOEND in JOINENDPOINT list" );
750+ throw std:: logic_error (" NOEND in JOINENDPOINT list" );
749751 }
750752 switch (j->end )
751753 {
@@ -758,7 +760,7 @@ bool Polygons::compdists(JOINENDPOINTLIST& pl, JOINOPLIST& ops,
758760 d = c - 1 ;
759761 break ;
760762 default :
761- throw logic_error (" NOEND in JOINENDPOINT list" );
763+ throw std:: logic_error (" NOEND in JOINENDPOINT list" );
762764 }
763765
764766 ops.push_back (JOINOP (float (dstfun (a, b, c, d)
@@ -826,7 +828,8 @@ bool Polygons::joinPolygons(path_t*& plist,
826828
827829 compdists (pointlist, ops, min, max, true , progressObserver, 50 , 12 );
828830
829- sort (ops.begin (), ops.end (), greater_weight ());
831+ sort (ops.begin (), ops.end (),
832+ [](const JOINOP& x, const JOINOP& y) { return x.weight > y.weight ; });
830833
831834 nops = ops.size ();
832835 cntr = 0 ;
@@ -1005,17 +1008,17 @@ bool Polygons::joinPolygons(path_t*& plist,
10051008 newcurve.vertex [d] = a_curve->vertex [d];
10061009 break ;
10071010 case NOJOIN:
1008- throw logic_error (" NOJOIN operation in JOINOP list" );
1011+ throw std:: logic_error (" NOJOIN operation in JOINOP list" );
10091012 default :
1010- throw logic_error (" invalid JOINOP" );
1013+ throw std:: logic_error (" invalid JOINOP" );
10111014 }
10121015
10131016 privcurve_free_members (a_curve);
10141017 memcpy (a_curve, &newcurve, sizeof (privcurve_t ));
10151018
10161019 path_t * ib = currOp.b ;
10171020 list_unlink (path_t , plist, ib);
1018- if (!ib) throw logic_error (" unlinked ib not in list" );
1021+ if (!ib) throw std:: logic_error (" unlinked ib not in list" );
10191022 path_free (ib);
10201023 }
10211024
0 commit comments