Skip to content

Commit

Permalink
version 1.0.6
Browse files Browse the repository at this point in the history
Additional clipper.export.h bugfixes
Additional bugfixes in DLL sample app
Minor tweaks to clipper.engine (C++)
  • Loading branch information
AngusJohnson committed Oct 28, 2022
1 parent 09d6cc4 commit e960879
Show file tree
Hide file tree
Showing 5 changed files with 452 additions and 143 deletions.
23 changes: 11 additions & 12 deletions CPP/Clipper2Lib/include/clipper2/clipper.engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef CLIPPER_ENGINE_H
#define CLIPPER_ENGINE_H

#define CLIPPER2_VERSION "1.0.5"
#define CLIPPER2_VERSION "1.0.6"

#include <cstdlib>
#include <queue>
Expand Down Expand Up @@ -159,7 +159,6 @@ namespace Clipper2Lib {
FillRule fillrule_ = FillRule::EvenOdd;
FillRule fillpos = FillRule::Positive;
int64_t bot_y_ = 0;
bool has_open_paths_ = false;
bool minima_list_sorted_ = false;
bool using_polytree_ = false;
Active* actives_ = nullptr;
Expand All @@ -170,7 +169,6 @@ namespace Clipper2Lib {
std::vector<Vertex*> vertex_lists_;
std::priority_queue<int64_t> scanline_list_;
std::vector<IntersectNode> intersect_nodes_;
std::vector<OutRec*> outrec_list_; //pointers in case of memory reallocs
std::vector<Joiner*> joiner_list_; //pointers in case of memory reallocs
void Reset();
void InsertScanline(int64_t y);
Expand Down Expand Up @@ -224,13 +222,12 @@ namespace Clipper2Lib {
void DeleteJoin(Joiner* joiner);
void ProcessJoinerList();
OutRec* ProcessJoin(Joiner* joiner);
bool DeepCheckOwner(OutRec* outrec, OutRec* owner);
protected:
bool has_open_paths_ = false;
bool succeeded_ = true;
std::vector<OutRec*> outrec_list_; //pointers in case list memory reallocated
bool ExecuteInternal(ClipType ct, FillRule ft, bool use_polytrees);
void BuildPaths(Paths64& solutionClosed, Paths64* solutionOpen);
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
bool DeepCheckOwner(OutRec* outrec, OutRec* owner);
#ifdef USINGZ
ZCallback64 zCallback_ = nullptr;
void SetZ(const Active& e1, const Active& e2, Point64& pt);
Expand Down Expand Up @@ -412,6 +409,9 @@ namespace Clipper2Lib {

class Clipper64 : public ClipperBase
{
private:
void BuildPaths64(Paths64& solutionClosed, Paths64* solutionOpen);
void BuildTree64(PolyPath64& polytree, Paths64& open_paths);
public:
#ifdef USINGZ
void SetZCallback(ZCallback64 cb) { zCallback_ = cb; }
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace Clipper2Lib {
closed_paths.clear();
open_paths.clear();
if (ExecuteInternal(clip_type, fill_rule, false))
BuildPaths(closed_paths, &open_paths);
BuildPaths64(closed_paths, &open_paths);
CleanUp();
return succeeded_;
}
Expand Down Expand Up @@ -474,6 +474,8 @@ namespace Clipper2Lib {
#ifdef USINGZ
ZCallbackD zCallback_ = nullptr;
#endif
void BuildPathsD(PathsD& solutionClosed, PathsD* solutionOpen);
void BuildTreeD(PolyPathD& polytree, PathsD& open_paths);
public:
explicit ClipperD(int precision = 2) : ClipperBase()
{
Expand Down Expand Up @@ -544,10 +546,7 @@ namespace Clipper2Lib {
#endif
if (ExecuteInternal(clip_type, fill_rule, false))
{
Paths64 sol, solo;
BuildPaths(sol, &solo);
closed_paths = ScalePaths<double, int64_t>(sol, invScale_);
open_paths = ScalePaths<double, int64_t>(solo, invScale_);
BuildPathsD(closed_paths, &open_paths);
}
CleanUp();
return succeeded_;
Expand Down
75 changes: 52 additions & 23 deletions CPP/Clipper2Lib/include/clipper2/clipper.export.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ typedef int64_t** CPaths64;
typedef double* CPathD;
typedef double** CPathsD;

typedef struct CRect64 { int64_t val[4]; } CRect64;
typedef struct CRectD { double val[4]; } CRectD;

typedef struct CPolyPath64 {
CPath64 polygon;
uint32_t is_hole;
Expand All @@ -76,6 +73,34 @@ typedef struct CPolyPathD {
}
CPolyTreeD;

template <typename T>
struct CRect {
T left;
T top;
T right;
T bottom;
};

typedef CRect<int64_t> CRect64;
typedef CRect<double> CRectD;

template <typename T>
inline bool CRectIsEmpty(const CRect<T>& rect)
{
return (rect.right <= rect.left) || (rect.bottom <= rect.top);
}

template <typename T>
inline Rect<T> CRectToRect(const CRect<T>& rect)
{
Rect<T> result;
result.left = rect.left;
result.top = rect.top;
result.right = rect.right;
result.bottom = rect.bottom;
return result;
}

inline CPath64 CreateCPath64(size_t cnt1, size_t cnt2);
inline CPath64 CreateCPath64(const Path64& p);
inline CPaths64 CreateCPaths64(const Paths64& pp);
Expand All @@ -99,6 +124,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale);

#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)


EXTERN_DLL_EXPORT const char* Version()
{
return CLIPPER2_VERSION;
Expand Down Expand Up @@ -258,7 +284,7 @@ EXTERN_DLL_EXPORT int BooleanOpPtD(uint8_t cliptype,
return 0;
}

EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
double delta, uint8_t jt, uint8_t et, double miter_limit = 2.0,
double arc_tolerance = 0.0, bool reverse_solution = false)
{
Expand All @@ -272,7 +298,7 @@ EXTERN_DLL_EXPORT CPaths64 InflatePaths64(const CPaths64 paths,
return CreateCPaths64(result);
}

EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
double delta, uint8_t jt, uint8_t et,
double precision = 2, double miter_limit = 2.0,
double arc_tolerance = 0.0, bool reverse_solution = false)
Expand All @@ -286,20 +312,23 @@ EXTERN_DLL_EXPORT CPathsD InflatePathsD(const CPathsD paths,
return CreateCPathsD(result, 1/scale);
}

EXTERN_DLL_EXPORT CPaths64 RectClip64(const Rect64 rect,
EXTERN_DLL_EXPORT CPaths64 RectClip64(const CRect64& rect,
const CPaths64 paths)
{
if (rect.IsEmpty() || !paths) return nullptr;
class RectClip rc(rect);
log(rect.left);
log(rect.right);
if (CRectIsEmpty(rect) || !paths) return nullptr;
Rect64 r64 = CRectToRect(rect);
class RectClip rc(r64);
Paths64 pp = ConvertCPaths64(paths);
Paths64 result;
result.reserve(pp.size());
for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!rect.Intersects(pathRec)) continue;
if (!r64.Intersects(pathRec)) continue;

if (rect.Contains(pathRec))
if (r64.Contains(pathRec))
result.push_back(p);
else
{
Expand All @@ -310,15 +339,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClip64(const Rect64 rect,
return CreateCPaths64(result);
}

EXTERN_DLL_EXPORT CPathsD RectClipD(const RectD rect,
EXTERN_DLL_EXPORT CPathsD RectClipD(const CRectD& rect,
const CPathsD paths, int precision = 2)
{
if (rect.IsEmpty() || !paths) return nullptr;
if (CRectIsEmpty(rect) || !paths) return nullptr;
if (precision < -8 || precision > 8) return nullptr;
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
Paths64 pp = ConvertCPathsD(paths, scale);

class RectClip rc(r);
Paths64 result;
result.reserve(pp.size());
Expand All @@ -338,21 +366,22 @@ EXTERN_DLL_EXPORT CPathsD RectClipD(const RectD rect,
return CreateCPathsD(result, 1/scale);
}

EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const Rect64 rect,
EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const CRect64& rect,
const CPaths64 paths)
{
if (rect.IsEmpty() || !paths) return nullptr;
class RectClipLines rcl (rect);
if (CRectIsEmpty(rect) || !paths) return nullptr;
Rect64 r = CRectToRect(rect);
class RectClipLines rcl (r);
Paths64 pp = ConvertCPaths64(paths);
Paths64 result;
result.reserve(pp.size());

for (const Path64& p : pp)
{
Rect64 pathRec = Bounds(p);
if (!rect.Intersects(pathRec)) continue;
if (!r.Intersects(pathRec)) continue;

if (rect.Contains(pathRec))
if (r.Contains(pathRec))
result.push_back(p);
else
{
Expand All @@ -364,14 +393,14 @@ EXTERN_DLL_EXPORT CPaths64 RectClipLines64(const Rect64 rect,
return CreateCPaths64(result);
}

EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const RectD rect,
EXTERN_DLL_EXPORT CPathsD RectClipLinesD(const CRectD& rect,
const CPathsD paths, int precision = 2)
{
Paths64 result;
if (rect.IsEmpty() || !paths) return nullptr;
if (CRectIsEmpty(rect) || !paths) return nullptr;
if (precision < -8 || precision > 8) return nullptr;
const double scale = std::pow(10, precision);
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
Rect64 r = ScaleRect<int64_t, double>(CRectToRect(rect), scale);
class RectClipLines rcl(r);
Paths64 pp = ConvertCPathsD(paths, scale);

Expand Down Expand Up @@ -692,7 +721,7 @@ inline CPolyTreeD* CreateCPolyTreeD(const PolyTree64& pt, double scale)
result->polygon = nullptr;
result->is_hole = false;
size_t child_cnt = pt.Count();
result->child_count = child_cnt;
result->child_count = static_cast<uint32_t>(child_cnt);
result->childs = nullptr;
if (!child_cnt) return result;
result->childs = new CPolyPathD[child_cnt];
Expand Down
Loading

3 comments on commit e960879

@sergey-239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angus
do marked this as version 1.0.6 in the commit message, but did not created a release. Is this intentional?
Thank you,
Sergey

@AngusJohnson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angus do marked this as version 1.0.6 in the commit message, but did not created a release. Is this intentional? Thank you, Sergey

Hi Sergey. I was just a bit slow in doing so. 😁

@sergey-239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, later I got that I noted your commit minutes after it was done, sorry for disturb you ;)

Please sign in to comment.