diff --git a/Cargo.toml b/Cargo.toml index 9412574..fd83768 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ categories = ["algorithms", "external-ffi-bindings"] generate-bindings = ["bindgen"] update-bindings = ["generate-bindings"] serde = ["dep:serde"] +usingz = [] [dependencies] libc = "0.2" diff --git a/build.rs b/build.rs index 1734070..8ca54f8 100644 --- a/build.rs +++ b/build.rs @@ -1,12 +1,29 @@ use std::env; fn main() { + build(cfg!(feature = "usingz")); + + #[cfg(feature = "generate-bindings")] + { + generate_bindings("bindings", false); + generate_bindings("bindings_usingz", true); + } +} + +fn build(usingz: bool) { println!("cargo:rerun-if-changed=clipper2c"); if cfg!(feature = "update-bindings") { println!("cargo:rerun-if-changed=generated"); } - cc::Build::new() + #[allow(unused_mut)] + let mut build = &mut cc::Build::new(); + + if usingz { + build = build.define("USINGZ", None); + } + + build .cpp(true) .opt_level(3) .include("clipper2c/vendor/Clipper2/CPP/Clipper2Lib/include/") @@ -46,180 +63,188 @@ fn main() { target_env.as_str() ), } +} + +#[cfg(feature = "generate-bindings")] +fn generate_bindings(bindings_name: &str, usingz: bool) { + let mut builder = bindgen::Builder::default(); + + if usingz { + builder = builder.clang_arg("-DUSINGZ"); + } - #[cfg(feature = "generate-bindings")] - { - let builder = bindgen::Builder::default() - .header("clipper2c/include/clipper2c.h") - .header("clipper2c/include/types.h") - .derive_default(true) - .derive_partialeq(true) - .derive_eq(true) - .derive_hash(true) - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) - .allowlist_type("ClipperClipperD") - .allowlist_type("ClipperPathD") - .allowlist_type("ClipperPathsD") - .allowlist_type("ClipperPolyTreeD") - .allowlist_type("ClipperPointD") - .allowlist_type("ClipperClipper64") - .allowlist_type("ClipperPath64") - .allowlist_type("ClipperPaths64") - .allowlist_type("ClipperPolyTree64") - .allowlist_type("ClipperPoint64") - .allowlist_type("ClipperFillRule") - .allowlist_type("ClipperClipType") - .allowlist_type("ClipperPathType") - .allowlist_type("ClipperPointInPolygonResult") - // PathD Methods - .allowlist_function("clipper_pathd_size") - .allowlist_function("clipper_pathd") - .allowlist_function("clipper_pathd_of_points") - .allowlist_function("clipper_pathd_add_point") - .allowlist_function("clipper_pathd_length") - .allowlist_function("clipper_pathd_get_point") - .allowlist_function("clipper_delete_pathd") - .allowlist_function("clipper_pathd_simplify") - .allowlist_function("clipper_pathd_to_path64") - .allowlist_function("clipper_point_in_pathd") - .allowlist_function("clipper_pathd_area") - // PathsD Methods - .allowlist_function("clipper_pathsd_size") - .allowlist_function("clipper_pathsd") - .allowlist_function("clipper_pathsd_of_paths") - .allowlist_function("clipper_pathsd_add_path") - .allowlist_function("clipper_pathsd_add_paths") - .allowlist_function("clipper_pathsd_get_path") - .allowlist_function("clipper_pathsd_get_point") - .allowlist_function("clipper_pathsd_length") - .allowlist_function("clipper_pathsd_path_length") - .allowlist_function("clipper_delete_pathsd") - .allowlist_function("clipper_pathsd_simplify") - .allowlist_function("clipper_pathsd_inflate") - .allowlist_function("clipper_pathsd_to_paths64") - .allowlist_function("clipper_pathsd_area") - // ClipperD Methods - .allowlist_function("clipper_clipperd_size") - .allowlist_function("clipper_clipperd") - .allowlist_function("clipper_clipperd_add_subject") - .allowlist_function("clipper_clipperd_add_open_subject") - .allowlist_function("clipper_clipperd_add_clip") - .allowlist_function("clipper_clipperd_execute") - .allowlist_function("clipper_clipperd_execute_tree_with_open") - .allowlist_function("clipper_clipperd_set_preserve_collinear") - .allowlist_function("clipper_clipperd_get_preserve_collinear") - .allowlist_function("clipper_clipperd_set_reverse_solution") - .allowlist_function("clipper_clipperd_get_reverse_solution") - .allowlist_function("clipper_clipperd_clear") - .allowlist_function("clipper_delete_clipperd") - // PolyTreeD Methods - .allowlist_function("clipper_polytreed_size") - .allowlist_function("clipper_polytreed") - .allowlist_function("clipper_polytreed_parent") - .allowlist_function("clipper_polytreed_count") - .allowlist_function("clipper_polytreed_get_child") - .allowlist_function("clipper_polytreed_set_inv_scale") - .allowlist_function("clipper_polytreed_inv_scale") - .allowlist_function("clipper_polytreed_add_child") - .allowlist_function("clipper_polytreed_is_hole") - .allowlist_function("clipper_polytreed_polygon") - .allowlist_function("clipper_polytreed_area") - .allowlist_function("clipper_polytreed_to_paths") - .allowlist_function("clipper_delete_polytreed") - // Path64 Methods - .allowlist_function("clipper_path64_size") - .allowlist_function("clipper_path64") - .allowlist_function("clipper_path64_of_points") - .allowlist_function("clipper_path64_add_point") - .allowlist_function("clipper_path64_length") - .allowlist_function("clipper_path64_get_point") - .allowlist_function("clipper_delete_path64") - .allowlist_function("clipper_path64_simplify") - .allowlist_function("clipper_path64_to_pathd") - .allowlist_function("clipper_point_in_path64") - .allowlist_function("clipper_path64_area") - // Paths64 Methods - .allowlist_function("clipper_paths64_size") - .allowlist_function("clipper_paths64") - .allowlist_function("clipper_paths64_of_paths") - .allowlist_function("clipper_paths64_add_path") - .allowlist_function("clipper_paths64_add_paths") - .allowlist_function("clipper_paths64_get_path") - .allowlist_function("clipper_paths64_get_point") - .allowlist_function("clipper_paths64_length") - .allowlist_function("clipper_paths64_path_length") - .allowlist_function("clipper_delete_paths64") - .allowlist_function("clipper_paths64_simplify") - .allowlist_function("clipper_paths64_inflate") - .allowlist_function("clipper_paths64_to_pathsd") - .allowlist_function("clipper_paths64_area") - // ClipperD Methods - .allowlist_function("clipper_clipper64_size") - .allowlist_function("clipper_clipper64") - .allowlist_function("clipper_clipper64_add_subject") - .allowlist_function("clipper_clipper64_add_open_subject") - .allowlist_function("clipper_clipper64_add_clip") - .allowlist_function("clipper_clipper64_execute") - .allowlist_function("clipper_clipper64_execute_tree_with_open") - .allowlist_function("clipper_clipper64_set_preserve_collinear") - .allowlist_function("clipper_clipper64_get_preserve_collinear") - .allowlist_function("clipper_clipper64_set_reverse_solution") - .allowlist_function("clipper_clipper64_get_reverse_solution") - .allowlist_function("clipper_clipper64_clear") - .allowlist_function("clipper_delete_clipper64") - // PolyTreeD Methods - .allowlist_function("clipper_polytree64_size") - .allowlist_function("clipper_polytree64") - .allowlist_function("clipper_polytree64_parent") - .allowlist_function("clipper_polytree64_count") - .allowlist_function("clipper_polytree64_get_child") - .allowlist_function("clipper_polytree64_set_inv_scale") - .allowlist_function("clipper_polytree64_inv_scale") - .allowlist_function("clipper_polytree64_add_child") - .allowlist_function("clipper_polytree64_is_hole") - .allowlist_function("clipper_polytree64_polygon") - .allowlist_function("clipper_polytree64_area") - .allowlist_function("clipper_polytree64_to_paths") - .allowlist_function("clipper_delete_polytree64") - // ClipperOffset Methods - .allowlist_function("clipper_clipperoffset_size") - .allowlist_function("clipper_clipperoffset") - .allowlist_function("clipper_clipperoffset_set_miter_limit") - .allowlist_function("clipper_clipperoffset_set_arc_tolerance") - .allowlist_function("clipper_clipperoffset_set_preserve_collinear") - .allowlist_function("clipper_clipperoffset_set_reverse_solution") - .allowlist_function("clipper_clipperoffset_get_miter_limit") - .allowlist_function("clipper_clipperoffset_get_arc_tolerance") - .allowlist_function("clipper_clipperoffset_get_preserve_collinear") - .allowlist_function("clipper_clipperoffset_get_reverse_solution") - .allowlist_function("clipper_clipperoffset_error_code") - .allowlist_function("clipper_clipperoffset_clear") - .allowlist_function("clipper_clipperoffset_add_path64") - .allowlist_function("clipper_clipperoffset_add_paths64") - .allowlist_function("clipper_clipperoffset_execute") - .allowlist_function("clipper_delete_clipperoffset") - .size_t_is_usize(true); - - let bindings = builder.generate().expect("unable to generate bindings"); - - let out_path = if cfg!(feature = "update-bindings") { - std::path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("generated") - } else { - std::path::PathBuf::from(env::var("OUT_DIR").unwrap()) - }; - let out_bindings = out_path.join("bindings.rs"); - - bindings - .write_to_file(&out_bindings) - .expect("couldn't write bindings!"); - - let content = std::fs::read_to_string(&out_bindings).expect("couldn't read bindings file"); - let processed_content = content.replace( + builder = builder + .header("clipper2c/include/clipper2c.h") + .header("clipper2c/include/types.h") + .derive_default(true) + .derive_partialeq(true) + .derive_eq(true) + .derive_hash(true) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .allowlist_type("ClipperClipperD") + .allowlist_type("ClipperPathD") + .allowlist_type("ClipperPathsD") + .allowlist_type("ClipperPolyTreeD") + .allowlist_type("ClipperPointD") + .allowlist_type("ClipperClipper64") + .allowlist_type("ClipperPath64") + .allowlist_type("ClipperPaths64") + .allowlist_type("ClipperPolyTree64") + .allowlist_type("ClipperPoint64") + .allowlist_type("ClipperFillRule") + .allowlist_type("ClipperClipType") + .allowlist_type("ClipperPathType") + .allowlist_type("ClipperPointInPolygonResult") + // PathD Methods + .allowlist_function("clipper_pathd_size") + .allowlist_function("clipper_pathd") + .allowlist_function("clipper_pathd_of_points") + .allowlist_function("clipper_pathd_add_point") + .allowlist_function("clipper_pathd_length") + .allowlist_function("clipper_pathd_get_point") + .allowlist_function("clipper_delete_pathd") + .allowlist_function("clipper_pathd_simplify") + .allowlist_function("clipper_pathd_to_path64") + .allowlist_function("clipper_point_in_pathd") + .allowlist_function("clipper_pathd_area") + // PathsD Methods + .allowlist_function("clipper_pathsd_size") + .allowlist_function("clipper_pathsd") + .allowlist_function("clipper_pathsd_of_paths") + .allowlist_function("clipper_pathsd_add_path") + .allowlist_function("clipper_pathsd_add_paths") + .allowlist_function("clipper_pathsd_get_path") + .allowlist_function("clipper_pathsd_get_point") + .allowlist_function("clipper_pathsd_length") + .allowlist_function("clipper_pathsd_path_length") + .allowlist_function("clipper_delete_pathsd") + .allowlist_function("clipper_pathsd_simplify") + .allowlist_function("clipper_pathsd_inflate") + .allowlist_function("clipper_pathsd_to_paths64") + .allowlist_function("clipper_pathsd_area") + // ClipperD Methods + .allowlist_function("clipper_clipperd_size") + .allowlist_function("clipper_clipperd") + .allowlist_function("clipper_clipperd_add_subject") + .allowlist_function("clipper_clipperd_add_open_subject") + .allowlist_function("clipper_clipperd_add_clip") + .allowlist_function("clipper_clipperd_execute") + .allowlist_function("clipper_clipperd_execute_tree_with_open") + .allowlist_function("clipper_clipperd_set_preserve_collinear") + .allowlist_function("clipper_clipperd_get_preserve_collinear") + .allowlist_function("clipper_clipperd_set_reverse_solution") + .allowlist_function("clipper_clipperd_get_reverse_solution") + .allowlist_function("clipper_clipperd_clear") + .allowlist_function("clipper_clipperd_set_z_callback") + .allowlist_function("clipper_delete_clipperd") + // PolyTreeD Methods + .allowlist_function("clipper_polytreed_size") + .allowlist_function("clipper_polytreed") + .allowlist_function("clipper_polytreed_parent") + .allowlist_function("clipper_polytreed_count") + .allowlist_function("clipper_polytreed_get_child") + .allowlist_function("clipper_polytreed_set_inv_scale") + .allowlist_function("clipper_polytreed_inv_scale") + .allowlist_function("clipper_polytreed_add_child") + .allowlist_function("clipper_polytreed_is_hole") + .allowlist_function("clipper_polytreed_polygon") + .allowlist_function("clipper_polytreed_area") + .allowlist_function("clipper_polytreed_to_paths") + .allowlist_function("clipper_delete_polytreed") + // Path64 Methods + .allowlist_function("clipper_path64_size") + .allowlist_function("clipper_path64") + .allowlist_function("clipper_path64_of_points") + .allowlist_function("clipper_path64_add_point") + .allowlist_function("clipper_path64_length") + .allowlist_function("clipper_path64_get_point") + .allowlist_function("clipper_delete_path64") + .allowlist_function("clipper_path64_simplify") + .allowlist_function("clipper_path64_to_pathd") + .allowlist_function("clipper_point_in_path64") + .allowlist_function("clipper_path64_area") + // Paths64 Methods + .allowlist_function("clipper_paths64_size") + .allowlist_function("clipper_paths64") + .allowlist_function("clipper_paths64_of_paths") + .allowlist_function("clipper_paths64_add_path") + .allowlist_function("clipper_paths64_add_paths") + .allowlist_function("clipper_paths64_get_path") + .allowlist_function("clipper_paths64_get_point") + .allowlist_function("clipper_paths64_length") + .allowlist_function("clipper_paths64_path_length") + .allowlist_function("clipper_delete_paths64") + .allowlist_function("clipper_paths64_simplify") + .allowlist_function("clipper_paths64_inflate") + .allowlist_function("clipper_paths64_to_pathsd") + .allowlist_function("clipper_paths64_area") + // Clipper64 Methods + .allowlist_function("clipper_clipper64_size") + .allowlist_function("clipper_clipper64") + .allowlist_function("clipper_clipper64_add_subject") + .allowlist_function("clipper_clipper64_add_open_subject") + .allowlist_function("clipper_clipper64_add_clip") + .allowlist_function("clipper_clipper64_execute") + .allowlist_function("clipper_clipper64_execute_tree_with_open") + .allowlist_function("clipper_clipper64_set_preserve_collinear") + .allowlist_function("clipper_clipper64_get_preserve_collinear") + .allowlist_function("clipper_clipper64_set_reverse_solution") + .allowlist_function("clipper_clipper64_get_reverse_solution") + .allowlist_function("clipper_clipper64_clear") + .allowlist_function("clipper_clipper64_set_z_callback") + .allowlist_function("clipper_delete_clipper64") + // PolyTreeD Methods + .allowlist_function("clipper_polytree64_size") + .allowlist_function("clipper_polytree64") + .allowlist_function("clipper_polytree64_parent") + .allowlist_function("clipper_polytree64_count") + .allowlist_function("clipper_polytree64_get_child") + .allowlist_function("clipper_polytree64_set_inv_scale") + .allowlist_function("clipper_polytree64_inv_scale") + .allowlist_function("clipper_polytree64_add_child") + .allowlist_function("clipper_polytree64_is_hole") + .allowlist_function("clipper_polytree64_polygon") + .allowlist_function("clipper_polytree64_area") + .allowlist_function("clipper_polytree64_to_paths") + .allowlist_function("clipper_delete_polytree64") + // ClipperOffset Methods + .allowlist_function("clipper_clipperoffset_size") + .allowlist_function("clipper_clipperoffset") + .allowlist_function("clipper_clipperoffset_set_miter_limit") + .allowlist_function("clipper_clipperoffset_set_arc_tolerance") + .allowlist_function("clipper_clipperoffset_set_preserve_collinear") + .allowlist_function("clipper_clipperoffset_set_reverse_solution") + .allowlist_function("clipper_clipperoffset_get_miter_limit") + .allowlist_function("clipper_clipperoffset_get_arc_tolerance") + .allowlist_function("clipper_clipperoffset_get_preserve_collinear") + .allowlist_function("clipper_clipperoffset_get_reverse_solution") + .allowlist_function("clipper_clipperoffset_error_code") + .allowlist_function("clipper_clipperoffset_clear") + .allowlist_function("clipper_clipperoffset_add_path64") + .allowlist_function("clipper_clipperoffset_add_paths64") + .allowlist_function("clipper_clipperoffset_execute") + .allowlist_function("clipper_delete_clipperoffset") + .size_t_is_usize(true); + + let bindings = builder.generate().expect("unable to generate bindings"); + + let out_path = if cfg!(feature = "update-bindings") { + std::path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("generated") + } else { + std::path::PathBuf::from(env::var("OUT_DIR").unwrap()) + }; + let out_bindings = out_path.join(bindings_name.to_string() + ".rs"); + + bindings + .write_to_file(&out_bindings) + .expect("couldn't write bindings!"); + + let content = std::fs::read_to_string(&out_bindings).expect("couldn't read bindings file"); + let processed_content = content.replace( "pub struct ClipperPoint64 {", "#[cfg_attr(\n\tfeature = \"serde\",\n\tderive(serde::Serialize, serde::Deserialize)\n)]\npub struct ClipperPoint64 {", ); - std::fs::write(&out_bindings, processed_content) - .expect("couldn't write processed bindings file"); - } + std::fs::write(&out_bindings, processed_content) + .expect("couldn't write processed bindings file"); } diff --git a/clipper2c/include/clipper2c.h b/clipper2c/include/clipper2c.h index 97a7237..0e44a8a 100644 --- a/clipper2c/include/clipper2c.h +++ b/clipper2c/include/clipper2c.h @@ -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); @@ -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, @@ -527,4 +535,4 @@ void clipper_delete_svgreader(ClipperSvgReader *p); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/clipper2c/include/types.h b/clipper2c/include/types.h index b97926c..c2a3446 100644 --- a/clipper2c/include/types.h +++ b/clipper2c/include/types.h @@ -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; @@ -102,4 +128,4 @@ extern "C" } #endif -#endif \ No newline at end of file +#endif diff --git a/clipper2c/src/clipper2c.cpp b/clipper2c/src/clipper2c.cpp index cd91aab..26ffa90 100644 --- a/clipper2c/src/clipper2c.cpp +++ b/clipper2c/src/clipper2c.cpp @@ -403,7 +403,13 @@ extern "C" ClipperPoint64 *pts = reinterpret_cast(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; } @@ -415,7 +421,13 @@ extern "C" ClipperPointD *pts = reinterpret_cast(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; } @@ -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; @@ -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; @@ -1020,4 +1044,4 @@ extern "C" #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/clipper2c/src/clipper64.cpp b/clipper2c/src/clipper64.cpp index b4d3fa7..9c714c1 100644 --- a/clipper2c/src/clipper64.cpp +++ b/clipper2c/src/clipper64.cpp @@ -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(&p1), + reinterpret_cast(&p2), + reinterpret_cast(&p3), + reinterpret_cast(&p4), + reinterpret_cast(&p5)); + }); +} +#endif + // Methods void clipper_clipper64_add_subject(ClipperClipper64 *c, @@ -77,4 +92,4 @@ int clipper_clipper64_execute_tree_with_open(ClipperClipper64 *c64, #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/clipper2c/src/clipperd.cpp b/clipper2c/src/clipperd.cpp index 39d44de..24c512a 100644 --- a/clipper2c/src/clipperd.cpp +++ b/clipper2c/src/clipperd.cpp @@ -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(&p1), + reinterpret_cast(&p2), + reinterpret_cast(&p3), + reinterpret_cast(&p4), + reinterpret_cast(&p5)); + }); +} +#endif + // Methods void clipper_clipperd_add_subject(ClipperClipperD *c, ClipperPathsD *subjects) { @@ -75,4 +90,4 @@ int clipper_clipperd_execute_tree_with_open(ClipperClipperD *cD, #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/clipper2c/src/conv.cpp b/clipper2c/src/conv.cpp index 2ab9cc4..1fdf156 100644 --- a/clipper2c/src/conv.cpp +++ b/clipper2c/src/conv.cpp @@ -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) { @@ -351,4 +367,4 @@ Clipper2Lib::PointInPolygonResult from_c(ClipperPointInPolygonResult result) break; }; return res; -} \ No newline at end of file +} diff --git a/generated/bindings_usingz.rs b/generated/bindings_usingz.rs new file mode 100644 index 0000000..c12faf9 --- /dev/null +++ b/generated/bindings_usingz.rs @@ -0,0 +1,771 @@ +/* automatically generated by rust-bindgen 0.69.4 */ + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperClipper64 { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperClipperD { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperClipperOffset { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPath64 { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPathD { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPaths64 { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPathsD { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPolyTree64 { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClipperPolyTreeD { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] +pub struct ClipperPointD { + pub x: f64, + pub y: f64, + pub z: i64, +} +#[test] +fn bindgen_test_layout_ClipperPointD() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ClipperPointD)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClipperPointD)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClipperPointD), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ClipperPointD), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ClipperPointD), + "::", + stringify!(z) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize) +)] +pub struct ClipperPoint64 { + pub x: i64, + pub y: i64, + pub z: i64, +} +#[test] +fn bindgen_test_layout_ClipperPoint64() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ClipperPoint64)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClipperPoint64)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClipperPoint64), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ClipperPoint64), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ClipperPoint64), + "::", + stringify!(z) + ) + ); +} +pub type ClipperZCallback64 = ::std::option::Option< + unsafe extern "C" fn( + user_data: *mut ::std::os::raw::c_void, + e1bot: *const ClipperPoint64, + e1top: *const ClipperPoint64, + e2bot: *const ClipperPoint64, + e2top: *const ClipperPoint64, + pt: *mut ClipperPoint64, + ), +>; +pub type ClipperZCallbackD = ::std::option::Option< + unsafe extern "C" fn( + user_data: *mut ::std::os::raw::c_void, + e1bot: *const ClipperPointD, + e1top: *const ClipperPointD, + e2bot: *const ClipperPointD, + e2top: *const ClipperPointD, + pt: *mut ClipperPointD, + ), +>; +pub const ClipperFillRule_EVEN_ODD: ClipperFillRule = 0; +pub const ClipperFillRule_NON_ZERO: ClipperFillRule = 1; +pub const ClipperFillRule_POSITIVE: ClipperFillRule = 2; +pub const ClipperFillRule_NEGATIVE: ClipperFillRule = 3; +pub type ClipperFillRule = ::std::os::raw::c_uint; +pub const ClipperClipType_NONE: ClipperClipType = 0; +pub const ClipperClipType_INTERSECTION: ClipperClipType = 1; +pub const ClipperClipType_UNION: ClipperClipType = 2; +pub const ClipperClipType_DIFFERENCE: ClipperClipType = 3; +pub const ClipperClipType_XOR: ClipperClipType = 4; +pub type ClipperClipType = ::std::os::raw::c_uint; +pub const ClipperPathType_SUBJECT: ClipperPathType = 0; +pub const ClipperPathType_CLIP: ClipperPathType = 1; +pub type ClipperPathType = ::std::os::raw::c_uint; +pub const ClipperJoinType_SQUARE_JOIN: ClipperJoinType = 0; +pub const ClipperJoinType_BEVEL_JOIN: ClipperJoinType = 1; +pub const ClipperJoinType_ROUND_JOIN: ClipperJoinType = 2; +pub const ClipperJoinType_MITER_JOIN: ClipperJoinType = 3; +pub type ClipperJoinType = ::std::os::raw::c_uint; +pub const ClipperEndType_POLYGON_END: ClipperEndType = 0; +pub const ClipperEndType_JOINED_END: ClipperEndType = 1; +pub const ClipperEndType_BUTT_END: ClipperEndType = 2; +pub const ClipperEndType_SQUARE_END: ClipperEndType = 3; +pub const ClipperEndType_ROUND_END: ClipperEndType = 4; +pub type ClipperEndType = ::std::os::raw::c_uint; +pub const ClipperPointInPolygonResult_IS_ON: ClipperPointInPolygonResult = 0; +pub const ClipperPointInPolygonResult_IS_INSIDE: ClipperPointInPolygonResult = 1; +pub const ClipperPointInPolygonResult_IS_OUTSIDE: ClipperPointInPolygonResult = 2; +pub type ClipperPointInPolygonResult = ::std::os::raw::c_uint; +extern "C" { + pub fn clipper_paths64_inflate( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPaths64, + delta: f64, + jt: ClipperJoinType, + et: ClipperEndType, + miter_limit: f64, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_pathsd_inflate( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPathsD, + delta: f64, + jt: ClipperJoinType, + et: ClipperEndType, + miter_limit: f64, + precision: ::std::os::raw::c_int, + ) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_path64(mem: *mut ::std::os::raw::c_void) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_pathd(mem: *mut ::std::os::raw::c_void) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_path64_of_points( + mem: *mut ::std::os::raw::c_void, + pts: *mut ClipperPoint64, + len_pts: usize, + ) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_pathd_of_points( + mem: *mut ::std::os::raw::c_void, + pts: *mut ClipperPointD, + len_pts: usize, + ) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_path64_add_point(path: *mut ClipperPath64, pt: ClipperPoint64); +} +extern "C" { + pub fn clipper_pathd_add_point(path: *mut ClipperPathD, pt: ClipperPointD); +} +extern "C" { + pub fn clipper_paths64(mem: *mut ::std::os::raw::c_void) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_pathsd(mem: *mut ::std::os::raw::c_void) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_paths64_of_paths( + mem: *mut ::std::os::raw::c_void, + paths: *mut *mut ClipperPath64, + len_paths: usize, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_pathsd_of_paths( + mem: *mut ::std::os::raw::c_void, + paths: *mut *mut ClipperPathD, + len_paths: usize, + ) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_paths64_add_path(paths: *mut ClipperPaths64, p: *mut ClipperPath64); +} +extern "C" { + pub fn clipper_pathsd_add_path(paths: *mut ClipperPathsD, p: *mut ClipperPathD); +} +extern "C" { + pub fn clipper_paths64_add_paths(a: *mut ClipperPaths64, b: *mut ClipperPaths64); +} +extern "C" { + pub fn clipper_pathsd_add_paths(a: *mut ClipperPathsD, b: *mut ClipperPathsD); +} +extern "C" { + pub fn clipper_path64_length(path: *mut ClipperPath64) -> usize; +} +extern "C" { + pub fn clipper_pathd_length(path: *mut ClipperPathD) -> usize; +} +extern "C" { + pub fn clipper_path64_get_point( + path: *mut ClipperPath64, + idx: ::std::os::raw::c_int, + ) -> ClipperPoint64; +} +extern "C" { + pub fn clipper_pathd_get_point( + path: *mut ClipperPathD, + idx: ::std::os::raw::c_int, + ) -> ClipperPointD; +} +extern "C" { + pub fn clipper_paths64_length(paths: *mut ClipperPaths64) -> usize; +} +extern "C" { + pub fn clipper_pathsd_length(paths: *mut ClipperPathsD) -> usize; +} +extern "C" { + pub fn clipper_paths64_path_length( + paths: *mut ClipperPaths64, + idx: ::std::os::raw::c_int, + ) -> usize; +} +extern "C" { + pub fn clipper_pathsd_path_length( + paths: *mut ClipperPathsD, + idx: ::std::os::raw::c_int, + ) -> usize; +} +extern "C" { + pub fn clipper_paths64_get_path( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPaths64, + idx: ::std::os::raw::c_int, + ) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_pathsd_get_path( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPathsD, + idx: ::std::os::raw::c_int, + ) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_paths64_get_point( + paths: *mut ClipperPaths64, + path_idx: ::std::os::raw::c_int, + point_idx: ::std::os::raw::c_int, + ) -> ClipperPoint64; +} +extern "C" { + pub fn clipper_pathsd_get_point( + paths: *mut ClipperPathsD, + path_idx: ::std::os::raw::c_int, + point_idx: ::std::os::raw::c_int, + ) -> ClipperPointD; +} +extern "C" { + pub fn clipper_path64_simplify( + mem: *mut ::std::os::raw::c_void, + path: *mut ClipperPath64, + epsilon: f64, + is_open_path: ::std::os::raw::c_int, + ) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_pathd_simplify( + mem: *mut ::std::os::raw::c_void, + path: *mut ClipperPathD, + epsilon: f64, + is_open_path: ::std::os::raw::c_int, + ) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_paths64_simplify( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPaths64, + epsilon: f64, + is_open_paths: ::std::os::raw::c_int, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_pathsd_simplify( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPathsD, + epsilon: f64, + is_open_paths: ::std::os::raw::c_int, + ) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_path64_to_pathd( + mem: *mut ::std::os::raw::c_void, + path: *mut ClipperPath64, + ) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_pathd_to_path64( + mem: *mut ::std::os::raw::c_void, + path: *mut ClipperPathD, + ) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_paths64_to_pathsd( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPaths64, + ) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_pathsd_to_paths64( + mem: *mut ::std::os::raw::c_void, + paths: *mut ClipperPathsD, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_pathd_area(path: *mut ClipperPathD) -> f64; +} +extern "C" { + pub fn clipper_path64_area(path: *mut ClipperPath64) -> f64; +} +extern "C" { + pub fn clipper_pathsd_area(paths: *mut ClipperPathsD) -> f64; +} +extern "C" { + pub fn clipper_paths64_area(paths: *mut ClipperPaths64) -> f64; +} +extern "C" { + pub fn clipper_point_in_path64( + path: *mut ClipperPath64, + pt: ClipperPoint64, + ) -> ClipperPointInPolygonResult; +} +extern "C" { + pub fn clipper_point_in_pathd( + path: *mut ClipperPathD, + pt: ClipperPointD, + ) -> ClipperPointInPolygonResult; +} +extern "C" { + pub fn clipper_polytree64( + mem: *mut ::std::os::raw::c_void, + parent: *mut ClipperPolyTree64, + ) -> *mut ClipperPolyTree64; +} +extern "C" { + pub fn clipper_polytreed( + mem: *mut ::std::os::raw::c_void, + parent: *mut ClipperPolyTreeD, + ) -> *mut ClipperPolyTreeD; +} +extern "C" { + pub fn clipper_polytree64_parent(pt: *mut ClipperPolyTree64) -> *const ClipperPolyTree64; +} +extern "C" { + pub fn clipper_polytree64_get_child( + pt: *mut ClipperPolyTree64, + idx: usize, + ) -> *const ClipperPolyTree64; +} +extern "C" { + pub fn clipper_polytree64_add_child( + pt: *mut ClipperPolyTree64, + path: *mut ClipperPath64, + ) -> *mut ClipperPolyTree64; +} +extern "C" { + pub fn clipper_polytree64_count(pt: *mut ClipperPolyTree64) -> usize; +} +extern "C" { + pub fn clipper_polytree64_is_hole(pt: *mut ClipperPolyTree64) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_polytree64_polygon( + mem: *mut ::std::os::raw::c_void, + pt: *mut ClipperPolyTree64, + ) -> *mut ClipperPath64; +} +extern "C" { + pub fn clipper_polytree64_area(pt: *mut ClipperPolyTree64) -> f64; +} +extern "C" { + pub fn clipper_polytree64_to_paths( + mem: *mut ::std::os::raw::c_void, + pt: *mut ClipperPolyTree64, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_polytreed_parent(pt: *mut ClipperPolyTreeD) -> *const ClipperPolyTreeD; +} +extern "C" { + pub fn clipper_polytreed_get_child( + pt: *mut ClipperPolyTreeD, + idx: usize, + ) -> *const ClipperPolyTreeD; +} +extern "C" { + pub fn clipper_polytreed_set_inv_scale(pt: *mut ClipperPolyTreeD, value: f64); +} +extern "C" { + pub fn clipper_polytreed_inv_scale(pt: *mut ClipperPolyTreeD) -> f64; +} +extern "C" { + pub fn clipper_polytreed_add_child( + pt: *mut ClipperPolyTreeD, + path: *mut ClipperPath64, + ) -> *mut ClipperPolyTreeD; +} +extern "C" { + pub fn clipper_polytreed_count(pt: *mut ClipperPolyTreeD) -> usize; +} +extern "C" { + pub fn clipper_polytreed_is_hole(pt: *mut ClipperPolyTreeD) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_polytreed_polygon( + mem: *mut ::std::os::raw::c_void, + pt: *mut ClipperPolyTreeD, + ) -> *mut ClipperPathD; +} +extern "C" { + pub fn clipper_polytreed_area(pt: *mut ClipperPolyTreeD) -> f64; +} +extern "C" { + pub fn clipper_polytreed_to_paths( + mem: *mut ::std::os::raw::c_void, + pt: *mut ClipperPolyTreeD, + ) -> *mut ClipperPathsD; +} +extern "C" { + pub fn clipper_clipper64(mem: *mut ::std::os::raw::c_void) -> *mut ClipperClipper64; +} +extern "C" { + pub fn clipper_clipperd( + mem: *mut ::std::os::raw::c_void, + precision: ::std::os::raw::c_int, + ) -> *mut ClipperClipperD; +} +extern "C" { + pub fn clipper_clipper64_set_preserve_collinear( + c: *mut ClipperClipper64, + t: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn clipper_clipper64_set_reverse_solution( + c: *mut ClipperClipper64, + t: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn clipper_clipper64_get_preserve_collinear( + c: *mut ClipperClipper64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipper64_get_reverse_solution( + c: *mut ClipperClipper64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipper64_clear(c: *mut ClipperClipper64); +} +extern "C" { + pub fn clipper_clipper64_set_z_callback( + c: *mut ClipperClipper64, + user_data: *mut ::std::os::raw::c_void, + cb: ClipperZCallback64, + ); +} +extern "C" { + pub fn clipper_clipperd_set_preserve_collinear( + c: *mut ClipperClipperD, + t: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn clipper_clipperd_set_reverse_solution(c: *mut ClipperClipperD, t: ::std::os::raw::c_int); +} +extern "C" { + pub fn clipper_clipperd_get_preserve_collinear( + c: *mut ClipperClipperD, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperd_get_reverse_solution(c: *mut ClipperClipperD) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperd_clear(c: *mut ClipperClipperD); +} +extern "C" { + pub fn clipper_clipperd_set_z_callback( + c: *mut ClipperClipperD, + user_data: *mut ::std::os::raw::c_void, + cb: ClipperZCallbackD, + ); +} +extern "C" { + pub fn clipper_clipper64_add_subject(c: *mut ClipperClipper64, subjects: *mut ClipperPaths64); +} +extern "C" { + pub fn clipper_clipper64_add_open_subject( + c: *mut ClipperClipper64, + open_subjects: *mut ClipperPaths64, + ); +} +extern "C" { + pub fn clipper_clipper64_add_clip(c: *mut ClipperClipper64, clips: *mut ClipperPaths64); +} +extern "C" { + pub fn clipper_clipper64_execute( + c64: *mut ClipperClipper64, + ct: ClipperClipType, + fr: ClipperFillRule, + closed: *mut ClipperPaths64, + open: *mut ClipperPaths64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipper64_execute_tree_with_open( + c64: *mut ClipperClipper64, + ct: ClipperClipType, + fr: ClipperFillRule, + tree: *mut ClipperPolyTree64, + open: *mut ClipperPaths64, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperd_add_subject(c: *mut ClipperClipperD, subjects: *mut ClipperPathsD); +} +extern "C" { + pub fn clipper_clipperd_add_open_subject( + c: *mut ClipperClipperD, + open_subjects: *mut ClipperPathsD, + ); +} +extern "C" { + pub fn clipper_clipperd_add_clip(c: *mut ClipperClipperD, clips: *mut ClipperPathsD); +} +extern "C" { + pub fn clipper_clipperd_execute( + cD: *mut ClipperClipperD, + ct: ClipperClipType, + fr: ClipperFillRule, + closed: *mut ClipperPathsD, + open: *mut ClipperPathsD, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperd_execute_tree_with_open( + cD: *mut ClipperClipperD, + ct: ClipperClipType, + fr: ClipperFillRule, + tree: *mut ClipperPolyTreeD, + open: *mut ClipperPathsD, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperoffset( + mem: *mut ::std::os::raw::c_void, + miter_limit: f64, + arc_tolerance: f64, + preserve_collinear: ::std::os::raw::c_int, + reverse_solution: ::std::os::raw::c_int, + ) -> *mut ClipperClipperOffset; +} +extern "C" { + pub fn clipper_clipperoffset_set_miter_limit(c: *mut ClipperClipperOffset, l: f64); +} +extern "C" { + pub fn clipper_clipperoffset_set_arc_tolerance(c: *mut ClipperClipperOffset, t: f64); +} +extern "C" { + pub fn clipper_clipperoffset_set_preserve_collinear( + c: *mut ClipperClipperOffset, + t: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn clipper_clipperoffset_set_reverse_solution( + c: *mut ClipperClipperOffset, + t: ::std::os::raw::c_int, + ); +} +extern "C" { + pub fn clipper_clipperoffset_get_miter_limit(c: *mut ClipperClipperOffset) -> f64; +} +extern "C" { + pub fn clipper_clipperoffset_get_arc_tolerance(c: *mut ClipperClipperOffset) -> f64; +} +extern "C" { + pub fn clipper_clipperoffset_get_preserve_collinear( + c: *mut ClipperClipperOffset, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperoffset_get_reverse_solution( + c: *mut ClipperClipperOffset, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperoffset_error_code(c: *mut ClipperClipperOffset) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn clipper_clipperoffset_clear(c: *mut ClipperClipperOffset); +} +extern "C" { + pub fn clipper_clipperoffset_add_path64( + c: *mut ClipperClipperOffset, + p: *mut ClipperPath64, + jt: ClipperJoinType, + et: ClipperEndType, + ); +} +extern "C" { + pub fn clipper_clipperoffset_add_paths64( + c: *mut ClipperClipperOffset, + p: *mut ClipperPaths64, + jt: ClipperJoinType, + et: ClipperEndType, + ); +} +extern "C" { + pub fn clipper_clipperoffset_execute( + mem: *mut ::std::os::raw::c_void, + c: *mut ClipperClipperOffset, + delta: f64, + ) -> *mut ClipperPaths64; +} +extern "C" { + pub fn clipper_path64_size() -> usize; +} +extern "C" { + pub fn clipper_pathd_size() -> usize; +} +extern "C" { + pub fn clipper_paths64_size() -> usize; +} +extern "C" { + pub fn clipper_pathsd_size() -> usize; +} +extern "C" { + pub fn clipper_polytree64_size() -> usize; +} +extern "C" { + pub fn clipper_polytreed_size() -> usize; +} +extern "C" { + pub fn clipper_clipper64_size() -> usize; +} +extern "C" { + pub fn clipper_clipperd_size() -> usize; +} +extern "C" { + pub fn clipper_clipperoffset_size() -> usize; +} +extern "C" { + pub fn clipper_delete_path64(p: *mut ClipperPath64); +} +extern "C" { + pub fn clipper_delete_pathd(p: *mut ClipperPathD); +} +extern "C" { + pub fn clipper_delete_paths64(p: *mut ClipperPaths64); +} +extern "C" { + pub fn clipper_delete_pathsd(p: *mut ClipperPathsD); +} +extern "C" { + pub fn clipper_delete_polytree64(p: *mut ClipperPolyTree64); +} +extern "C" { + pub fn clipper_delete_polytreed(p: *mut ClipperPolyTreeD); +} +extern "C" { + pub fn clipper_delete_clipper64(p: *mut ClipperClipper64); +} +extern "C" { + pub fn clipper_delete_clipperd(p: *mut ClipperClipperD); +} +extern "C" { + pub fn clipper_delete_clipperoffset(p: *mut ClipperClipperOffset); +} diff --git a/src/lib.rs b/src/lib.rs index b37fa6b..f0cea47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,24 @@ #[cfg(test)] mod test; +#[cfg(not(feature = "usingz"))] #[cfg(all(not(feature = "update-bindings"), feature = "generate-bindings"))] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +#[cfg(feature = "usingz")] +#[cfg(all(not(feature = "update-bindings"), feature = "generate-bindings"))] +include!(concat!(env!("OUT_DIR"), "/bindings_usingz.rs")); + +#[cfg(not(feature = "usingz"))] #[cfg(any(feature = "update-bindings", not(feature = "generate-bindings")))] include!(concat!( env!("CARGO_MANIFEST_DIR"), "/generated/bindings.rs" )); + +#[cfg(feature = "usingz")] +#[cfg(any(feature = "update-bindings", not(feature = "generate-bindings")))] +include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/generated/bindings_usingz.rs" +)); diff --git a/src/test.rs b/src/test.rs index 71e978c..86d8034 100644 --- a/src/test.rs +++ b/src/test.rs @@ -14,16 +14,44 @@ unsafe fn malloc(size: usize) -> *mut std::os::raw::c_void { #[test] fn test_difference_boolean_operation() { let mut triangle = vec![ - ClipperPoint64 { x: 0, y: 0 }, - ClipperPoint64 { x: 10, y: 0 }, - ClipperPoint64 { x: 5, y: 10 }, + ClipperPoint64 { + x: 0, + y: 0, + ..Default::default() + }, + ClipperPoint64 { + x: 10, + y: 0, + ..Default::default() + }, + ClipperPoint64 { + x: 5, + y: 10, + ..Default::default() + }, ]; let mut square = vec![ - ClipperPoint64 { x: 0, y: 0 }, - ClipperPoint64 { x: 4, y: 0 }, - ClipperPoint64 { x: 4, y: 4 }, - ClipperPoint64 { x: 0, y: 4 }, + ClipperPoint64 { + x: 0, + y: 0, + ..Default::default() + }, + ClipperPoint64 { + x: 4, + y: 0, + ..Default::default() + }, + ClipperPoint64 { + x: 4, + y: 4, + ..Default::default() + }, + ClipperPoint64 { + x: 0, + y: 4, + ..Default::default() + }, ]; for _ in 0..1_000 { @@ -45,6 +73,27 @@ fn test_difference_boolean_operation() { let clipper_mem = malloc(clipper_clipper64_size()); let clipper_ptr = clipper_clipper64(clipper_mem); + #[cfg(feature = "usingz")] + { + extern "C" fn cb( + _ud: *mut std::ffi::c_void, + _e1bot: *const ClipperPoint64, + _e1top: *const ClipperPoint64, + _e2bot: *const ClipperPoint64, + _e2top: *const ClipperPoint64, + pt: *mut ClipperPoint64, + ) { + unsafe { + (*pt).z = 1; + } + } + crate::clipper_clipper64_set_z_callback( + clipper_ptr, + std::ptr::null_mut(), + Some(cb), + ); + } + clipper_clipper64_add_subject(clipper_ptr, subjects_ptr); clipper_clipper64_add_clip(clipper_ptr, clips_ptr); @@ -76,6 +125,15 @@ fn test_difference_boolean_operation() { let point_len: i32 = clipper_paths64_path_length(closed_path_ptr, i) .try_into() .unwrap(); + + #[cfg(feature = "usingz")] + { + assert!((0..point_len) + .map(|j| clipper_paths64_get_point(closed_path_ptr, i, j)) + .map(|p| p.z) + .any(|z| z == 1)); + } + (0..point_len) .map(|j| clipper_paths64_get_point(closed_path_ptr, i, j)) .map(|p| (p.x, p.y))