Skip to content

Add C wrapper for Clipper2 - #60

Open
gpeairs wants to merge 1 commit into
JuliaGeometry:masterfrom
gpeairs:clipper2-cwrapper
Open

Add C wrapper for Clipper2#60
gpeairs wants to merge 1 commit into
JuliaGeometry:masterfrom
gpeairs:clipper2-cwrapper

Conversation

@gpeairs

@gpeairs gpeairs commented Jul 30, 2026

Copy link
Copy Markdown

This PR is intended as the first step towards updating Clipper.jl to wrap Clipper2. As discussed in #50, I wrote a custom C wrapper to do this. The plan is that Yggdrasil#14270 will add this wrapper as a third library product of Clipper2_jll, libcclipper2. The wrapper was originally bundled in the recipe in that PR (as was done with Clipper1), but the maintainers prefer files of this size be hosted elsewhere. At their suggestion this PR adds the two wrapper source files here, with the C ABI implementation in deps/cwrapper/cclipper2.cpp and header deps/cwrapper/clipper2.h.

This doesn't change anything for Clipper.jl users at this point; these are just build inputs for Clipper2_jll. Yggdrasil#14270 (which also updates the Clipper2 version to 2.0.1) is gated on this, since it currently points at my personal fork as a placeholder. Following that, a separate PR will add a Julia wrapper for the new C ABI and bump the version number for a breaking release.

Some notes on the wrapper:

  • Variable-length results are returned through caller-supplied callbacks, so the wrapper never owns result memory.
  • The wrapper owns enum values, mapped to Clipper2's enums with switch statements. Upstream has renumbered enums before, e.g. with the insertion of JoinType::Bevel in v1.2.3.
  • The wrapper uses exception barriers, running every exported function body inside a try/catch.
  • The plan is for a single -DUSINGZ build, linked against libClipper2Z. Internally, points then carry a z integer tag. The Clipper engine stamps intersection-created vertices with a sentinel value Z_INTERSECTION = INT64_MIN. There are narrow (x,y) entry points that construct a point with z=0, so callers pay 8 bytes per vertex for z tags they never see. I've found this to be negligible overhead compared to engine operations, but a second library product could be added later if a need justifies it. The equivalent *_z entry points expose the z tag. The file also compiles without USINGZ, minus the *_z symbols. (For context, Z tagging is the feature motivating the upgrade on my side at Upgrade to Clipper2 aws-cqc/DeviceLayout.jl#199 (comment).)

@asinghvi17

Copy link
Copy Markdown
Member

This seems generally reasonable, but would be interested to see a finished version based on local testing

@gpeairs gpeairs mentioned this pull request Aug 3, 2026
@gpeairs

gpeairs commented Aug 3, 2026

Copy link
Copy Markdown
Author

I was just thinking the same thing, so I opened #61 which adds the Julia side for local testing.

@gpeairs

gpeairs commented Aug 17, 2026

Copy link
Copy Markdown
Author

@SimonDanisch, just pinging if you want to take a look at this/#61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants