Skip to content

Commit 100225c

Browse files
committed
clipper2: Update to 1.5.2
1 parent 261e7d3 commit 100225c

15 files changed

+625
-376
lines changed

COPYRIGHT.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ License: MPL-2.0
200200

201201
Files: thirdparty/clipper2/*
202202
Comment: Clipper2
203-
Copyright: 2010-2024, Angus Johnson
203+
Copyright: 2010-2025, Angus Johnson
204204
License: BSL-1.0
205205

206206
Files: thirdparty/cvtt/*

thirdparty/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Files extracted from upstream source:
107107
## clipper2
108108

109109
- Upstream: https://github.com/AngusJohnson/Clipper2
110-
- Version: 1.4.0 (736ddb0b53d97fd5f65dd3d9bbf8a0993eaf387c, 2024)
110+
- Version: 1.5.2 (6901921c4be75126d1de60bfd24bd86a61319fd0, 2025)
111111
- License: BSL 1.0
112112

113113
Files extracted from upstream source:
@@ -118,7 +118,7 @@ Files extracted from upstream source:
118118
Patches:
119119

120120
- `0001-disable-exceptions.patch` (GH-80796)
121-
- `0002-llvm-disable-int1280-math.patch` (GH-95964)
121+
- `0002-llvm-disable-int128-math.patch` (GH-95964)
122122

123123

124124
## cvtt

thirdparty/clipper2/include/clipper2/clipper.core.h

+46-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
33
* Date : 12 May 2024 *
4-
* Website : http://www.angusj.com *
4+
* Website : https://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2024 *
66
* Purpose : Core Clipper Library structures and functions *
7-
* License : http://www.boost.org/LICENSE_1_0.txt *
7+
* License : https://www.boost.org/LICENSE_1_0.txt *
88
*******************************************************************************/
99

1010
#ifndef CLIPPER_CORE_H
1111
#define CLIPPER_CORE_H
1212

13+
#include "clipper2/clipper.version.h"
1314
#include <cstdint>
14-
#include <cstdlib>
15-
#include <cmath>
1615
#include <vector>
1716
#include <string>
1817
#include <iostream>
1918
#include <algorithm>
20-
#include <climits>
2119
#include <numeric>
22-
#include <optional>
23-
#include "clipper2/clipper.version.h"
20+
#include <cmath>
2421

2522
#define CLIPPER2_THROW(exception) std::abort()
2623

@@ -33,7 +30,7 @@ namespace Clipper2Lib
3330
public:
3431
explicit Clipper2Exception(const char* description) :
3532
m_descr(description) {}
36-
virtual const char* what() const throw() override { return m_descr.c_str(); }
33+
virtual const char* what() const noexcept override { return m_descr.c_str(); }
3734
private:
3835
std::string m_descr;
3936
};
@@ -90,6 +87,9 @@ namespace Clipper2Lib
9087
CLIPPER2_THROW(Clipper2Exception(undefined_error));
9188
case range_error_i:
9289
CLIPPER2_THROW(Clipper2Exception(range_error));
90+
// Should never happen, but adding this to stop a compiler warning
91+
default:
92+
CLIPPER2_THROW(Clipper2Exception("Unknown error"));
9393
}
9494
#else
9595
if(error_code) {}; // only to stop compiler 'parameter not used' warning
@@ -109,17 +109,21 @@ namespace Clipper2Lib
109109
//https://en.wikipedia.org/wiki/Nonzero-rule
110110
enum class FillRule { EvenOdd, NonZero, Positive, Negative };
111111

112+
#ifdef USINGZ
113+
using z_type = int64_t;
114+
#endif
115+
112116
// Point ------------------------------------------------------------------------
113117

114118
template <typename T>
115119
struct Point {
116120
T x;
117121
T y;
118122
#ifdef USINGZ
119-
int64_t z;
123+
z_type z;
120124

121125
template <typename T2>
122-
inline void Init(const T2 x_ = 0, const T2 y_ = 0, const int64_t z_ = 0)
126+
inline void Init(const T2 x_ = 0, const T2 y_ = 0, const z_type z_ = 0)
123127
{
124128
if constexpr (std::is_integral_v<T> &&
125129
is_round_invocable<T2>::value && !std::is_integral_v<T2>)
@@ -139,7 +143,7 @@ namespace Clipper2Lib
139143
explicit Point() : x(0), y(0), z(0) {};
140144

141145
template <typename T2>
142-
Point(const T2 x_, const T2 y_, const int64_t z_ = 0)
146+
Point(const T2 x_, const T2 y_, const z_type z_ = 0)
143147
{
144148
Init(x_, y_);
145149
z = z_;
@@ -152,7 +156,7 @@ namespace Clipper2Lib
152156
}
153157

154158
template <typename T2>
155-
explicit Point(const Point<T2>& p, int64_t z_)
159+
explicit Point(const Point<T2>& p, z_type z_)
156160
{
157161
Init(p.x, p.y, z_);
158162
}
@@ -162,7 +166,7 @@ namespace Clipper2Lib
162166
return Point(x * scale, y * scale, z);
163167
}
164168

165-
void SetZ(const int64_t z_value) { z = z_value; }
169+
void SetZ(const z_type z_value) { z = z_value; }
166170

167171
friend std::ostream& operator<<(std::ostream& os, const Point& point)
168172
{
@@ -326,10 +330,10 @@ namespace Clipper2Lib
326330
{
327331
Path<T> result;
328332
result.reserve(4);
329-
result.push_back(Point<T>(left, top));
330-
result.push_back(Point<T>(right, top));
331-
result.push_back(Point<T>(right, bottom));
332-
result.push_back(Point<T>(left, bottom));
333+
result.emplace_back(left, top);
334+
result.emplace_back(right, top);
335+
result.emplace_back(right, bottom);
336+
result.emplace_back(left, bottom);
333337
return result;
334338
}
335339

@@ -364,6 +368,22 @@ namespace Clipper2Lib
364368
top == other.top && bottom == other.bottom;
365369
}
366370

371+
Rect<T>& operator+=(const Rect<T>& other)
372+
{
373+
left = (std::min)(left, other.left);
374+
top = (std::min)(top, other.top);
375+
right = (std::max)(right, other.right);
376+
bottom = (std::max)(bottom, other.bottom);
377+
return *this;
378+
}
379+
380+
Rect<T> operator+(const Rect<T>& other) const
381+
{
382+
Rect<T> result = *this;
383+
result += other;
384+
return result;
385+
}
386+
367387
friend std::ostream& operator<<(std::ostream& os, const Rect<T>& rect) {
368388
os << "(" << rect.left << "," << rect.top << "," << rect.right << "," << rect.bottom << ") ";
369389
return os;
@@ -597,13 +617,13 @@ namespace Clipper2Lib
597617
result.reserve(path.size());
598618
typename Path<T>::const_iterator path_iter = path.cbegin();
599619
Point<T> first_pt = *path_iter++, last_pt = first_pt;
600-
result.push_back(first_pt);
620+
result.emplace_back(first_pt);
601621
for (; path_iter != path.cend(); ++path_iter)
602622
{
603623
if (!NearEqual(*path_iter, last_pt, max_dist_sqrd))
604624
{
605625
last_pt = *path_iter;
606-
result.push_back(last_pt);
626+
result.emplace_back(last_pt);
607627
}
608628
}
609629
if (!is_closed_path) return result;
@@ -621,7 +641,7 @@ namespace Clipper2Lib
621641
for (typename Paths<T>::const_iterator paths_citer = paths.cbegin();
622642
paths_citer != paths.cend(); ++paths_citer)
623643
{
624-
result.push_back(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path));
644+
result.emplace_back(std::move(StripNearEqual(*paths_citer, max_dist_sqrd, is_closed_path)));
625645
}
626646
return result;
627647
}
@@ -697,11 +717,11 @@ namespace Clipper2Lib
697717
{
698718
// Work around LLVM issue: https://github.com/llvm/llvm-project/issues/16778
699719
// Details: https://github.com/godotengine/godot/pull/95964#issuecomment-2306581804
700-
//#if (defined(__clang__) || defined(__GNUC__)) && UINTPTR_MAX >= UINT64_MAX
701-
// const auto ab = static_cast<__int128_t>(a) * static_cast<__int128_t>(b);
702-
// const auto cd = static_cast<__int128_t>(c) * static_cast<__int128_t>(d);
703-
// return ab == cd;
704-
//#else
720+
// #if (defined(__clang__) || defined(__GNUC__)) && UINTPTR_MAX >= UINT64_MAX
721+
// const auto ab = static_cast<__int128_t>(a) * static_cast<__int128_t>(b);
722+
// const auto cd = static_cast<__int128_t>(c) * static_cast<__int128_t>(d);
723+
// return ab == cd;
724+
// #else
705725
// nb: unsigned values needed for calculating overflow carry
706726
const auto abs_a = static_cast<uint64_t>(std::abs(a));
707727
const auto abs_b = static_cast<uint64_t>(std::abs(b));
@@ -768,7 +788,7 @@ namespace Clipper2Lib
768788
const Point<T>& line1, const Point<T>& line2)
769789
{
770790
//perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²)
771-
//see http://en.wikipedia.org/wiki/Perpendicular_distance
791+
//see https://en.wikipedia.org/wiki/Perpendicular_distance
772792
double a = static_cast<double>(pt.x - line1.x);
773793
double b = static_cast<double>(pt.y - line1.y);
774794
double c = static_cast<double>(line2.x - line1.x);

thirdparty/clipper2/include/clipper2/clipper.engine.h

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
/*******************************************************************************
22
* Author : Angus Johnson *
3-
* Date : 5 July 2024 *
4-
* Website : http://www.angusj.com *
3+
* Date : 17 September 2024 *
4+
* Website : https://www.angusj.com *
55
* Copyright : Angus Johnson 2010-2024 *
66
* Purpose : This is the main polygon clipping module *
7-
* License : http://www.boost.org/LICENSE_1_0.txt *
7+
* License : https://www.boost.org/LICENSE_1_0.txt *
88
*******************************************************************************/
99

1010
#ifndef CLIPPER_ENGINE_H
1111
#define CLIPPER_ENGINE_H
1212

13-
#include <cstdlib>
14-
#include <stdint.h> //#541
15-
#include <iostream>
13+
#include "clipper2/clipper.core.h"
1614
#include <queue>
17-
#include <vector>
1815
#include <functional>
19-
#include <numeric>
2016
#include <memory>
2117

22-
#include "clipper2/clipper.core.h"
23-
2418
namespace Clipper2Lib {
2519

2620
struct Scanline;
@@ -32,13 +26,13 @@ namespace Clipper2Lib {
3226
struct HorzSegment;
3327

3428
//Note: all clipping operations except for Difference are commutative.
35-
enum class ClipType { None, Intersection, Union, Difference, Xor };
29+
enum class ClipType { NoClip, Intersection, Union, Difference, Xor };
3630

3731
enum class PathType { Subject, Clip };
38-
enum class JoinWith { None, Left, Right };
32+
enum class JoinWith { NoJoin, Left, Right };
3933

4034
enum class VertexFlags : uint32_t {
41-
None = 0, OpenStart = 1, OpenEnd = 2, LocalMax = 4, LocalMin = 8
35+
Empty = 0, OpenStart = 1, OpenEnd = 2, LocalMax = 4, LocalMin = 8
4236
};
4337

4438
constexpr enum VertexFlags operator &(enum VertexFlags a, enum VertexFlags b)
@@ -55,7 +49,7 @@ namespace Clipper2Lib {
5549
Point64 pt;
5650
Vertex* next = nullptr;
5751
Vertex* prev = nullptr;
58-
VertexFlags flags = VertexFlags::None;
52+
VertexFlags flags = VertexFlags::Empty;
5953
};
6054

6155
struct OutPt {
@@ -131,7 +125,7 @@ namespace Clipper2Lib {
131125
Vertex* vertex_top = nullptr;
132126
LocalMinima* local_min = nullptr; // the bottom of an edge 'bound' (also Vatti)
133127
bool is_left_bound = false;
134-
JoinWith join_with = JoinWith::None;
128+
JoinWith join_with = JoinWith::NoJoin;
135129
};
136130

137131
struct LocalMinima {
@@ -167,7 +161,7 @@ namespace Clipper2Lib {
167161
};
168162

169163
#ifdef USINGZ
170-
typedef std::function<void(const Point64& e1bot, const Point64& e1top,
164+
typedef std::function<void(const Point64& e1bot, const Point64& e1top,
171165
const Point64& e2bot, const Point64& e2top, Point64& pt)> ZCallback64;
172166

173167
typedef std::function<void(const PointD& e1bot, const PointD& e1top,
@@ -197,7 +191,7 @@ namespace Clipper2Lib {
197191

198192
class ClipperBase {
199193
private:
200-
ClipType cliptype_ = ClipType::None;
194+
ClipType cliptype_ = ClipType::NoClip;
201195
FillRule fillrule_ = FillRule::EvenOdd;
202196
FillRule fillpos = FillRule::Positive;
203197
int64_t bot_y_ = 0;
@@ -210,7 +204,7 @@ namespace Clipper2Lib {
210204
std::vector<Vertex*> vertex_lists_;
211205
std::priority_queue<int64_t> scanline_list_;
212206
IntersectNodeList intersect_nodes_;
213-
HorzSegmentList horz_seg_list_;
207+
HorzSegmentList horz_seg_list_;
214208
std::vector<HorzJoin> horz_join_list_;
215209
void Reset();
216210
inline void InsertScanline(int64_t y);

0 commit comments

Comments
 (0)