Skip to content

Commit 495ccd2

Browse files
committed
feat: use clipper c++ lib version 1.5.4
Updates to version 1.5.4 of the clipper2 library. Also retains ClipType None instead of the renamed NoClip to prevent breaking changes.
1 parent fb47275 commit 495ccd2

File tree

170 files changed

+10748
-16668
lines changed

Some content is hidden

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

170 files changed

+10748
-16668
lines changed

clipper2c/src/conv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ClipperClipType to_c(Clipper2Lib::ClipType cliptype)
7676
ClipperClipType ct = NONE;
7777
switch (cliptype)
7878
{
79-
case Clipper2Lib::ClipType::None:
79+
case Clipper2Lib::ClipType::NoClip:
8080
break;
8181
case Clipper2Lib::ClipType::Intersection:
8282
ct = INTERSECTION;
@@ -251,7 +251,7 @@ Clipper2Lib::SvgReader *from_c(ClipperSvgReader *p)
251251

252252
Clipper2Lib::ClipType from_c(ClipperClipType fr)
253253
{
254-
Clipper2Lib::ClipType clipType = Clipper2Lib::ClipType::None;
254+
Clipper2Lib::ClipType clipType = Clipper2Lib::ClipType::NoClip;
255255
switch (fr)
256256
{
257257
case NONE:
@@ -351,4 +351,4 @@ Clipper2Lib::PointInPolygonResult from_c(ClipperPointInPolygonResult result)
351351
break;
352352
};
353353
return res;
354-
}
354+
}

clipper2c/vendor/Clipper2/CPP/BenchMark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ foreach(benchmark ${benchmark_srcs})
7777
Clipper2_bm
7878
Clipper2utils_bm
7979
)
80-
endforeach()
80+
endforeach()

clipper2c/vendor/Clipper2/CPP/BenchMark/GetIntersectPtBenchmark.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "clipper2/clipper.core.h"
44
#include "CommonUtils.h"
55
#include "ClipFileLoad.h"
6-
#include <iomanip>
6+
#include <iomanip>
77
#include <cstdlib>
88
#include <random>
99

@@ -180,7 +180,7 @@ static inline Int128 multiply(int64_t lhs, int64_t rhs)
180180

181181
static int64_t divide(Int128 dividend, Int128 divisor)
182182
{
183-
// this function assumes that the parameter values will
183+
// this function assumes that the parameter values will
184184
// generate a result that fits into a 64bit integer.
185185
bool negate = (divisor.hi < 0) != (dividend.hi < 0);
186186
if (dividend.hi < 0) dividend = -dividend;
@@ -231,15 +231,15 @@ static int64_t divide(Int128 dividend, Int128 divisor)
231231
cntr.lo |= 0x8000000000000000LL;
232232
cntr.hi >>= 1;
233233
}
234-
if (result.hi || (int64_t)result.lo < 0)
234+
if (result.hi || (int64_t)result.lo < 0)
235235
return negate ? INT64_MIN : INT64_MAX;
236236
else
237237
return negate ? -(int64_t)result.lo : result.lo;
238238
}
239239

240240
static inline int64_t muldiv(Int128 lhs, int64_t rhs, Int128 divisor)
241241
{
242-
// this function assumes that the parameter values will
242+
// this function assumes that the parameter values will
243243
// generate a result that fits into a 64bit integer.
244244
int64_t sign = (lhs.is_negative() != divisor.is_negative()) != (rhs < 0) ? -2 : 2;
245245
if (lhs.is_negative()) lhs.negate();
@@ -276,7 +276,7 @@ typedef std::function<bool(const Point64&, const Point64&,
276276
const Point64&, const Point64&, Point64&)> GipFunction;
277277

278278
// GIP_Current: This is Clipper2's current GetIntersectPoint.
279-
// It's definitely the fastest function, but its accuracy declines
279+
// It's definitely the fastest function, but its accuracy declines
280280
// a little when using very large 64bit integers (eg +/-10e17).
281281
static bool GIP_Current(const Point64& ln1a, const Point64& ln1b,
282282
const Point64& ln2a, const Point64& ln2b, Point64& ip)
@@ -333,8 +333,8 @@ static bool GIP_Func_F(const Point64& ln1a, const Point64& ln1b,
333333
}
334334

335335
// GIP_F_Mod: GIP_Func_F except replaces nearbyint with static casts.
336-
// Surprisingly, while this function is faster that GIP_Func_F here,
337-
// it's much slower than both GIP_Func_F and GIP_Current when using it
336+
// Surprisingly, while this function is faster that GIP_Func_F here,
337+
// it's much slower than both GIP_Func_F and GIP_Current when using it
338338
// as a replacement for GetIntersectPoint() in clipper.core.h.
339339
static bool GIP_F_Mod(const Point64& ln1a, const Point64& ln1b,
340340
const Point64& ln2a, const Point64& ln2b, Point64& ip)
@@ -364,7 +364,7 @@ static bool GIP_F_Mod(const Point64& ln1a, const Point64& ln1b,
364364
return true;
365365
}
366366

367-
// GIP_128: GetIntersectPoint using 128bit integer precision
367+
// GIP_128: GetIntersectPoint using 128bit integer precision
368368
// This function is the most precise, but it's also very slow.
369369
static bool GIP_128(const Point64& ln1a, const Point64& ln1b,
370370
const Point64& ln2a, const Point64& ln2b, Point64& ip)
@@ -394,10 +394,10 @@ static inline GipFunction GetGipFunc(int64_t index)
394394
{
395395
switch (index)
396396
{
397-
case 0: return GIP_Current;
397+
case 0: return GIP_Current;
398398
case 1: return GIP_Func_F;
399399
case 2: return GIP_F_Mod;
400-
case 3: return GIP_128;
400+
case 3: return GIP_128;
401401
default: throw "Invalid function!";
402402
}
403403
}
@@ -407,9 +407,9 @@ static inline std::string GetGipFuncName(int64_t index)
407407
switch (index)
408408
{
409409
case 0: return "GIP_Current";
410-
case 1: return "GIP_Func_F ";
411-
case 2: return "GIP_F_Mod ";
412-
case 3: return "GIP_128 ";
410+
case 1: return "GIP_Func_F ";
411+
case 2: return "GIP_F_Mod ";
412+
case 3: return "GIP_128 ";
413413
default: throw "Invalid function!";
414414
}
415415
}
@@ -476,7 +476,7 @@ static void BM_GIP(benchmark::State& state)
476476

477477
static void CustomArguments(benchmark::internal::Benchmark* b)
478478
{
479-
for (int i = 0; i < number_of_test_functions; ++i)
479+
for (int i = 0; i < number_of_test_functions; ++i)
480480
b->Args({ i });
481481
}
482482

@@ -490,16 +490,16 @@ int main(int argc, char** argv)
490490
benchmark::Initialize(0, nullptr);
491491
BENCHMARK(BM_GIP)->Apply(CustomArguments);
492492

493-
// the closer test segments are to collinear, the less accurate
493+
// the closer test segments are to collinear, the less accurate
494494
// calculations will be in determining their intersection points.
495495
const double min_angle_degrees = 0.5;
496496
const double sine_min_angle = std::sin(min_angle_degrees *PI / 180.0);
497497

498498
bool first_pass = true;
499499
for (int current_pow10 = 12; current_pow10 <= 18; ++current_pow10)
500500
{
501-
// using random coordinates that are restricted to the specified
502-
// power of 10 range, create multiple TestRecords containing
501+
// using random coordinates that are restricted to the specified
502+
// power of 10 range, create multiple TestRecords containing
503503
// segment pairs that intersect at their midpoints
504504
int64_t max_coord = static_cast<int64_t>(pow(10, current_pow10));
505505
for (int64_t i = 0; i < 100000; ++i)
@@ -511,7 +511,7 @@ int main(int argc, char** argv)
511511
Point64 ip4 = ReflectPoint(ip3, actual);
512512

513513
// Exclude segments that are **almost** collinear.
514-
if (std::abs(GetSineFrom3Points(ip1, actual, ip3)) < sine_min_angle) continue;
514+
if (std::abs(GetSineFrom3Points(ip1, actual, ip3)) < sine_min_angle) continue;
515515
// Alternatively, just exclude segments that are collinear
516516
//if (!CrossProduct(ip1, actual, ip3)) continue;
517517

@@ -576,4 +576,4 @@ int main(int argc, char** argv)
576576
tests.clear();
577577
}
578578
return 0;
579-
}
579+
}

clipper2c/vendor/Clipper2/CPP/BenchMark/PointInPolygonBenchmark.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ inline PointInPolygonResult PIP2(const Point64& pt, const Path64& polygon)
195195
}
196196

197197
/////////////////////////////////////////////////////////
198-
// PIP3: An entirely different algorithm for comparision.
198+
// PIP3: An entirely different algorithm for comparison.
199199
// "Optimal Reliable Point-in-Polygon Test and
200200
// Differential Coding Boolean Operations on Polygons"
201201
// by Jianqiang Hao et al.
@@ -252,7 +252,7 @@ static PointInPolygonResult PIP3(const Point64&pt, const Path64&path)
252252
// global data structures
253253
/////////////////////////////////////////////////////////
254254

255-
const Path64 points_of_interest_outside =
255+
const Path64 points_of_interest_outside =
256256
MakePath({ 21887,10420, 21726,10825, 21662,10845, 21617,10890 });
257257
const Path64 points_of_interest_inside =
258258
MakePath({ 21887,10430, 21843,10520, 21810,10686, 21900,10461 });
@@ -393,11 +393,11 @@ int main(int argc, char** argv)
393393
std::endl;
394394

395395
//////////////////////////////////////////////////////////////
396-
// 1. Very basic error testing
396+
// 1. Very basic error testing
397397
//////////////////////////////////////////////////////////////
398398

399399
std::cout << std::endl << SetConsoleTextColor(yellow_bold) <<
400-
"Tests for errors #1:" << SetConsoleTextColor(reset) << std::endl <<
400+
"Tests for errors #1:" << SetConsoleTextColor(reset) << std::endl <<
401401
"(Reusing 'TestPolytreeHoles' tests)" << std::endl << std::endl;
402402

403403
// 1a. use const paths (PolytreeHoleOwner2.txt) with changing points of interest
@@ -412,7 +412,7 @@ int main(int argc, char** argv)
412412
if (!ifs || !ifs.good()) return 1;
413413
LoadTestNum(ifs, 1, paths, subject_open, clip, _, __, ___, ____);
414414
ifs.close();
415-
415+
416416
for (int i = 0; i < 3; ++i) DoErrorTest1(i);
417417

418418
// 1b. Use a const point of interest (10,10) against various paths
@@ -451,7 +451,7 @@ int main(int argc, char** argv)
451451

452452
std::cout << std::endl << SetConsoleTextColor(cyan_bold) <<
453453
"Benchmarking ..." << SetConsoleTextColor(reset) << std::endl;
454-
std::cout << "Note: function performance varies depending on the proportion of edges" <<
454+
std::cout << "Note: function performance varies depending on the proportion of edges" <<
455455
std::endl << "that intersect with an imaginary horizontal line passing through the" <<
456456
std::endl << "point of interest." << std::endl << std::endl;
457457

@@ -479,7 +479,7 @@ int main(int argc, char** argv)
479479
BENCHMARK(BM_PIP2)->Apply(CustomArguments); // modified Clipper2
480480
BENCHMARK(BM_PIP3)->Apply(CustomArguments); // Hao et al. (2018)
481481
benchmark::RunSpecifiedBenchmarks(benchmark::CreateDefaultDisplayReporter());
482-
482+
483483
std::cout << std::endl << std::endl << SetConsoleTextColor(yellow_bold) <<
484484
"Benchmarks 2:" << SetConsoleTextColor(reset) << std::endl;
485485

@@ -521,4 +521,4 @@ int main(int argc, char** argv)
521521
break;
522522
}
523523

524-
}
524+
}

clipper2c/vendor/Clipper2/CPP/BenchMark/StripDuplicateBenchmark.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
using namespace Clipper2Lib;
77

8-
// globals
8+
// globals
99
Paths64 test_paths;
1010

1111
// Previous (slow) StripDuplicates function - copies path
1212
template <typename T>
13-
inline Path<T> StripDuplicates1(const Path<T> &path, bool is_closed_path)
14-
{
13+
inline Path<T> StripDuplicates1(const Path<T> &path, bool is_closed_path)
14+
{
1515
if (path.size() == 0) return Path<T>();
1616
Path<T> result;
1717
result.reserve(path.size());
@@ -42,24 +42,24 @@ inline void StripDuplicates2(Path<T>& path, bool is_closed_path)
4242

4343
static void StripDuplicates_OLD(benchmark::State &state)
4444
{
45-
for (auto _ : state)
45+
for (auto _ : state)
4646
{
4747
for (Path64& p: test_paths)
4848
p = StripDuplicates1(p, true);
4949
}
5050
}
5151

52-
static void StripDuplicates_NEW(benchmark::State &state)
52+
static void StripDuplicates_NEW(benchmark::State &state)
5353
{
5454
for (auto _ : state) {
5555
for (Path64& p : test_paths)
56-
StripDuplicates2(p, true);
56+
StripDuplicates2(p, true);
5757
}
5858
}
5959

6060

6161
int main(int argc, char** argv)
62-
{
62+
{
6363
const size_t max_paths = 5;
6464
const int width = 6000, height = 4000, count = 10000;
6565
test_paths.reserve(max_paths);
@@ -70,4 +70,4 @@ int main(int argc, char** argv)
7070
BENCHMARK(StripDuplicates_OLD);
7171
BENCHMARK(StripDuplicates_NEW);
7272
benchmark::RunSpecifiedBenchmarks(benchmark::CreateDefaultDisplayReporter());
73-
}
73+
}

0 commit comments

Comments
 (0)