Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ categories = ["algorithms", "external-ffi-bindings"]
generate-bindings = ["bindgen"]
update-bindings = ["generate-bindings"]
serde = ["dep:serde"]
usingz = []

[dependencies]
libc = "0.2"
Expand Down
369 changes: 197 additions & 172 deletions build.rs

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion clipper2c/include/clipper2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ int clipper_clipper64_get_preserve_collinear(ClipperClipper64 *c);
int clipper_clipper64_get_reverse_solution(ClipperClipper64 *c);
void clipper_clipper64_clear(ClipperClipper64 *c);

#ifdef USINGZ
void clipper_clipper64_set_z_callback(ClipperClipper64 *c, void* user_data, ClipperZCallback64 cb);
#endif

// ClipperD Setters / Getters
//
void clipper_clipperd_set_preserve_collinear(ClipperClipperD *c, int t);
Expand All @@ -372,6 +376,10 @@ int clipper_clipperd_get_preserve_collinear(ClipperClipperD *c);
int clipper_clipperd_get_reverse_solution(ClipperClipperD *c);
void clipper_clipperd_clear(ClipperClipperD *c);

#ifdef USINGZ
void clipper_clipperd_set_z_callback(ClipperClipperD *c, void* user_data, ClipperZCallbackD cb);
#endif

// Clipper64 Methods

void clipper_clipper64_add_subject(ClipperClipper64 *c,
Expand Down Expand Up @@ -527,4 +535,4 @@ void clipper_delete_svgreader(ClipperSvgReader *p);

#ifdef __cplusplus
}
#endif
#endif
28 changes: 27 additions & 1 deletion clipper2c/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,40 @@ extern "C"
{
double x;
double y;
#ifdef USINGZ
int64_t z;
#endif
} ClipperPointD;

typedef struct ClipperPoint64
{
int64_t x;
int64_t y;
#ifdef USINGZ
int64_t z;
#endif
} ClipperPoint64;

#ifdef USINGZ
typedef void (*ClipperZCallback64)(
void* user_data,
const ClipperPoint64* e1bot,
const ClipperPoint64* e1top,
const ClipperPoint64* e2bot,
const ClipperPoint64* e2top,
ClipperPoint64* pt
);

typedef void (*ClipperZCallbackD)(
void* user_data,
const ClipperPointD* e1bot,
const ClipperPointD* e1top,
const ClipperPointD* e2bot,
const ClipperPointD* e2top,
ClipperPointD* pt
);
#endif

struct ClipperRect64
{
int64_t left;
Expand Down Expand Up @@ -102,4 +128,4 @@ extern "C"
}
#endif

#endif
#endif
34 changes: 29 additions & 5 deletions clipper2c/src/clipper2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,13 @@ extern "C"
ClipperPoint64 *pts = reinterpret_cast<ClipperPoint64 *>(mem);
for (size_t i = 0; i < len; ++i)
{
pts[i] = {p[i].x, p[i].y};
pts[i] = {
p[i].x,
p[i].y,
#ifdef USINGZ
p[i].z
#endif
};
}
return pts;
}
Expand All @@ -415,7 +421,13 @@ extern "C"
ClipperPointD *pts = reinterpret_cast<ClipperPointD *>(mem);
for (size_t i = 0; i < len; ++i)
{
pts[i] = {p[i].x, p[i].y};
pts[i] = {
p[i].x,
p[i].y,
#ifdef USINGZ
p[i].z
#endif
};
}
return pts;
}
Expand Down Expand Up @@ -500,7 +512,13 @@ extern "C"
auto len = ps[i].size();
for (size_t j = 0; j < len; ++j)
{
pts[i][j] = {ps[i][j].x, ps[i][j].y};
pts[i][j] = {
ps[i][j].x,
ps[i][j].y,
#ifdef USINGZ
ps[i][j].z
#endif
};
}
}
return pts;
Expand All @@ -516,7 +534,13 @@ extern "C"
auto len = ps[i].size();
for (size_t j = 0; j < len; ++j)
{
pts[i][j] = {ps[i][j].x, ps[i][j].y};
pts[i][j] = {
ps[i][j].x,
ps[i][j].y,
#ifdef USINGZ
ps[i][j].z
#endif
};
}
}
return pts;
Expand Down Expand Up @@ -1020,4 +1044,4 @@ extern "C"

#ifdef __cplusplus
}
#endif
#endif
17 changes: 16 additions & 1 deletion clipper2c/src/clipper64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ int clipper_clipper64_get_reverse_solution(ClipperClipper64 *c) {

void clipper_clipper64_clear(ClipperClipper64 *c) { from_c(c)->Clear(); }

#ifdef USINGZ
void clipper_clipper64_set_z_callback(ClipperClipper64 *c, void* user_data, ClipperZCallback64 cb) {
from_c(c)->SetZCallback([cb, user_data](const Point64 &p1, const Point64 &p2,
const Point64 &p3, const Point64 &p4,
Point64 &p5) {
cb(user_data,
reinterpret_cast<const ClipperPoint64 *>(&p1),
reinterpret_cast<const ClipperPoint64 *>(&p2),
reinterpret_cast<const ClipperPoint64 *>(&p3),
reinterpret_cast<const ClipperPoint64 *>(&p4),
reinterpret_cast<ClipperPoint64 *>(&p5));
});
}
#endif

// Methods

void clipper_clipper64_add_subject(ClipperClipper64 *c,
Expand Down Expand Up @@ -77,4 +92,4 @@ int clipper_clipper64_execute_tree_with_open(ClipperClipper64 *c64,

#ifdef __cplusplus
}
#endif
#endif
17 changes: 16 additions & 1 deletion clipper2c/src/clipperd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ int clipper_clipperd_get_reverse_solution(ClipperClipperD *c) {

void clipper_clipperd_clear(ClipperClipperD *c) { from_c(c)->Clear(); }

#ifdef USINGZ
void clipper_clipperd_set_z_callback(ClipperClipperD *c, void* user_data, ClipperZCallbackD cb) {
from_c(c)->SetZCallback([cb, user_data](const PointD &p1, const PointD &p2,
const PointD &p3, const PointD &p4,
PointD &p5) {
cb(user_data,
reinterpret_cast<const ClipperPointD *>(&p1),
reinterpret_cast<const ClipperPointD *>(&p2),
reinterpret_cast<const ClipperPointD *>(&p3),
reinterpret_cast<const ClipperPointD *>(&p4),
reinterpret_cast<ClipperPointD *>(&p5));
});
}
#endif

// Methods

void clipper_clipperd_add_subject(ClipperClipperD *c, ClipperPathsD *subjects) {
Expand Down Expand Up @@ -75,4 +90,4 @@ int clipper_clipperd_execute_tree_with_open(ClipperClipperD *cD,

#ifdef __cplusplus
}
#endif
#endif
22 changes: 19 additions & 3 deletions clipper2c/src/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@
#include "clipper2/clipper.core.h"
#include "types.h"

ClipperPoint64 to_c(Clipper2Lib::Point64 p) { return {p.x, p.y}; }
ClipperPoint64 to_c(Clipper2Lib::Point64 p) {
return {
p.x,
p.y,
#ifdef USINGZ
p.z
#endif
};
}

ClipperPointD to_c(Clipper2Lib::PointD p) { return {p.x, p.y}; }
ClipperPointD to_c(Clipper2Lib::PointD p) {
return {
p.x,
p.y,
#ifdef USINGZ
p.z
#endif
};
}

ClipperPath64 *to_c(Clipper2Lib::Path64 *p)
{
Expand Down Expand Up @@ -351,4 +367,4 @@ Clipper2Lib::PointInPolygonResult from_c(ClipperPointInPolygonResult result)
break;
};
return res;
}
}
Loading