Skip to content

Commit 3eb773e

Browse files
authored
Merge master into release (GH-2438)
Merge master into release
2 parents 5fc6056 + 81ea5e7 commit 3eb773e

File tree

319 files changed

+150915
-46450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+150915
-46450
lines changed

.clang-tidy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Checks: >-
22
*,
3+
-altera-id-dependent-backward-branch,
4+
-altera-unroll-loops,
5+
-bugprone-branch-clone,
36
-bugprone-integer-division,
47
-bugprone-narrowing-conversions,
58
-bugprone-too-small-loop-variable,
@@ -9,6 +12,7 @@ Checks: >-
912
-clang-analyzer-cplusplus.Move,
1013
-cppcoreguidelines-avoid-c-arrays,
1114
-cppcoreguidelines-avoid-magic-numbers,
15+
-cppcoreguidelines-init-variables,
1216
-cppcoreguidelines-macro-usage,
1317
-cppcoreguidelines-narrowing-conversions,
1418
-cppcoreguidelines-non-private-member-variables-in-classes,
@@ -38,25 +42,31 @@ Checks: >-
3842
-modernize-use-emplace,
3943
-modernize-use-equals-default,
4044
-modernize-use-nullptr,
45+
-modernize-use-trailing-return-type,
4146
-modernize-use-using,
4247
-performance-move-const-arg,
48+
-performance-no-automatic-move,
4349
-performance-type-promotion-in-math-fn,
4450
-performance-unnecessary-copy-initialization,
4551
-performance-unnecessary-value-param,
4652
-readability-braces-around-statements,
4753
-readability-const-return-type,
4854
-readability-container-size-empty,
55+
-readability-convert-member-functions-to-static,
4956
-readability-delete-null-pointer,
5057
-readability-else-after-return,
5158
-readability-implicit-bool-conversion,
5259
-readability-inconsistent-declaration-parameter-name,
5360
-readability-isolate-declaration,
5461
-readability-magic-numbers,
62+
-readability-make-member-function-const,
5563
-readability-misleading-indentation,
5664
-readability-non-const-parameter,
65+
-readability-qualified-auto,
5766
-readability-redundant-control-flow,
5867
-readability-redundant-declaration,
5968
-readability-redundant-member-init,
69+
-readability-identifier-length,
6070
-readability-simplify-boolean-expr,
6171
-readability-static-accessed-through-instance,
6272
-readability-static-definition-in-anonymous-namespace,

3rd-party/cove/app/vectorizationconfigform.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "ui_vectorizationconfigform.h"
3232

33-
class QDoubleValidator;
3433
class QWidget;
3534

3635
namespace cove {
@@ -39,11 +38,9 @@ VectorizationConfigForm::VectorizationConfigForm(QWidget* parent)
3938
{
4039
ui.setupUi(this);
4140

42-
QDoubleValidator* dv;
4341
ui.shortPathLineEdit->setValidator(new QIntValidator(2, INT_MAX, this));
4442
ui.joinDistanceLineEdit->setValidator(
45-
dv = new QDoubleValidator(1, std::numeric_limits<double>::infinity(), 1,
46-
this));
43+
new QDoubleValidator(1, std::numeric_limits<double>::infinity(), 1, this));
4744
ui.distDirBalanceLineEdit->setValidator(
4845
new QDoubleValidator(0, 1, 2, this));
4946
}

3rd-party/cove/libvectorizer/Concurrency.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919

2020
#include "Concurrency.h"
2121

22-
#include <memory>
23-
24-
#include <QAtomicInteger>
25-
2622

2723
namespace cove {
2824

@@ -36,6 +32,11 @@ namespace Concurrency {
3632

3733
// ### Concurrency::Progress ###
3834

35+
static_assert(std::is_copy_constructible<Progress>::value, "Concurrency::Progress must be copy constructible.");
36+
static_assert(std::is_move_constructible<Progress>::value, "Concurrency::Progress must be move constructible.");
37+
static_assert(!std::is_copy_assignable<Progress>::value, "Concurrency::Progress is not copy assignable.");
38+
static_assert(!std::is_move_assignable<Progress>::value, "Concurrency::Progress is not move assignable.");
39+
3940
int Progress::getPercentage() const noexcept
4041
{
4142
return data->percentage.load();
@@ -65,6 +66,15 @@ void TransformedProgress::setPercentage(int percentage)
6566
}
6667

6768

69+
// ### Concurrency::Job ###
70+
71+
using ArbitraryResultType = int;
72+
static_assert(std::is_copy_constructible<Job<ArbitraryResultType>>::value, "Concurrency::Job must be copy constructible.");
73+
static_assert(std::is_move_constructible<Job<ArbitraryResultType>>::value, "Concurrency::Job must be move constructible.");
74+
static_assert(!std::is_copy_assignable<Job<ArbitraryResultType>>::value, "Concurrency::Job is not copy assignable.");
75+
static_assert(!std::is_move_assignable<Job<ArbitraryResultType>>::value, "Concurrency::Job is not move assignable.");
76+
77+
6878
} // namespace Concurrency
6979

7080
} // cove

3rd-party/cove/libvectorizer/Concurrency.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ namespace Concurrency {
4141
/**
4242
* A class for the exchange of progress state during concurrent processing.
4343
*
44-
* In order to allow copies to be made as needed by QtConcurrent,
45-
* the actual data is held via a std::shared_ptr. This std::shared_ptr object
46-
* is const in order to ensure thread safety also in accessing this object
44+
* Copies of a Progress object share the same progress state.
45+
* The actual data is held via a const std::shared_ptr, enabling
46+
* shared ownership and safe concurrent access from multiple threads
4747
* (cf. std::shared_ptr documentation).
48+
*
49+
* Assignment is not supported. It would require extra synchronization
50+
* for concurrent access to the same object.
4851
*/
4952
class Progress final : public ProgressObserver
5053
{
@@ -59,7 +62,7 @@ class Progress final : public ProgressObserver
5962
public:
6063
Progress() : data(std::make_shared<Data>()) {}
6164
Progress(const Progress&) = default;
62-
Progress(Progress&& p) = delete;
65+
Progress(Progress&& p) noexcept : Progress(static_cast<const Progress&>(p)) {}; // copy from const
6366
Progress& operator=(const Progress&) = delete;
6467
Progress& operator=(Progress&& p) = delete;
6568
~Progress() override = default;
@@ -102,6 +105,8 @@ struct TransformedProgress : public ProgressObserver
102105
*
103106
* It features the `QFuture` which signals the thread's total state and result,
104107
* and `Progress` information which is shared with the worker activity.
108+
*
109+
* Assignment is not supported, following the choice made for Progress.
105110
*/
106111
template <typename ResultType>
107112
struct Job
@@ -113,11 +118,11 @@ struct Job
113118
char padding[64 - (sizeof(future) - sizeof(progress)) % 64] = {}; // NOLINT
114119

115120
Job() = delete;
116-
Job(Job const&) = delete;
117-
Job(Job&& cj) noexcept : future(std::move(cj.future)), progress(cj.progress) {}
121+
Job(Job const&) = default;
122+
Job(Job&& j) noexcept : Job(std::move(j.future), j.progress) {};
118123
Job(QFuture<ResultType>&& f, const Progress& p) noexcept : future(std::move(f)), progress(p) {}
119124
Job& operator=(Job const&) = delete;
120-
Job& operator=(Job&& job) noexcept { future = std::move(job.future); progress = job.progress; }
125+
Job& operator=(Job&& job) = delete;
121126
~Job() = default;
122127
};
123128

3rd-party/cove/libvectorizer/Polygons.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
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

@@ -50,7 +49,6 @@ do \
5049
if (JOIN_DEBUG) qDebug(__VA_ARGS__); \
5150
} while (0)
5251

53-
using namespace std;
5452

5553
namespace cove {
5654
const 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

3rd-party/cove/libvectorizer/Polygons.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#ifndef COVE_POLYGONS_H
2222
#define COVE_POLYGONS_H
2323

24-
#include <algorithm>
25-
#include <functional>
2624
#include <limits>
2725
#include <vector>
2826

@@ -143,15 +141,6 @@ class Polygons
143141

144142
typedef std::vector<JOINENDPOINT> JOINENDPOINTLIST;
145143

146-
struct greater_weight
147-
: public std::binary_function<const JOINOP&, const JOINOP&, bool>
148-
{
149-
bool operator()(const JOINOP& x, const JOINOP& y)
150-
{
151-
return x.weight > y.weight;
152-
}
153-
};
154-
155144
// implementation dependent value...
156145
static const int NPOINTS_MAX;
157146

3rd-party/cove/libvectorizer/Vectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void Vectorizer::setInitColors(const std::vector<QRgb>& initColors)
301301
}
302302
}
303303

304-
/*! Runs classfication. The progress observer is called during work if set.
304+
/*! Runs classification. The progress observer is called during work if set.
305305
* \param[in] progressObserver Pointer to class implementing ProgressObserver.
306306
* In case it is null pointer no calls take place.
307307
*/

3rd-party/cove/potrace/trace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ int bestpolygon(privpath_t *pp)
564564
SAFE_MALLOC(seg0, n+1, int);
565565
SAFE_MALLOC(seg1, n+1, int);
566566

567+
if (n > 2) {
567568
/* calculate clipped paths */
568569
if(pp->closed) {
569570
for (i=0; i<n; i++) {
@@ -649,6 +650,13 @@ int bestpolygon(privpath_t *pp)
649650
}
650651
if(!pp->closed)
651652
pp->po[m-1] = n-1;
653+
} else {
654+
// n <= 2, shouldn't occur after despeckling
655+
pp->m = 2;
656+
SAFE_MALLOC(pp->po, 2, int);
657+
pp->po[0] = 0;
658+
pp->po[1] = n-1;
659+
}
652660

653661
free(pen);
654662
free(prev);

3rd-party/cove/tests/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
2-
3-
# project(CoveTests)
4-
51
find_package(Qt5Core ${Qt5Core_VERSION} REQUIRED)
62
find_package(Qt5Gui ${Qt5Core_VERSION} REQUIRED)
73
find_package(Qt5Test ${Qt5Core_VERSION} REQUIRED)
@@ -38,6 +34,9 @@ add_test(
3834
add_executable(cove-PolygonBenchmark EXCLUDE_FROM_ALL
3935
PolygonTest.cpp
4036
)
37+
target_link_libraries(cove-PolygonBenchmark
38+
PRIVATE cove-test-config
39+
)
4140
target_compile_definitions(cove-PolygonBenchmark
4241
PRIVATE
4342
COVE_BENCHMARK=QBENCHMARK

0 commit comments

Comments
 (0)