Skip to content

Commit e960879

Browse files
committed
version 1.0.6
Additional clipper.export.h bugfixes Additional bugfixes in DLL sample app Minor tweaks to clipper.engine (C++)
1 parent 09d6cc4 commit e960879

5 files changed

Lines changed: 452 additions & 143 deletions

File tree

CPP/Clipper2Lib/include/clipper2/clipper.engine.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef CLIPPER_ENGINE_H
1111
#define CLIPPER_ENGINE_H
1212

13-
#define CLIPPER2_VERSION "1.0.5"
13+
#define CLIPPER2_VERSION "1.0.6"
1414

1515
#include <cstdlib>
1616
#include <queue>
@@ -159,7 +159,6 @@ namespace Clipper2Lib {
159159
FillRule fillrule_ = FillRule::EvenOdd;
160160
FillRule fillpos = FillRule::Positive;
161161
int64_t bot_y_ = 0;
162-
bool has_open_paths_ = false;
163162
bool minima_list_sorted_ = false;
164163
bool using_polytree_ = false;
165164
Active* actives_ = nullptr;
@@ -170,7 +169,6 @@ namespace Clipper2Lib {
170169
std::vector<Vertex*> vertex_lists_;
171170
std::priority_queue<int64_t> scanline_list_;
172171
std::vector<IntersectNode> intersect_nodes_;
173-
std::vector<OutRec*> outrec_list_; //pointers in case of memory reallocs
174172
std::vector<Joiner*> joiner_list_; //pointers in case of memory reallocs
175173
void Reset();
176174
void InsertScanline(int64_t y);
@@ -224,13 +222,12 @@ namespace Clipper2Lib {
224222
void DeleteJoin(Joiner* joiner);
225223
void ProcessJoinerList();
226224
OutRec* ProcessJoin(Joiner* joiner);
227-
bool DeepCheckOwner(OutRec* outrec, OutRec* owner);
228225
protected:
226+
bool has_open_paths_ = false;
229227
bool succeeded_ = true;
228+
std::vector<OutRec*> outrec_list_; //pointers in case list memory reallocated
230229
bool ExecuteInternal(ClipType ct, FillRule ft, bool use_polytrees);
231-
void BuildPaths(Paths64& solutionClosed, Paths64* solutionOpen);
232-
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
233-
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
230+
bool DeepCheckOwner(OutRec* outrec, OutRec* owner);
234231
#ifdef USINGZ
235232
ZCallback64 zCallback_ = nullptr;
236233
void SetZ(const Active& e1, const Active& e2, Point64& pt);
@@ -412,6 +409,9 @@ namespace Clipper2Lib {
412409

413410
class Clipper64 : public ClipperBase
414411
{
412+
private:
413+
void BuildPaths64(Paths64& solutionClosed, Paths64* solutionOpen);
414+
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
415415
public:
416416
#ifdef USINGZ
417417
void SetZCallback(ZCallback64 cb) { zCallback_ = cb; }
@@ -443,7 +443,7 @@ namespace Clipper2Lib {
443443
closed_paths.clear();
444444
open_paths.clear();
445445
if (ExecuteInternal(clip_type, fill_rule, false))
446-
BuildPaths(closed_paths, &open_paths);
446+
BuildPaths64(closed_paths, &open_paths);
447447
CleanUp();
448448
return succeeded_;
449449
}
@@ -474,6 +474,8 @@ namespace Clipper2Lib {
474474
#ifdef USINGZ
475475
ZCallbackD zCallback_ = nullptr;
476476
#endif
477+
void BuildPathsD(PathsD& solutionClosed, PathsD* solutionOpen);
478+
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
477479
public:
478480
explicit ClipperD(int precision = 2) : ClipperBase()
479481
{
@@ -544,10 +546,7 @@ namespace Clipper2Lib {
544546
#endif
545547
if (ExecuteInternal(clip_type, fill_rule, false))
546548
{
547-
Paths64 sol, solo;
548-
BuildPaths(sol, &solo);
549-
closed_paths = ScalePaths<double, int64_t>(sol, invScale_);
550-
open_paths = ScalePaths<double, int64_t>(solo, invScale_);
549+
BuildPathsD(closed_paths, &open_paths);
551550
}
552551
CleanUp();
553552
return succeeded_;

CPP/Clipper2Lib/include/clipper2/clipper.export.h

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ typedef int64_t** CPaths64;
5757
typedef double* CPathD;
5858
typedef double** CPathsD;
5959

60-
typedef struct CRect64 { int64_t val[4]; } CRect64;
61-
typedef struct CRectD { double val[4]; } CRectD;
62-
6360
typedef struct CPolyPath64 {
6461
CPath64 polygon;
6562
uint32_t is_hole;
@@ -76,6 +73,34 @@ typedef struct CPolyPathD {
7673
}
7774
CPolyTreeD;
7875

76+
template <typename T>
77+
struct CRect {
78+
T left;
79+
T top;
80+
T right;
81+
T bottom;
82+
};
83+
84+
typedef CRect<int64_t> CRect64;
85+
typedef CRect<double> CRectD;
86+
87+
template <typename T>
88+
inline bool CRectIsEmpty(const CRect<T>& rect)
89+
{
90+
return (rect.right <= rect.left) || (rect.bottom <= rect.top);
91+
}
92+
93+
template <typename T>
94+
inline Rect<T> CRectToRect(const CRect<T>& rect)
95+
{
96+
Rect<T> result;
97+
result.left = rect.left;
98+
result.top = rect.top;
99+
result.right = rect.right;
100+
result.bottom = rect.bottom;
101+
return result;
102+
}
103+
79104
inline CPath64 CreateCPath64(size_t cnt1, size_t cnt2);
80105
inline CPath64 CreateCPath64(const Path64& p);
81106
inline CPaths64 CreateCPaths64(const Paths64& pp);
@@ -99,6 +124,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale);
99124

100125
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)
101126

127+
102128
EXTERN_DLL_EXPORT const char* Version()
103129
{
104130
return CLIPPER2_VERSION;
@@ -258,7 +284,7 @@ EXTERN_DLL_EXPORT int BooleanOpPtD(uint8_t cliptype,
258284
return 0;
259285
}
260286

261-
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
287+
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
262288
double delta, uint8_t jt, uint8_t et, double miter_limit = 2.0,
263289
double arc_tolerance = 0.0, bool reverse_solution = false)
264290
{
@@ -272,7 +298,7 @@ EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
272298
return CreateCPaths64(result);
273299
}
274300

275-
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
301+
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
276302
double delta, uint8_t jt, uint8_t et,
277303
double precision = 2, double miter_limit = 2.0,
278304
double arc_tolerance = 0.0, bool reverse_solution = false)
@@ -286,20 +312,23 @@ EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
286312
return CreateCPathsD(result, 1/scale);
287313
}
288314

289-
EXTERN_DLL_EXPORT CPaths64 RectClip64(const Rect64 rect,
315+
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect,
290316
const CPaths64 paths)
291317
{
292-
if (rect.IsEmpty() || !paths) return nullptr;
293-
class RectClip rc(rect);
318+
log(rect.left);
319+
log(rect.right);
320+
if (CRectIsEmpty(rect) || !paths) return nullptr;
321+
Rect64 r64 = CRectToRect(rect);
322+
class RectClip rc(r64);
294323
Paths64 pp = ConvertCPaths64(paths);
295324
Paths64 result;
296325
result.reserve(pp.size());
297326
for (const Path64& p : pp)
298327
{
299328
Rect64 pathRec = Bounds(p);
300-
if (!rect.Intersects(pathRec)) continue;
329+
if (!r64.Intersects(pathRec)) continue;
301330

302-
if (rect.Contains(pathRec))
331+
if (r64.Contains(pathRec))
303332
result.push_back(p);
304333
else
305334
{
@@ -310,15 +339,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClip64(const Rect64 rect,
310339
return CreateCPaths64(result);
311340
}
312341

313-
EXTERN_DLL_EXPORT CPathsD RectClipD(const RectD rect,
342+
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect,
314343
const CPathsD paths, int precision = 2)
315344
{
316-
if (rect.IsEmpty() || !paths) return nullptr;
345+
if (CRectIsEmpty(rect) || !paths) return nullptr;
317346
if (precision < -8 || precision > 8) return nullptr;
318347
const double scale = std::pow(10, precision);
319-
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
348+
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
320349
Paths64 pp = ConvertCPathsD(paths, scale);
321-
322350
class RectClip rc(r);
323351
Paths64 result;
324352
result.reserve(pp.size());
@@ -338,21 +366,22 @@ EXTERN_DLL_EXPORT CPathsD RectClipD(const RectD rect,
338366
return CreateCPathsD(result, 1/scale);
339367
}
340368

341-
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const Rect64 rect,
369+
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
342370
const CPaths64 paths)
343371
{
344-
if (rect.IsEmpty() || !paths) return nullptr;
345-
class RectClipLines rcl (rect);
372+
if (CRectIsEmpty(rect) || !paths) return nullptr;
373+
Rect64 r = CRectToRect(rect);
374+
class RectClipLines rcl (r);
346375
Paths64 pp = ConvertCPaths64(paths);
347376
Paths64 result;
348377
result.reserve(pp.size());
349378

350379
for (const Path64& p : pp)
351380
{
352381
Rect64 pathRec = Bounds(p);
353-
if (!rect.Intersects(pathRec)) continue;
382+
if (!r.Intersects(pathRec)) continue;
354383

355-
if (rect.Contains(pathRec))
384+
if (r.Contains(pathRec))
356385
result.push_back(p);
357386
else
358387
{
@@ -364,14 +393,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const Rect64 rect,
364393
return CreateCPaths64(result);
365394
}
366395

367-
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const RectD rect,
396+
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
368397
const CPathsD paths, int precision = 2)
369398
{
370399
Paths64 result;
371-
if (rect.IsEmpty() || !paths) return nullptr;
400+
if (CRectIsEmpty(rect) || !paths) return nullptr;
372401
if (precision < -8 || precision > 8) return nullptr;
373402
const double scale = std::pow(10, precision);
374-
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
403+
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
375404
class RectClipLines rcl(r);
376405
Paths64 pp = ConvertCPathsD(paths, scale);
377406

@@ -692,7 +721,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale)
692721
result->polygon = nullptr;
693722
result->is_hole = false;
694723
size_t child_cnt = pt.Count();
695-
result->child_count = child_cnt;
724+
result->child_count = static_cast<uint32_t>(child_cnt);
696725
result->childs = nullptr;
697726
if (!child_cnt) return result;
698727
result->childs = new CPolyPathD[child_cnt];

0 commit comments

Comments
 (0)